Chore: Convert to typescript the mute and unmute slash commands files (#24325)

* Convert to typescript the mute and unmute slash commands files

* Lint fix

Co-authored-by: Leonardo Ostjen Couto <leonardoostjen@gmail.com>
pull/24306/head^2
eduardofcabrera 4 years ago committed by GitHub
parent b58012bdcb
commit 4487f9ecc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      app/slashcommands-mute/index.ts
  2. 0
      app/slashcommands-mute/server/index.ts
  3. 66
      app/slashcommands-mute/server/mute.js
  4. 61
      app/slashcommands-mute/server/mute.ts
  5. 63
      app/slashcommands-mute/server/unmute.js
  6. 60
      app/slashcommands-mute/server/unmute.ts

@ -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',
},
);

@ -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<string, string>): 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,
);

@ -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',
},
);

@ -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<string, string>): void | Promise<void> {
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,
);
Loading…
Cancel
Save