diff --git a/app/slashcommands-mute/index.js b/app/slashcommands-mute/index.ts similarity index 100% rename from app/slashcommands-mute/index.js rename to app/slashcommands-mute/index.ts diff --git a/app/slashcommands-mute/server/index.js b/app/slashcommands-mute/server/index.ts similarity index 100% rename from app/slashcommands-mute/server/index.js rename to app/slashcommands-mute/server/index.ts diff --git a/app/slashcommands-mute/server/mute.js b/app/slashcommands-mute/server/mute.js deleted file mode 100644 index 6858cc07a56..00000000000 --- a/app/slashcommands-mute/server/mute.js +++ /dev/null @@ -1,66 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Match } from 'meteor/check'; -import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; - -import { slashCommands } from '../../utils'; -import { Users, Subscriptions } from '../../models'; -import { api } from '../../../server/sdk/api'; - -/* - * Mute is a named function that will replace /mute commands - */ - -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 userId = Meteor.userId(); - const user = Meteor.users.findOne(userId); - const mutedUser = Users.findOneByUsernameIgnoringCase(username); - if (mutedUser == null) { - api.broadcast('notify.ephemeralMessage', userId, item.rid, { - msg: TAPi18n.__( - 'Username_doesnt_exist', - { - postProcess: 'sprintf', - sprintf: [username], - }, - user.language, - ), - }); - return; - } - - const subscription = Subscriptions.findOneByRoomIdAndUserId(item.rid, mutedUser._id, { - fields: { _id: 1 }, - }); - if (!subscription) { - api.broadcast('notify.ephemeralMessage', userId, item.rid, { - msg: TAPi18n.__( - 'Username_is_not_in_this_room', - { - postProcess: 'sprintf', - sprintf: [username], - }, - user.language, - ), - }); - return; - } - Meteor.call('muteUserInRoom', { - rid: item.rid, - username, - }); - }, - { - description: 'Mute_someone_in_room', - params: '@username', - permission: 'mute-user', - }, -); diff --git a/app/slashcommands-mute/server/mute.ts b/app/slashcommands-mute/server/mute.ts new file mode 100644 index 00000000000..ee000c5667f --- /dev/null +++ b/app/slashcommands-mute/server/mute.ts @@ -0,0 +1,61 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { slashCommands } from '../../utils/lib/slashCommand'; +import { settings } from '../../settings/server'; +import { Users, Subscriptions } from '../../models/server'; +import { api } from '../../../server/sdk/api'; + +/* + * Mute is a named function that will replace /mute commands + */ + +function Mute(_command: 'mute', params: string, item: Record): void { + const username = params.trim().replace('@', ''); + if (username === '') { + return; + } + + const userId = Meteor.userId() as string; + const mutedUser = Users.findOneByUsernameIgnoringCase(username); + if (mutedUser == null) { + api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Username_doesnt_exist', { + postProcess: 'sprintf', + sprintf: [username], + lng: settings.get('Language') || 'en', + }), + }); + } + const subscription = Subscriptions.findOneByRoomIdAndUserId(item.rid, mutedUser._id, { + fields: { _id: 1 }, + }); + if (!subscription) { + api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Username_is_not_in_this_room', { + postProcess: 'sprintf', + sprintf: [username], + lng: settings.get('Language') || 'en', + }), + }); + return; + } + Meteor.call('muteUserInRoom', { + rid: item.rid, + username, + }); +} + +slashCommands.add( + 'mute', + Mute, + { + description: 'Mute_someone_in_room', + params: '@username', + permission: 'mute-user', + }, + undefined, + false, + undefined, + undefined, +); diff --git a/app/slashcommands-mute/server/unmute.js b/app/slashcommands-mute/server/unmute.js deleted file mode 100644 index 4d9a5185732..00000000000 --- a/app/slashcommands-mute/server/unmute.js +++ /dev/null @@ -1,63 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Match } from 'meteor/check'; -import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; - -import { slashCommands } from '../../utils'; -import { Users, Subscriptions } from '../../models'; -import { api } from '../../../server/sdk/api'; - -/* - * Unmute is a named function that will replace /unmute commands - */ - -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 = Users.findOneByUsernameIgnoringCase(username); - if (unmutedUser == null) { - return api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Username_doesnt_exist', - { - postProcess: 'sprintf', - sprintf: [username], - }, - user.language, - ), - }); - } - - const subscription = Subscriptions.findOneByRoomIdAndUserId(item.rid, unmutedUser._id, { - fields: { _id: 1 }, - }); - if (!subscription) { - return api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Username_is_not_in_this_room', - { - postProcess: 'sprintf', - sprintf: [username], - }, - user.language, - ), - }); - } - Meteor.call('unmuteUserInRoom', { - rid: item.rid, - username, - }); - }, - { - description: 'Unmute_someone_in_room', - params: '@username', - permission: 'mute-user', - }, -); diff --git a/app/slashcommands-mute/server/unmute.ts b/app/slashcommands-mute/server/unmute.ts new file mode 100644 index 00000000000..bcc43f1b1f1 --- /dev/null +++ b/app/slashcommands-mute/server/unmute.ts @@ -0,0 +1,60 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { slashCommands } from '../../utils/lib/slashCommand'; +import { Users, Subscriptions } from '../../models/server'; +import { settings } from '../../settings/server'; +import { api } from '../../../server/sdk/api'; + +/* + * Unmute is a named function that will replace /unmute commands + */ + +function Unmute(_command: 'unmute', params: string, item: Record): void | Promise { + const username = params.trim().replace('@', ''); + if (username === '') { + return; + } + const userId = Meteor.userId() as string; + const unmutedUser = Users.findOneByUsernameIgnoringCase(username); + if (unmutedUser == null) { + return api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Username_doesnt_exist', { + postProcess: 'sprintf', + sprintf: [username], + lng: settings.get('Language') || 'en', + }), + }); + } + + const subscription = Subscriptions.findOneByRoomIdAndUserId(item.rid, unmutedUser._id, { + fields: { _id: 1 }, + }); + if (!subscription) { + return api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Username_is_not_in_this_room', { + postProcess: 'sprintf', + sprintf: [username], + lng: settings.get('Language') || 'en', + }), + }); + } + Meteor.call('unmuteUserInRoom', { + rid: item.rid, + username, + }); +} + +slashCommands.add( + 'unmute', + Unmute, + { + description: 'Unmute_someone_in_room', + params: '@username', + permission: 'mute-user', + }, + undefined, + false, + undefined, + undefined, +);