Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join command #6268

Merged
merged 4 commits into from
Mar 23, 2017
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
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/lib/slashCommand.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
RocketChat.slashCommands =
commands: {}

RocketChat.slashCommands.add = (command, callback, options) ->
RocketChat.slashCommands.add = (command, callback, options, result) ->
RocketChat.slashCommands.commands[command] =
command: command
callback: callback
params: options?.params
description: options?.description
clientOnly: options?.clientOnly or false

result: result
return

RocketChat.slashCommands.run = (command, params, item) ->
Expand Down
9 changes: 7 additions & 2 deletions packages/rocketchat-slashcommands-join/client.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
RocketChat.slashCommands.add 'join', undefined,
description: 'Join_the_given_channel'
params: '#channel'
description: 'Join_the_given_channel'
params: '#channel'
(err, result, params) ->
if err.error == 'error-user-already-in-room'
params.cmd = 'open'
params.msg.msg = params.msg.msg.replace('join', 'open')
RocketChat.slashCommands.run 'open', params.params, params.msg
16 changes: 9 additions & 7 deletions packages/rocketchat-slashcommands-join/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ class Join
channel = channel.replace('#', '')

user = Meteor.users.findOne Meteor.userId()
room = RocketChat.models.Rooms.findOneByNameAndTypeNotContainingUsername(channel, 'c', user.username)

if not room?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
room = RocketChat.models.Rooms.findOneByNameAndType channel, 'c'
if not room
RocketChat.Notifications.notifyUser Meteor.userId(), 'message',
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('Channel_doesnt_exist', { postProcess: 'sprintf', sprintf: [ channel ] }, user.language)
}
return


throw new Meteor.Error('error-user-already-in-room', 'You are already in the channel', {
method: 'slashCommands'
}) if room.usernames.indexOf(user.username) > -1

Meteor.call 'joinRoom', room._id

RocketChat.slashCommands.add 'join', Join
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class @ChatMessages
if commandOptions.clientOnly
commandOptions.callback(command, param, msgObject)
else
Meteor.call 'slashCommand', {cmd: command, params: param, msg: msgObject }
Meteor.call 'slashCommand', {cmd: command, params: param, msg: msgObject }, (err, result) -> commandOptions.result?(err, result, {cmd: command, params: param, msg: msgObject })
return

if !RocketChat.settings.get('Message_AllowUnrecognizedSlashCommand')
Expand Down