diff --git a/packages/rocketchat-lib/lib/slashCommand.coffee b/packages/rocketchat-lib/lib/slashCommand.coffee index 0fad4644a4f0..8e8b7b4ee701 100644 --- a/packages/rocketchat-lib/lib/slashCommand.coffee +++ b/packages/rocketchat-lib/lib/slashCommand.coffee @@ -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) -> diff --git a/packages/rocketchat-slashcommands-join/client.coffee b/packages/rocketchat-slashcommands-join/client.coffee index 922aeedc74c7..92ede9a683a7 100644 --- a/packages/rocketchat-slashcommands-join/client.coffee +++ b/packages/rocketchat-slashcommands-join/client.coffee @@ -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 \ No newline at end of file diff --git a/packages/rocketchat-slashcommands-join/server.coffee b/packages/rocketchat-slashcommands-join/server.coffee index bf66a39d62d8..c6bebe71cf8d 100644 --- a/packages/rocketchat-slashcommands-join/server.coffee +++ b/packages/rocketchat-slashcommands-join/server.coffee @@ -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 diff --git a/packages/rocketchat-ui/client/lib/chatMessages.coffee b/packages/rocketchat-ui/client/lib/chatMessages.coffee index 2b22a3b5f379..aa4bd9276bc8 100644 --- a/packages/rocketchat-ui/client/lib/chatMessages.coffee +++ b/packages/rocketchat-ui/client/lib/chatMessages.coffee @@ -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')