-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
converted slashcommand-join coffee to js #6469
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
RocketChat.slashCommands.add('join', void 0, { | ||
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 was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
/* | ||
* Join is a named function that will replace /join commands | ||
* @param {Object} message - The message object | ||
*/ | ||
|
||
|
||
const Join = function(command, params, item) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO named functions are better for theses cases, cuz the stack trace of the errors will be more clear. |
||
|
||
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.indexOf(user.username) > -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you replace the |
||
throw new Meteor.Error('error-user-already-in-room', 'You are already in the channel', { | ||
method: 'slashCommands' | ||
}); | ||
} | ||
Meteor.call('joinRoom', room._id); | ||
}; | ||
|
||
RocketChat.slashCommands.add('join', Join); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use
void 0