@@ -8,6 +8,7 @@ import { Notifications } from '../../notifications';
88import { callbacks } from '../../callbacks' ;
99import { emoji } from '../../emoji' ;
1010import { isTheLastMessage , msgStream } from '../../lib' ;
11+ import { hasPermission } from '../../authorization/server/functions/hasPermission' ;
1112
1213const removeUserReaction = ( message , reaction , username ) => {
1314 message . reactions [ reaction ] . usernames . splice ( message . reactions [ reaction ] . usernames . indexOf ( username ) , 1 ) ;
@@ -17,16 +18,17 @@ const removeUserReaction = (message, reaction, username) => {
1718 return message ;
1819} ;
1920
20- export function setReaction ( room , user , message , reaction , shouldReact ) {
21+ async function setReaction ( room , user , message , reaction , shouldReact ) {
2122 reaction = `:${ reaction . replace ( / : / g, '' ) } :` ;
2223
2324 if ( ! emoji . list [ reaction ] && EmojiCustom . findByNameOrAlias ( reaction ) . count ( ) === 0 ) {
2425 throw new Meteor . Error ( 'error-not-allowed' , 'Invalid emoji provided.' , { method : 'setReaction' } ) ;
2526 }
2627
27- if ( room . ro && ! room . reactWhenReadOnly ) {
28- if ( ! Array . isArray ( room . unmuted ) || room . unmuted . indexOf ( user . username ) === - 1 ) {
29- return false ;
28+ if ( room . ro === true && ( ! room . reactWhenReadOnly && ! hasPermission ( user . _id , 'post-readonly' , room . _id ) ) ) {
29+ // Unless the user was manually unmuted
30+ if ( ! ( room . unmuted || [ ] ) . includes ( user . username ) ) {
31+ throw new Error ( 'You can\'t send messages because the room is readonly.' ) ;
3032 }
3133 }
3234
@@ -38,8 +40,6 @@ export function setReaction(room, user, message, reaction, shouldReact) {
3840 msg : TAPi18n . __ ( 'You_have_been_muted' , { } , user . language ) ,
3941 } ) ;
4042 return false ;
41- } if ( ! Subscriptions . findOne ( { rid : message . rid } ) ) {
42- return false ;
4343 }
4444
4545 const userAlreadyReacted = Boolean ( message . reactions ) && Boolean ( message . reactions [ reaction ] ) && message . reactions [ reaction ] . usernames . indexOf ( user . username ) !== - 1 ;
@@ -92,18 +92,18 @@ Meteor.methods({
9292 setReaction ( reaction , messageId , shouldReact ) {
9393 const user = Meteor . user ( ) ;
9494
95- const message = Messages . findOneById ( messageId ) ;
96-
97- const room = Meteor . call ( 'canAccessRoom' , message . rid , Meteor . userId ( ) ) ;
98-
9995 if ( ! user ) {
10096 throw new Meteor . Error ( 'error-invalid-user' , 'Invalid user' , { method : 'setReaction' } ) ;
10197 }
10298
99+ const message = Messages . findOneById ( messageId ) ;
100+
103101 if ( ! message ) {
104102 throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , { method : 'setReaction' } ) ;
105103 }
106104
105+ const room = Meteor . call ( 'canAccessRoom' , message . rid , Meteor . userId ( ) ) ;
106+
107107 if ( ! room ) {
108108 throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , { method : 'setReaction' } ) ;
109109 }
0 commit comments