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-join/server.js

37 lines
972 B

/*
* 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);
});