Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions app/reactions/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';

import { roomTypes } from '../../utils/client';
import { Rooms } from '../../models';
import { MessageAction } from '../../ui-utils';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
Expand All @@ -17,13 +18,7 @@ Template.room.events({
const user = Meteor.user();
const room = Rooms.findOne({ _id: rid });

if (room.ro && !room.reactWhenReadOnly) {
if (!Array.isArray(room.unmuted) || room.unmuted.indexOf(user.username) === -1) {
return false;
}
}

if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
if (roomTypes.readOnly(room._id, user._id)) {
return false;
}

Expand Down Expand Up @@ -73,21 +68,15 @@ Meteor.startup(function() {
return false;
}

if (room.ro && !room.reactWhenReadOnly) {
if (!Array.isArray(room.unmuted) || room.unmuted.indexOf(user.username) === -1) {
return false;
}
}

if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
if (!subscription) {
return false;
}

if (!subscription) {
if (message.private) {
return false;
}

if (message.private) {
if (roomTypes.readOnly(room._id, user._id)) {
return false;
}

Expand Down
15 changes: 5 additions & 10 deletions app/reactions/client/methods/setReaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _ from 'underscore';
import { Messages, Rooms, Subscriptions } from '../../../models';
import { callbacks } from '../../../callbacks';
import { emoji } from '../../../emoji';
import { roomTypes } from '../../../utils/client';

Meteor.methods({
setReaction(reaction, messageId) {
Expand All @@ -16,25 +17,19 @@ Meteor.methods({
const message = Messages.findOne({ _id: messageId });
const room = Rooms.findOne({ _id: message.rid });

if (room.ro && !room.reactWhenReadOnly) {
if (!Array.isArray(room.unmuted) || room.unmuted.indexOf(user.username) === -1) {
return false;
}
}

if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1) {
if (message.private) {
return false;
}

if (!Subscriptions.findOne({ rid: message.rid })) {
if (!emoji.list[reaction]) {
return false;
}

if (message.private) {
if (roomTypes.readOnly(room._id, user._id)) {
return false;
}

if (!emoji.list[reaction]) {
if (!Subscriptions.findOne({ rid: message.rid })) {
return false;
}

Expand Down
22 changes: 11 additions & 11 deletions app/reactions/server/setReaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import _ from 'underscore';

import { Messages, EmojiCustom, Subscriptions, Rooms } from '../../models';
import { Messages, EmojiCustom, Rooms } from '../../models';
import { Notifications } from '../../notifications';
import { callbacks } from '../../callbacks';
import { emoji } from '../../emoji';
import { isTheLastMessage, msgStream } from '../../lib';
import { hasPermission } from '../../authorization/server/functions/hasPermission';

const removeUserReaction = (message, reaction, username) => {
message.reactions[reaction].usernames.splice(message.reactions[reaction].usernames.indexOf(username), 1);
Expand All @@ -17,16 +18,17 @@ const removeUserReaction = (message, reaction, username) => {
return message;
};

export function setReaction(room, user, message, reaction, shouldReact) {
async function setReaction(room, user, message, reaction, shouldReact) {
reaction = `:${ reaction.replace(/:/g, '') }:`;

if (!emoji.list[reaction] && EmojiCustom.findByNameOrAlias(reaction).count() === 0) {
throw new Meteor.Error('error-not-allowed', 'Invalid emoji provided.', { method: 'setReaction' });
}

if (room.ro && !room.reactWhenReadOnly) {
if (!Array.isArray(room.unmuted) || room.unmuted.indexOf(user.username) === -1) {
return false;
if (room.ro === true && (!room.reactWhenReadOnly && !hasPermission(user._id, 'post-readonly', room._id))) {
// Unless the user was manually unmuted
if (!(room.unmuted || []).includes(user.username)) {
throw new Error('You can\'t send messages because the room is readonly.');
}
}

Expand All @@ -38,8 +40,6 @@ export function setReaction(room, user, message, reaction, shouldReact) {
msg: TAPi18n.__('You_have_been_muted', {}, user.language),
});
return false;
} if (!Subscriptions.findOne({ rid: message.rid })) {
return false;
}

const userAlreadyReacted = Boolean(message.reactions) && Boolean(message.reactions[reaction]) && message.reactions[reaction].usernames.indexOf(user.username) !== -1;
Expand Down Expand Up @@ -92,18 +92,18 @@ Meteor.methods({
setReaction(reaction, messageId, shouldReact) {
const user = Meteor.user();

const message = Messages.findOneById(messageId);

const room = Meteor.call('canAccessRoom', message.rid, Meteor.userId());

if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setReaction' });
}

const message = Messages.findOneById(messageId);

if (!message) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}

const room = Meteor.call('canAccessRoom', message.rid, Meteor.userId());

if (!room) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}
Expand Down
8 changes: 3 additions & 5 deletions app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@
</ul>
{{/unless}}
{{#if broadcast}}
{{#with msg.u}}
<button type="button" class="js-reply-broadcast rc-button rc-button--primary rc-button--small rc-button--outline" name="button">
{{> icon icon="reply"}} {{_'Reply'}}
</button>
{{/with}}
<button type="button" class="js-reply-broadcast rc-button rc-button--primary rc-button--small rc-button--outline" name="button">
{{> icon icon="reply"}} {{_'Reply'}}
</button>
{{/if}}
{{#unless hideReactions}}
<ul class="reactions">
Expand Down