From ddfacb34b0195f9dfcdc816c38304d3905ae321d Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Sun, 15 May 2022 20:45:57 +0530 Subject: [PATCH] [NEW] Ability for Rocket.Chat Apps to delete messages (Derived from #24806) --- apps/meteor/app/apps/server/bridges/messages.ts | 16 ++++++++++++++++ .../packages/rocketchat-i18n/i18n/en.i18n.json | 1 + 2 files changed, 17 insertions(+) diff --git a/apps/meteor/app/apps/server/bridges/messages.ts b/apps/meteor/app/apps/server/bridges/messages.ts index 93eaa0c616b62..fd9282f8fad56 100644 --- a/apps/meteor/app/apps/server/bridges/messages.ts +++ b/apps/meteor/app/apps/server/bridges/messages.ts @@ -10,6 +10,7 @@ import { executeSendMessage } from '../../../lib/server/methods/sendMessage'; import { api } from '../../../../server/sdk/api'; import notifications from '../../../notifications/server/lib/Notifications'; import { AppServerOrchestrator } from '../orchestrator'; +import { deleteMessage } from '../../../lib/server'; export class AppMessageBridge extends MessageBridge { // eslint-disable-next-line no-empty-function @@ -50,6 +51,21 @@ export class AppMessageBridge extends MessageBridge { updateMessage(msg, editor); } + protected async delete(messageId: string, appId: string): Promise { + this.orch.debugLog(`The App ${appId} is deleting a message with id: "${messageId}".`); + + const appUser = Users.findOneByAppId(appId, {}); + if (!appUser) { + throw new Error('Invalid app user, cannot delete message.'); + } + const message = Messages.findOneById(messageId); + if (!message) { + throw new Error('Invalid message, cannot delete message.'); + } + + await deleteMessage(message, appUser); + } + protected async notifyUser(user: IUser, message: IMessage, appId: string): Promise { this.orch.debugLog(`The App ${appId} is notifying a user.`); diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 3baaa21deec4b..b9b337737d1cc 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -518,6 +518,7 @@ "Apps_Permissions_server-setting_write": "Modify settings in this server", "Apps_Permissions_room_read": "Access room information", "Apps_Permissions_room_write": "Create and modify rooms", + "Apps_Permissions_message_delete": "Delete messages", "Apps_Permissions_message_read": "Access messages", "Apps_Permissions_message_write": "Send and modify messages", "Apps_Permissions_livechat-status_read": "Access Livechat status information",