-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
b58012b
commit 4487f9e
Showing
6 changed files
with
121 additions
and
129 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |