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-slashcommands-in.../server.coffee

50 lines
1.4 KiB

###
# Invite is a named function that will replace /invite commands
# @param {Object} message - The message object
###
if Meteor.isClient
Tracker.autorun ->
RocketChat.slashCommands.add 'invite', undefined,
description: TAPi18n.__('Invite_user_to_join_channel')
params: '@username'
else
class Invite
constructor: (command, params, item) ->
if command isnt 'invite' or not Match.test params, String
return
username = params.trim()
if username is ''
return
username = username.replace('@', '')
user = Meteor.users.findOne({ username: username })
currentUser = Meteor.users.findOne Meteor.userId()
if not user?
console.log 'notify user_doesnt_exist'
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('User_doesnt_exist', { postProcess: 'sprintf', sprintf: [ username ] }, currentUser.language)
}
return
# cancel if the user is already in this room
if RocketChat.models.Rooms.findOneByIdContainigUsername(item.rid, user.username)?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('Username_is_already_in_here', { postProcess: 'sprintf', sprintf: [ username ] }, currentUser.language)
}
return
Meteor.runAsUser user._id, ->
Meteor.call 'joinRoom', item.rid
RocketChat.slashCommands.add 'invite', Invite