Skip to content
Snippets Groups Projects
Commit 16adfc10 authored by graywolf336's avatar graywolf336
Browse files

Prevent someone from reacting if they are muted

parent 4e432824
No related merge requests found
......@@ -4,6 +4,13 @@ Template.room.events({
event.stopPropagation();
const data = Blaze.getData(event.currentTarget);
let user = Meteor.user();
let room = RocketChat.models.Rooms.findOne({ _id: data._arguments[1].rid });
if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
return false;
}
RocketChat.EmojiPicker.open(event.currentTarget, (emoji) => {
Meteor.call('setReaction', ':' + emoji + ':', data._arguments[1]._id);
});
......@@ -46,7 +53,14 @@ Meteor.startup(function() {
Meteor.call('setReaction', ':' + emoji + ':', data._arguments[1]._id);
});
},
validation() {
validation(message) {
let room = RocketChat.models.Rooms.findOne({ _id: message.rid });
let user = Meteor.user();
if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
return false;
}
return true;
},
order: 22
......
......@@ -4,9 +4,14 @@ Meteor.methods({
throw new Meteor.Error(203, 'User_logged_out');
}
const user = Meteor.user();
let message = RocketChat.models.Messages.findOne({ _id: messageId });
let room = RocketChat.models.Rooms.findOne({ _id: message.rid });
const user = Meteor.user();
if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
return false;
}
if (message.reactions && message.reactions[reaction] && message.reactions[reaction].usernames.indexOf(user.username) !== -1) {
message.reactions[reaction].usernames.splice(message.reactions[reaction].usernames.indexOf(user.username), 1);
......
......@@ -7,12 +7,24 @@ Meteor.methods({
let message = RocketChat.models.Messages.findOneById(messageId);
if (!Meteor.call('canAccessRoom', message.rid, Meteor.userId())) {
let room = Meteor.call('canAccessRoom', message.rid, Meteor.userId());
if (!room) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}
const user = Meteor.user();
if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: room._id,
ts: new Date(),
msg: TAPi18n.__('You_have_been_muted', {}, user.language)
});
return false;
}
if (message.reactions && message.reactions[reaction] && message.reactions[reaction].usernames.indexOf(user.username) !== -1) {
message.reactions[reaction].usernames.splice(message.reactions[reaction].usernames.indexOf(user.username), 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment