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/packages/rocketchat-lib/server/methods/sendMessage.coffee

33 lines
1.1 KiB

Meteor.methods
sendMessage: (message, options) ->
if message.msg?.length > RocketChat.settings.get('Message_MaxAllowedSize')
throw new Meteor.Error 400, '[methods] sendMessage -> Message size exceed Message_MaxAllowedSize'
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user")
user = RocketChat.models.Users.findOneById Meteor.userId(), fields: username: 1
room = Meteor.call 'canAccessRoom', message.rid, user._id
if not room
return false
if user.username in (room.muted or [])
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
RocketChat.sendMessage user, message, room, options
# Limit a user to sending 5 msgs/second
# DDPRateLimiter.addRule
# type: 'method'
# name: 'sendMessage'
# userId: (userId) ->
# return RocketChat.models.Users.findOneById(userId)?.username isnt RocketChat.settings.get('InternalHubot_Username')
# , 5, 1000