Skip to content

Commit

Permalink
Merge pull request #6469 from ggazzo/slashcommands-join
Browse files Browse the repository at this point in the history
converted slashcommand-join coffee to js
  • Loading branch information
engelgabriel authored Mar 29, 2017
2 parents 37f9ae3 + 75a4c25 commit f52ff73
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
8 changes: 0 additions & 8 deletions packages/rocketchat-slashcommands-join/client.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions packages/rocketchat-slashcommands-join/client.js
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);
}
});
5 changes: 2 additions & 3 deletions packages/rocketchat-slashcommands-join/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ Package.onUse(function(api) {

api.use([
'ecmascript',
'coffeescript',
'check',
'rocketchat:lib'
]);

api.use('templating', 'client');

api.addFiles('client.coffee', 'client');
api.addFiles('server.coffee', 'server');
api.addFiles('client.js', 'client');
api.addFiles('server.js', 'server');
});
33 changes: 0 additions & 33 deletions packages/rocketchat-slashcommands-join/server.coffee

This file was deleted.

37 changes: 37 additions & 0 deletions packages/rocketchat-slashcommands-join/server.js
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);
});

0 comments on commit f52ff73

Please sign in to comment.