diff --git a/apps/meteor/app/e2e/client/rocketchat.e2e.ts b/apps/meteor/app/e2e/client/rocketchat.e2e.ts index 472e71959933..f1ae89c6e403 100644 --- a/apps/meteor/app/e2e/client/rocketchat.e2e.ts +++ b/apps/meteor/app/e2e/client/rocketchat.e2e.ts @@ -1,7 +1,7 @@ import QueryString from 'querystring'; import URL from 'url'; -import type { IE2EEMessage, IMessage, IRoom, ISubscription } from '@rocket.chat/core-typings'; +import type { IE2EEMessage, IMessage, IRoom, ISubscription, MessageAttachment } from '@rocket.chat/core-typings'; import { isE2EEMessage, isFileAttachment } from '@rocket.chat/core-typings'; import { Emitter } from '@rocket.chat/emitter'; import EJSON from 'ejson'; @@ -40,6 +40,7 @@ import { } from './helper'; import { log, logError } from './logger'; import { E2ERoom } from './rocketchat.e2e.room'; + import './events.js'; let failedToDecodeKey = false; @@ -409,6 +410,30 @@ class E2E extends Emitter { } } + async decryptPinnedMessage(message: IMessage) { + if (!message?.attachments || !message.attachments[0]?.text || message.attachments[0]?.t !== 'e2e') { + return message; + } + + const e2eRoom = await this.getInstanceByRoomId(message.rid); + const pinnedMessage = message.attachments[0]?.text; + + if (!e2eRoom || !pinnedMessage) { + return message; + } + + const data = await e2eRoom.decrypt(pinnedMessage); + + if (!data) { + return message; + } + + const decryptedPinnedMessage = { ...message } as IMessage & { attachments: MessageAttachment[] }; + decryptedPinnedMessage.attachments[0].text = data.text; + + return decryptedPinnedMessage; + } + async decryptMessage(message: IMessage | IE2EEMessage): Promise { if (!isE2EEMessage(message) || message.e2e === 'done') { return message; diff --git a/apps/meteor/app/message-pin/server/pinMessage.ts b/apps/meteor/app/message-pin/server/pinMessage.ts index dc17a75a0192..940a0877ecb2 100644 --- a/apps/meteor/app/message-pin/server/pinMessage.ts +++ b/apps/meteor/app/message-pin/server/pinMessage.ts @@ -139,6 +139,7 @@ Meteor.methods({ author_icon: getUserAvatarURL(originalMessage.u.username), ts: originalMessage.ts, attachments: attachments.map(recursiveRemove), + t: originalMessage?.t, }, ], }); diff --git a/apps/meteor/client/startup/e2e.ts b/apps/meteor/client/startup/e2e.ts index f9cf156f8d8b..b07d5041790c 100644 --- a/apps/meteor/client/startup/e2e.ts +++ b/apps/meteor/client/startup/e2e.ts @@ -118,6 +118,11 @@ Meteor.startup(() => { if (!e2eRoom?.shouldConvertReceivedMessages()) { return msg; } + + if (msg.t === 'message_pinned') { + return e2e.decryptPinnedMessage(msg); + } + return e2e.decryptMessage(msg); }); diff --git a/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts b/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts index efcd7725102d..f6837a7a9703 100644 --- a/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts +++ b/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts @@ -27,4 +27,6 @@ export type MessageAttachmentDefault = { thumb_url?: string; color?: string; + + t?: 'e2e'; } & MessageAttachmentBase;