-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6469 from ggazzo/slashcommands-join
converted slashcommand-join coffee to js
- Loading branch information
Showing
5 changed files
with
49 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
RocketChat.slashCommands.add('join', undefined, { | ||
description: 'Join_the_given_channel', | ||
params: '#channel' | ||
}, function(err, result, params) { | ||
if (err.error === 'error-user-already-in-room') { | ||
params.cmd = 'open'; | ||
params.msg.msg = params.msg.msg.replace('join', 'open'); | ||
return RocketChat.slashCommands.run('open', params.params, params.msg); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
/* | ||
* Join is a named function that will replace /join commands | ||
* @param {Object} message - The message object | ||
*/ | ||
|
||
|
||
RocketChat.slashCommands.add('join', function Join(command, params, item) { | ||
|
||
if (command !== 'join' || !Match.test(params, String)) { | ||
return; | ||
} | ||
let channel = params.trim(); | ||
if (channel === '') { | ||
return; | ||
} | ||
channel = channel.replace('#', ''); | ||
const user = Meteor.users.findOne(Meteor.userId()); | ||
const room = RocketChat.models.Rooms.findOneByNameAndType(channel, 'c'); | ||
if (!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) | ||
}); | ||
} | ||
if (room.usernames.includes(user.username)) { | ||
throw new Meteor.Error('error-user-already-in-room', 'You are already in the channel', { | ||
method: 'slashCommands' | ||
}); | ||
} | ||
Meteor.call('joinRoom', room._id); | ||
}); |