Skip to content
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 slashcommands-mute coffee to js #6474

Merged
merged 2 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/rocketchat-slashcommands-mute/client/mute.coffee

This file was deleted.

4 changes: 4 additions & 0 deletions packages/rocketchat-slashcommands-mute/client/mute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RocketChat.slashCommands.add('mute', undefined, {
description: 'Mute_someone_in_room',
params: '@username'
});
3 changes: 0 additions & 3 deletions packages/rocketchat-slashcommands-mute/client/unmute.coffee

This file was deleted.

4 changes: 4 additions & 0 deletions packages/rocketchat-slashcommands-mute/client/unmute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RocketChat.slashCommands.add('unmute', undefined, {
description: 'Unmute_someone_in_room',
params: '@username'
});
9 changes: 4 additions & 5 deletions packages/rocketchat-slashcommands-mute/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ Package.onUse(function(api) {

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

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

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

This file was deleted.

45 changes: 45 additions & 0 deletions packages/rocketchat-slashcommands-mute/server/mute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

/*
* Mute is a named function that will replace /mute commands
*/

RocketChat.slashCommands.add('mute', function Mute(command, params, item) {
if (command !== 'mute' || !Match.test(params, String)) {
return;
}
const username = params.trim().replace('@', '');
if (username === '') {
return;
}
const user = Meteor.users.findOne(Meteor.userId());
const mutedUser = RocketChat.models.Users.findOneByUsername(username);
const room = RocketChat.models.Rooms.findOneById(item.rid);
if (mutedUser == null) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Username_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
return;
}
if ((room.usernames || []).includes(username)) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Username_is_not_in_this_room', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
return;
}
Meteor.call('muteUserInRoom', {
rid: item.rid,
username
});
});
40 changes: 0 additions & 40 deletions packages/rocketchat-slashcommands-mute/server/unmute.coffee

This file was deleted.

44 changes: 44 additions & 0 deletions packages/rocketchat-slashcommands-mute/server/unmute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/*
* Unmute is a named function that will replace /unmute commands
*/

RocketChat.slashCommands.add('unmute', function Unmute(command, params, item) {

if (command !== 'unmute' || !Match.test(params, String)) {
return;
}
const username = params.trim().replace('@', '');
if (username === '') {
return;
}
const user = Meteor.users.findOne(Meteor.userId());
const unmutedUser = RocketChat.models.Users.findOneByUsername(username);
const room = RocketChat.models.Rooms.findOneById(item.rid);
if (unmutedUser == null) {
return RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Username_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
}
if ((room.usernames || []).includes(username)) {
return RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Username_is_not_in_this_room', {
postProcess: 'sprintf',
sprintf: [username]
}, user.language)
});
}
Meteor.call('unmuteUserInRoom', {
rid: item.rid,
username
});
});