diff --git a/packages/rocketchat-slashcommands-mute/client/mute.coffee b/packages/rocketchat-slashcommands-mute/client/mute.coffee deleted file mode 100644 index c7c62f28f576..000000000000 --- a/packages/rocketchat-slashcommands-mute/client/mute.coffee +++ /dev/null @@ -1,3 +0,0 @@ -RocketChat.slashCommands.add 'mute', null, - description: 'Mute_someone_in_room' - params: '@username' diff --git a/packages/rocketchat-slashcommands-mute/client/mute.js b/packages/rocketchat-slashcommands-mute/client/mute.js new file mode 100644 index 000000000000..14735ce70ae9 --- /dev/null +++ b/packages/rocketchat-slashcommands-mute/client/mute.js @@ -0,0 +1,4 @@ +RocketChat.slashCommands.add('mute', undefined, { + description: 'Mute_someone_in_room', + params: '@username' +}); diff --git a/packages/rocketchat-slashcommands-mute/client/unmute.coffee b/packages/rocketchat-slashcommands-mute/client/unmute.coffee deleted file mode 100644 index 18b417f298d5..000000000000 --- a/packages/rocketchat-slashcommands-mute/client/unmute.coffee +++ /dev/null @@ -1,3 +0,0 @@ -RocketChat.slashCommands.add 'unmute', null, - description: 'Unmute_someone_in_room' - params: '@username' diff --git a/packages/rocketchat-slashcommands-mute/client/unmute.js b/packages/rocketchat-slashcommands-mute/client/unmute.js new file mode 100644 index 000000000000..447e02cec79b --- /dev/null +++ b/packages/rocketchat-slashcommands-mute/client/unmute.js @@ -0,0 +1,4 @@ +RocketChat.slashCommands.add('unmute', undefined, { + description: 'Unmute_someone_in_room', + params: '@username' +}); diff --git a/packages/rocketchat-slashcommands-mute/package.js b/packages/rocketchat-slashcommands-mute/package.js index af1bc9a816b3..aee8058a6f7b 100644 --- a/packages/rocketchat-slashcommands-mute/package.js +++ b/packages/rocketchat-slashcommands-mute/package.js @@ -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'); }); diff --git a/packages/rocketchat-slashcommands-mute/server/mute.coffee b/packages/rocketchat-slashcommands-mute/server/mute.coffee deleted file mode 100644 index d8bc3d3bc513..000000000000 --- a/packages/rocketchat-slashcommands-mute/server/mute.coffee +++ /dev/null @@ -1,40 +0,0 @@ -### -# Mute is a named function that will replace /mute commands -### - -class Mute - constructor: (command, params, item) -> - if command isnt 'mute' or not Match.test params, String - return - - username = params.trim() - if username is '' - return - - username = username.replace('@', '') - - user = Meteor.users.findOne Meteor.userId() - mutedUser = RocketChat.models.Users.findOneByUsername username - room = RocketChat.models.Rooms.findOneById item.rid - - if not mutedUser? - 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 username not in (room.usernames or []) - 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: username } - -RocketChat.slashCommands.add 'mute', Mute diff --git a/packages/rocketchat-slashcommands-mute/server/mute.js b/packages/rocketchat-slashcommands-mute/server/mute.js new file mode 100644 index 000000000000..38273ff18fee --- /dev/null +++ b/packages/rocketchat-slashcommands-mute/server/mute.js @@ -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 + }); +}); diff --git a/packages/rocketchat-slashcommands-mute/server/unmute.coffee b/packages/rocketchat-slashcommands-mute/server/unmute.coffee deleted file mode 100644 index e3b6ee25d82d..000000000000 --- a/packages/rocketchat-slashcommands-mute/server/unmute.coffee +++ /dev/null @@ -1,40 +0,0 @@ -### -# Unmute is a named function that will replace /unmute commands -### - -class Unmute - constructor: (command, params, item) -> - if command isnt 'unmute' or not Match.test params, String - return - - username = params.trim() - if username is '' - return - - username = username.replace('@', '') - - user = Meteor.users.findOne Meteor.userId() - unmutedUser = RocketChat.models.Users.findOneByUsername username - room = RocketChat.models.Rooms.findOneById item.rid - - if not unmutedUser? - 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 username not in (room.usernames or []) - 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 'unmuteUserInRoom', { rid: item.rid, username: username } - -RocketChat.slashCommands.add 'unmute', Unmute diff --git a/packages/rocketchat-slashcommands-mute/server/unmute.js b/packages/rocketchat-slashcommands-mute/server/unmute.js new file mode 100644 index 000000000000..c5a3f02cfa10 --- /dev/null +++ b/packages/rocketchat-slashcommands-mute/server/unmute.js @@ -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 + }); +});