Skip to content

Commit

Permalink
Chore: Convert to typescript the mute and unmute slash commands files (
Browse files Browse the repository at this point in the history
…#24325)

* Convert to typescript the mute and unmute slash commands files

* Lint fix

Co-authored-by: Leonardo Ostjen Couto <leonardoostjen@gmail.com>
  • Loading branch information
eduardofcabrera and ostjen authored Feb 15, 2022
1 parent b58012b commit 4487f9e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 129 deletions.
File renamed without changes.
File renamed without changes.
66 changes: 0 additions & 66 deletions app/slashcommands-mute/server/mute.js

This file was deleted.

61 changes: 61 additions & 0 deletions app/slashcommands-mute/server/mute.ts
Original file line number Diff line number Diff line change
@@ -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,
);
63 changes: 0 additions & 63 deletions app/slashcommands-mute/server/unmute.js

This file was deleted.

60 changes: 60 additions & 0 deletions app/slashcommands-mute/server/unmute.ts
Original file line number Diff line number Diff line change
@@ -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,
);

0 comments on commit 4487f9e

Please sign in to comment.