From cea4f949767d2f30658fb4e8ecd00861c92497ff Mon Sep 17 00:00:00 2001 From: eduardofcabrera <64327259+eduardofcabrera@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:11:06 -0300 Subject: [PATCH] Covert to typescript the unarchive slash commands files (#24331) Co-authored-by: Leonardo Ostjen Couto --- .../client/client.js | 7 -- .../client/client.ts | 15 ++++ .../client/{index.js => index.ts} | 0 .../server/{index.js => index.ts} | 0 .../server/server.js | 81 ------------------- .../server/server.ts | 76 +++++++++++++++++ 6 files changed, 91 insertions(+), 88 deletions(-) delete mode 100644 app/slashcommands-unarchiveroom/client/client.js create mode 100644 app/slashcommands-unarchiveroom/client/client.ts rename app/slashcommands-unarchiveroom/client/{index.js => index.ts} (100%) rename app/slashcommands-unarchiveroom/server/{index.js => index.ts} (100%) delete mode 100644 app/slashcommands-unarchiveroom/server/server.js create mode 100644 app/slashcommands-unarchiveroom/server/server.ts diff --git a/app/slashcommands-unarchiveroom/client/client.js b/app/slashcommands-unarchiveroom/client/client.js deleted file mode 100644 index 2495cf81535..00000000000 --- a/app/slashcommands-unarchiveroom/client/client.js +++ /dev/null @@ -1,7 +0,0 @@ -import { slashCommands } from '../../utils'; - -slashCommands.add('unarchive', null, { - description: 'Unarchive', - params: '#channel', - permission: 'unarchive-room', -}); diff --git a/app/slashcommands-unarchiveroom/client/client.ts b/app/slashcommands-unarchiveroom/client/client.ts new file mode 100644 index 00000000000..aab7690912a --- /dev/null +++ b/app/slashcommands-unarchiveroom/client/client.ts @@ -0,0 +1,15 @@ +import { slashCommands } from '../../utils/lib/slashCommand'; + +slashCommands.add( + 'unarchive', + undefined, + { + description: 'Unarchive', + params: '#channel', + permission: 'unarchive-room', + }, + undefined, + false, + undefined, + undefined, +); diff --git a/app/slashcommands-unarchiveroom/client/index.js b/app/slashcommands-unarchiveroom/client/index.ts similarity index 100% rename from app/slashcommands-unarchiveroom/client/index.js rename to app/slashcommands-unarchiveroom/client/index.ts diff --git a/app/slashcommands-unarchiveroom/server/index.js b/app/slashcommands-unarchiveroom/server/index.ts similarity index 100% rename from app/slashcommands-unarchiveroom/server/index.js rename to app/slashcommands-unarchiveroom/server/index.ts diff --git a/app/slashcommands-unarchiveroom/server/server.js b/app/slashcommands-unarchiveroom/server/server.js deleted file mode 100644 index de1f3cf920a..00000000000 --- a/app/slashcommands-unarchiveroom/server/server.js +++ /dev/null @@ -1,81 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Match } from 'meteor/check'; -import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; - -import { Rooms, Messages } from '../../models'; -import { slashCommands } from '../../utils'; -import { roomTypes, RoomMemberActions } from '../../utils/server'; -import { api } from '../../../server/sdk/api'; - -function Unarchive(command, params, item) { - if (command !== 'unarchive' || !Match.test(params, String)) { - return; - } - - let channel = params.trim(); - let room; - - if (channel === '') { - room = Rooms.findOneById(item.rid); - channel = room.name; - } else { - channel = channel.replace('#', ''); - room = Rooms.findOneByName(channel); - } - - const user = Meteor.users.findOne(Meteor.userId()); - - if (!room) { - return api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Channel_doesnt_exist', - { - postProcess: 'sprintf', - sprintf: [channel], - }, - user.language, - ), - }); - } - - // You can not archive direct messages. - if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE)) { - return; - } - - if (!room.archived) { - api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Channel_already_Unarchived', - { - postProcess: 'sprintf', - sprintf: [channel], - }, - user.language, - ), - }); - return; - } - - Meteor.call('unarchiveRoom', room._id); - - Messages.createRoomUnarchivedByRoomIdAndUser(room._id, Meteor.user()); - api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Channel_Unarchived', - { - postProcess: 'sprintf', - sprintf: [channel], - }, - user.language, - ), - }); - - return Unarchive; -} - -slashCommands.add('unarchive', Unarchive, { - description: 'Unarchive', - params: '#channel', - permission: 'unarchive-room', -}); diff --git a/app/slashcommands-unarchiveroom/server/server.ts b/app/slashcommands-unarchiveroom/server/server.ts new file mode 100644 index 00000000000..0da3515a546 --- /dev/null +++ b/app/slashcommands-unarchiveroom/server/server.ts @@ -0,0 +1,76 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { Rooms, Messages } from '../../models/server'; +import { slashCommands } from '../../utils/lib/slashCommand'; +import { roomTypes, RoomMemberActions } from '../../utils/server'; +import { settings } from '../../settings/server'; +import { api } from '../../../server/sdk/api'; + +function Unarchive(_command: 'unarchive', params: string, item: Record): void | Promise | Function { + let channel = params.trim(); + let room; + + if (channel === '') { + room = Rooms.findOneById(item.rid); + channel = room.name; + } else { + channel = channel.replace('#', ''); + room = Rooms.findOneByName(channel); + } + + const userId = Meteor.userId() as string; + + if (!room) { + return api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Channel_doesnt_exist', { + postProcess: 'sprintf', + sprintf: [channel], + lng: settings.get('Language') || 'en', + }), + }); + } + + // You can not archive direct messages. + if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE)) { + return; + } + + if (!room.archived) { + api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Channel_already_Unarchived', { + postProcess: 'sprintf', + sprintf: [channel], + lng: settings.get('Language') || 'en', + }), + }); + return; + } + + Meteor.call('unarchiveRoom', room._id); + + Messages.createRoomUnarchivedByRoomIdAndUser(room._id, Meteor.user()); + api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Channel_Unarchived', { + postProcess: 'sprintf', + sprintf: [channel], + lng: settings.get('Language') || 'en', + }), + }); + + return Unarchive; +} + +slashCommands.add( + 'unarchive', + Unarchive, + { + description: 'Unarchive', + params: '#channel', + permission: 'unarchive-room', + }, + undefined, + false, + undefined, + undefined, +);