Skip to content

Commit 5c7e8ec

Browse files
authored
fix: Editing encrypted message attachment description (#37270)
1 parent b71f838 commit 5c7e8ec

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

.changeset/healthy-colts-notice.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/core-typings': patch
3+
'@rocket.chat/meteor': patch
4+
---
5+
6+
Fixes editing of encrypted message attachment description.

apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
isQuoteAttachment,
88
isTranslatedAttachment,
99
isTranslatedMessage,
10+
isEncryptedMessageAttachment,
1011
} from '@rocket.chat/core-typings';
1112
import type { Options, Root } from '@rocket.chat/message-parser';
1213
import { parse } from '@rocket.chat/message-parser';
@@ -77,9 +78,10 @@ export const parseMessageAttachment = <T extends MessageAttachment>(
7778
'';
7879

7980
if (isFileAttachment(attachment) && attachment.description) {
80-
attachment.descriptionMd = translated
81-
? textToMessageToken(text, parseOptions)
82-
: (attachment.descriptionMd ?? textToMessageToken(text, parseOptions));
81+
attachment.descriptionMd =
82+
translated || isEncryptedMessageAttachment(attachment)
83+
? textToMessageToken(text, parseOptions)
84+
: (attachment.descriptionMd ?? textToMessageToken(text, parseOptions));
8385
}
8486

8587
return {

apps/meteor/tests/e2e/e2e-encryption/e2ee-file-encryption.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe('E2EE File Encryption', () => {
3838
await page.goto('/home');
3939
});
4040

41-
test('File and description encryption', async ({ page }) => {
41+
test('File and description encryption and editing the description', async ({ page }) => {
4242
await test.step('create an encrypted channel', async () => {
4343
const channelName = faker.string.uuid();
4444

@@ -59,6 +59,18 @@ test.describe('E2EE File Encryption', () => {
5959
await expect(poHomeChannel.content.getFileDescription).toHaveText('any_description');
6060
await expect(poHomeChannel.content.lastMessageFileName).toContainText('any_file1.txt');
6161
});
62+
63+
await test.step('edit the description', async () => {
64+
await poHomeChannel.content.openLastMessageMenu();
65+
await poHomeChannel.content.btnOptionEditMessage.click();
66+
67+
expect(await poHomeChannel.composer.inputValue()).toBe('any_description');
68+
69+
await poHomeChannel.content.inputMessage.fill('edited any_description');
70+
await page.keyboard.press('Enter');
71+
72+
await expect(poHomeChannel.content.getFileDescription).toHaveText('edited any_description');
73+
});
6274
});
6375

6476
test('File encryption with whitelisted and blacklisted media types', async ({ page, api }) => {

packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ export type MessageAttachmentBase = {
2121
sha256: string;
2222
};
2323
};
24+
25+
export type EncryptedMessageAttachment = MessageAttachmentBase & {
26+
encryption: Required<MessageAttachmentBase>['encryption'];
27+
};
28+
29+
export const isEncryptedMessageAttachment = (attachment: MessageAttachmentBase): attachment is EncryptedMessageAttachment => {
30+
return attachment?.encryption !== undefined && typeof attachment.encryption === 'object';
31+
};

0 commit comments

Comments
 (0)