diff --git a/.changeset/healthy-colts-notice.md b/.changeset/healthy-colts-notice.md new file mode 100644 index 0000000000000..89d708a555e89 --- /dev/null +++ b/.changeset/healthy-colts-notice.md @@ -0,0 +1,6 @@ +--- +'@rocket.chat/core-typings': patch +'@rocket.chat/meteor': patch +--- + +Fixes editing of encrypted message attachment description. diff --git a/apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts b/apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts index 969f36a6f2fc8..1994d868925ee 100644 --- a/apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts +++ b/apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts @@ -7,6 +7,7 @@ import { isQuoteAttachment, isTranslatedAttachment, isTranslatedMessage, + isEncryptedMessageAttachment, } from '@rocket.chat/core-typings'; import type { Options, Root } from '@rocket.chat/message-parser'; import { parse } from '@rocket.chat/message-parser'; @@ -77,9 +78,10 @@ export const parseMessageAttachment = ( ''; if (isFileAttachment(attachment) && attachment.description) { - attachment.descriptionMd = translated - ? textToMessageToken(text, parseOptions) - : (attachment.descriptionMd ?? textToMessageToken(text, parseOptions)); + attachment.descriptionMd = + translated || isEncryptedMessageAttachment(attachment) + ? textToMessageToken(text, parseOptions) + : (attachment.descriptionMd ?? textToMessageToken(text, parseOptions)); } return { diff --git a/apps/meteor/tests/e2e/e2e-encryption/e2ee-file-encryption.spec.ts b/apps/meteor/tests/e2e/e2e-encryption/e2ee-file-encryption.spec.ts index 7b009c7723db8..bfb18e84f4b3f 100644 --- a/apps/meteor/tests/e2e/e2e-encryption/e2ee-file-encryption.spec.ts +++ b/apps/meteor/tests/e2e/e2e-encryption/e2ee-file-encryption.spec.ts @@ -38,7 +38,7 @@ test.describe('E2EE File Encryption', () => { await page.goto('/home'); }); - test('File and description encryption', async ({ page }) => { + test('File and description encryption and editing the description', async ({ page }) => { await test.step('create an encrypted channel', async () => { const channelName = faker.string.uuid(); @@ -59,6 +59,18 @@ test.describe('E2EE File Encryption', () => { await expect(poHomeChannel.content.getFileDescription).toHaveText('any_description'); await expect(poHomeChannel.content.lastMessageFileName).toContainText('any_file1.txt'); }); + + await test.step('edit the description', async () => { + await poHomeChannel.content.openLastMessageMenu(); + await poHomeChannel.content.btnOptionEditMessage.click(); + + expect(await poHomeChannel.composer.inputValue()).toBe('any_description'); + + await poHomeChannel.content.inputMessage.fill('edited any_description'); + await page.keyboard.press('Enter'); + + await expect(poHomeChannel.content.getFileDescription).toHaveText('edited any_description'); + }); }); test('File encryption with whitelisted and blacklisted media types', async ({ page, api }) => { diff --git a/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts b/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts index 27271a6625195..f870f8cfc1ec7 100644 --- a/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts +++ b/packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts @@ -21,3 +21,11 @@ export type MessageAttachmentBase = { sha256: string; }; }; + +export type EncryptedMessageAttachment = MessageAttachmentBase & { + encryption: Required['encryption']; +}; + +export const isEncryptedMessageAttachment = (attachment: MessageAttachmentBase): attachment is EncryptedMessageAttachment => { + return attachment?.encryption !== undefined && typeof attachment.encryption === 'object'; +};