The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/muteUserInRoom.coffee

29 lines
1.1 KiB

Meteor.methods
muteUserInRoom: (data) ->
fromId = Meteor.userId()
check(data, Match.ObjectIncluding({ rid: String, username: String }))
unless RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid)
throw new Meteor.Error 'not-allowed', '[methods] muteUserInRoom -> Not allowed'
room = RocketChat.models.Rooms.findOneById data.rid
if not room
throw new Meteor.Error 'invalid-room', '[methods] muteUserInRoom -> Room ID is invalid'
if room.t not in ['c', 'p']
throw new Meteor.Error 'invalid-room-type', '[methods] muteUserInRoom -> Invalid room type'
if data.username not in (room?.usernames or [])
throw new Meteor.Error 'not-in-room', '[methods] muteUserInRoom -> User is not in this room'
mutedUser = RocketChat.models.Users.findOneByUsername data.username
RocketChat.models.Rooms.muteUsernameByRoomId data.rid, mutedUser.username
fromUser = RocketChat.models.Users.findOneById fromId
RocketChat.models.Messages.createUserMutedWithRoomIdAndUser data.rid, mutedUser,
u:
_id: fromUser._id
username: fromUser.username
return true