From ac5915f80c3defc6ecfebc4221c9d886b9064eee Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Mon, 24 Mar 2025 21:36:24 +0530 Subject: [PATCH 01/11] don't allow edit message action on otr message --- .../components/message/toolbar/useEditMessageAction.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/meteor/client/components/message/toolbar/useEditMessageAction.ts b/apps/meteor/client/components/message/toolbar/useEditMessageAction.ts index 92df4f7cea35a..c19a2c7b8f5ec 100644 --- a/apps/meteor/client/components/message/toolbar/useEditMessageAction.ts +++ b/apps/meteor/client/components/message/toolbar/useEditMessageAction.ts @@ -1,4 +1,4 @@ -import { isRoomFederated } from '@rocket.chat/core-typings'; +import { isOTRAckMessage, isOTRMessage, isRoomFederated } from '@rocket.chat/core-typings'; import type { IRoom, IMessage, ISubscription } from '@rocket.chat/core-typings'; import { usePermission, useSetting, useUser } from '@rocket.chat/ui-contexts'; import moment from 'moment'; @@ -26,6 +26,10 @@ export const useEditMessageAction = ( return message.u._id === user?._id; } + if (isOTRMessage(message) || isOTRAckMessage(message)) { + return false; + } + const editOwn = message.u && message.u._id === user?._id; if (!canEditMessage && (!isEditAllowed || !editOwn)) { return false; From e04f36338410acd292a4f7384b3c75586736a1d3 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Mon, 24 Mar 2025 21:47:16 +0530 Subject: [PATCH 02/11] skip OTR message when using keyboard events for editing --- apps/meteor/app/ui/client/lib/ChatMessages.ts | 2 +- apps/meteor/client/lib/chats/ChatAPI.ts | 2 +- apps/meteor/client/lib/chats/data.ts | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/ui/client/lib/ChatMessages.ts b/apps/meteor/app/ui/client/lib/ChatMessages.ts index 3745864061f42..a675c413fe18f 100644 --- a/apps/meteor/app/ui/client/lib/ChatMessages.ts +++ b/apps/meteor/app/ui/client/lib/ChatMessages.ts @@ -64,7 +64,7 @@ export class ChatMessages implements ChatAPI { } if (!this.currentEditing) { - let lastMessage = await this.data.findLastOwnMessage(); + let lastMessage = await this.data.findPreviousOwnMessage(); // Videoconf messages should not be edited if (lastMessage && isVideoConfMessage(lastMessage)) { diff --git a/apps/meteor/client/lib/chats/ChatAPI.ts b/apps/meteor/client/lib/chats/ChatAPI.ts index 058870cfbd286..2a2c2c73fbee7 100644 --- a/apps/meteor/client/lib/chats/ChatAPI.ts +++ b/apps/meteor/client/lib/chats/ChatAPI.ts @@ -70,7 +70,7 @@ export type DataAPI = { getLastMessage(): Promise; findLastOwnMessage(): Promise; getLastOwnMessage(): Promise; - findPreviousOwnMessage(message: IMessage): Promise; + findPreviousOwnMessage(message?: IMessage): Promise; getPreviousOwnMessage(message: IMessage): Promise; findNextOwnMessage(message: IMessage): Promise; getNextOwnMessage(message: IMessage): Promise; diff --git a/apps/meteor/client/lib/chats/data.ts b/apps/meteor/client/lib/chats/data.ts index ffb5259983d7b..240e8e27bb196 100644 --- a/apps/meteor/client/lib/chats/data.ts +++ b/apps/meteor/client/lib/chats/data.ts @@ -1,4 +1,11 @@ -import type { IEditedMessage, IMessage, IRoom, ISubscription } from '@rocket.chat/core-typings'; +import { + isOTRAckMessage, + isOTRMessage, + type IEditedMessage, + type IMessage, + type IRoom, + type ISubscription, +} from '@rocket.chat/core-typings'; import { Random } from '@rocket.chat/random'; import moment from 'moment'; @@ -85,6 +92,10 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage return false; } + if (isOTRMessage(message) || isOTRAckMessage(message)) { + return false; + } + const canEditMessage = hasAtLeastOnePermission('edit-message', message.rid); const editAllowed = (settings.get('Message_AllowEditing') as boolean | undefined) ?? false; const editOwn = message?.u && message.u._id === Meteor.userId(); @@ -104,7 +115,7 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage return true; }; - const findPreviousOwnMessage = async (message: IMessage): Promise => { + const findPreviousOwnMessage = async (message?: IMessage): Promise => { const uid = Meteor.userId(); if (!uid) { @@ -112,7 +123,7 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage } const msg = Messages.findOne( - { rid, 'tmid': tmid ?? { $exists: false }, 'u._id': uid, '_hidden': { $ne: true }, 'ts': { $lt: message.ts } }, + { rid, 'tmid': tmid ?? { $exists: false }, 'u._id': uid, '_hidden': { $ne: true }, 'ts': { ...(message && { $lt: message.ts }) } }, { sort: { ts: -1 }, reactive: false }, ); From f151642361fd0584a656a01ae3716078ef1dedaa Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Mon, 24 Mar 2025 22:09:06 +0530 Subject: [PATCH 03/11] add cs --- .changeset/hungry-games-smoke.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-games-smoke.md diff --git a/.changeset/hungry-games-smoke.md b/.changeset/hungry-games-smoke.md new file mode 100644 index 0000000000000..350c33091aaaf --- /dev/null +++ b/.changeset/hungry-games-smoke.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Blocks edit message action for Off-The-Record (OTR) messages. From f02193c3702d0a499ee14cae9bdf4422607438ee Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 15 Apr 2025 18:56:53 +0530 Subject: [PATCH 04/11] chore: remove unused functions --- apps/meteor/client/lib/chats/ChatAPI.ts | 2 -- apps/meteor/client/lib/chats/data.ts | 25 ------------------------- 2 files changed, 27 deletions(-) diff --git a/apps/meteor/client/lib/chats/ChatAPI.ts b/apps/meteor/client/lib/chats/ChatAPI.ts index 2a2c2c73fbee7..f41e9366ceee9 100644 --- a/apps/meteor/client/lib/chats/ChatAPI.ts +++ b/apps/meteor/client/lib/chats/ChatAPI.ts @@ -68,8 +68,6 @@ export type DataAPI = { getMessageByID(mid: IMessage['_id']): Promise; findLastMessage(): Promise; getLastMessage(): Promise; - findLastOwnMessage(): Promise; - getLastOwnMessage(): Promise; findPreviousOwnMessage(message?: IMessage): Promise; getPreviousOwnMessage(message: IMessage): Promise; findNextOwnMessage(message: IMessage): Promise; diff --git a/apps/meteor/client/lib/chats/data.ts b/apps/meteor/client/lib/chats/data.ts index 240e8e27bb196..260db8da3f303 100644 --- a/apps/meteor/client/lib/chats/data.ts +++ b/apps/meteor/client/lib/chats/data.ts @@ -64,29 +64,6 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage return message; }; - const findLastOwnMessage = async (): Promise => { - const uid = Meteor.userId(); - - if (!uid) { - return undefined; - } - - return Messages.findOne( - { rid, 'tmid': tmid ?? { $exists: false }, 'u._id': uid, '_hidden': { $ne: true } }, - { sort: { ts: -1 }, reactive: false }, - ); - }; - - const getLastOwnMessage = async (): Promise => { - const message = await findLastOwnMessage(); - - if (!message) { - throw new Error('Message not found'); - } - - return message; - }; - const canUpdateMessage = async (message: IMessage): Promise => { if (MessageTypes.isSystemMessage(message)) { return false; @@ -319,8 +296,6 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage getMessageByID, findLastMessage, getLastMessage, - findLastOwnMessage, - getLastOwnMessage, findPreviousOwnMessage, getPreviousOwnMessage, findNextOwnMessage, From fce3763a40c0317957dd1acfe8c750808c10aaa2 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Thu, 8 May 2025 20:22:16 +0530 Subject: [PATCH 05/11] add e2e test --- apps/meteor/tests/e2e/otr.spec.ts | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/apps/meteor/tests/e2e/otr.spec.ts b/apps/meteor/tests/e2e/otr.spec.ts index b6ff4789e0c27..f835ac7b66fdd 100644 --- a/apps/meteor/tests/e2e/otr.spec.ts +++ b/apps/meteor/tests/e2e/otr.spec.ts @@ -43,4 +43,67 @@ test.describe.serial('OTR', () => { await user1Page.close(); }); + + test('should not allow edit OTR messages', async ({ browser, page }) => { + const user1Page = await browser.newPage({ storageState: Users.user1.state }); + const user1Channel = new HomeChannel(user1Page); + + await test.step('log in user1', async () => { + await user1Page.goto(`/direct/${Users.admin.data.username}`); + await user1Channel.content.waitForChannel(); + }); + + await test.step('send normal messages', async () => { + await poHomeChannel.sidenav.openChat(Users.user1.data.username); + await poHomeChannel.content.sendMessage('Normal message'); + await user1Channel.content.sendMessage('Normal message'); + }); + + await test.step('invite OTR with user1', async () => { + await poHomeChannel.tabs.kebab.click({ force: true }); + await poHomeChannel.tabs.btnEnableOTR.click({ force: true }); + await poHomeChannel.tabs.otr.btnStartOTR.click(); + }); + + await test.step('accept handshake with user1', async () => { + await user1Channel.tabs.otr.btnAcceptOTR.click(); + }); + + await test.step('send OTR messages', async () => { + await poHomeChannel.content.sendMessage('hello user1'); + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-stopwatch')).toBeVisible(); + + await user1Channel.content.sendMessage('hello admin'); + await expect(user1Channel.content.lastUserMessage.locator('.rcx-icon--name-stopwatch')).toBeVisible(); + }); + + await test.step('not show edit message action', async () => { + await poHomeChannel.content.openLastMessageMenu(); + await expect(page.locator('role=menuitem[name="Edit"]')).not.toBeVisible(); + + await user1Channel.content.openLastMessageMenu(); + await expect(user1Channel.content.lastUserMessage.locator('role=menuitem[name="Edit"]')).not.toBeVisible(); + + await page.keyboard.press('Escape'); + await user1Page.keyboard.press('Escape'); + }); + + await test.step('should allow edit normal messages when using keyboard edit action', async () => { + await page.locator('[name="msg"]').focus(); + await page.keyboard.press('ArrowUp'); + await expect(page.locator('[name="msg"]')).toHaveValue('Normal message'); + await page.locator('[name="msg"]').fill('Normal message edited'); + await page.keyboard.press('Enter'); + await expect(page.locator('.rcx-toastbar.rcx-toastbar--error')).toBeVisible(); + + await user1Page.locator('[name="msg"]').focus(); + await user1Page.keyboard.press('ArrowUp'); + await expect(user1Page.locator('[name="msg"]')).toHaveValue('Normal message'); + await user1Page.locator('[name="msg"]').fill('Normal message edited'); + await user1Page.keyboard.press('Enter'); + await expect(user1Page.locator('.rcx-toastbar.rcx-toastbar--error')).toBeVisible(); + }); + + await user1Page.close(); + }); }); From 51e272007d2a3cfe2549305259a572a5c5bca4f8 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Thu, 8 May 2025 20:24:18 +0530 Subject: [PATCH 06/11] test spec --- apps/meteor/tests/e2e/otr.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/tests/e2e/otr.spec.ts b/apps/meteor/tests/e2e/otr.spec.ts index f835ac7b66fdd..6757cec4cf0db 100644 --- a/apps/meteor/tests/e2e/otr.spec.ts +++ b/apps/meteor/tests/e2e/otr.spec.ts @@ -88,7 +88,7 @@ test.describe.serial('OTR', () => { await user1Page.keyboard.press('Escape'); }); - await test.step('should allow edit normal messages when using keyboard edit action', async () => { + await test.step('keyboard edit action when using up arrow key should show normal messages', async () => { await page.locator('[name="msg"]').focus(); await page.keyboard.press('ArrowUp'); await expect(page.locator('[name="msg"]')).toHaveValue('Normal message'); From 559dc886598fce5bba3ff22443d5c6c83a97ab72 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Fri, 9 May 2025 22:18:03 +0530 Subject: [PATCH 07/11] fix: Editing non OTR messages when OTR session is active --- .../components/message/variants/RoomMessage.tsx | 13 ++++++------- apps/meteor/client/lib/chats/flows/sendMessage.ts | 3 ++- apps/meteor/client/lib/onClientBeforeSendMessage.ts | 2 +- .../client/views/root/hooks/useOTRMessaging.ts | 8 ++++++-- packages/i18n/src/locales/en.i18n.json | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/meteor/client/components/message/variants/RoomMessage.tsx b/apps/meteor/client/components/message/variants/RoomMessage.tsx index 3832aa216163d..a939487015af0 100644 --- a/apps/meteor/client/components/message/variants/RoomMessage.tsx +++ b/apps/meteor/client/components/message/variants/RoomMessage.tsx @@ -1,4 +1,4 @@ -import type { IMessage } from '@rocket.chat/core-typings'; +import { type IMessage, isOTRAckMessage, isOTRMessage } from '@rocket.chat/core-typings'; import { Message, MessageLeftContainer, MessageContainer, CheckBox } from '@rocket.chat/fuselage'; import { useToggle } from '@rocket.chat/fuselage-hooks'; import { MessageAvatar } from '@rocket.chat/ui-avatar'; @@ -55,13 +55,12 @@ const RoomMessage = ({ const { openUserCard, triggerProps } = useUserCard(); const selecting = useIsSelecting(); - const isOTRMessage = message.t === 'otr' || message.t === 'otr-ack'; + const isOTRMsg = isOTRMessage(message) || isOTRAckMessage(message); const toggleSelected = useToggleSelect(message._id); - const selected = useIsSelectedMessage(message._id, isOTRMessage); + const selected = useIsSelectedMessage(message._id, isOTRMsg); useCountSelected(); - const messageRef = useJumpToMessage(message._id); return ( @@ -69,10 +68,10 @@ const RoomMessage = ({ ref={messageRef} id={message._id} role='listitem' - aria-roledescription={t('message')} + aria-roledescription={isOTRMsg ? t('OTR_message') : t('message')} tabIndex={0} aria-labelledby={`${message._id}-displayName ${message._id}-time ${message._id}-content ${message._id}-read-status`} - onClick={selecting && !isOTRMessage ? toggleSelected : undefined} + onClick={selecting && !isOTRMsg ? toggleSelected : undefined} isSelected={selected} isEditing={editing} isPending={message.temp} @@ -101,7 +100,7 @@ const RoomMessage = ({ {...triggerProps} /> )} - {selecting && } + {selecting && } {sequential && } diff --git a/apps/meteor/client/lib/chats/flows/sendMessage.ts b/apps/meteor/client/lib/chats/flows/sendMessage.ts index 3d372900fb299..0fb16296a8582 100644 --- a/apps/meteor/client/lib/chats/flows/sendMessage.ts +++ b/apps/meteor/client/lib/chats/flows/sendMessage.ts @@ -23,10 +23,11 @@ const process = async (chat: ChatAPI, message: IMessage, previewUrls?: string[], return; } - message = (await onClientBeforeSendMessage(message)) as IMessage; + message = (await onClientBeforeSendMessage({ ...message, isEditing: !!chat.currentEditing })) as IMessage & { isEditing?: boolean }; // e2e should be a client property only delete message.e2e; + delete (message as IMessage & { isEditing?: boolean }).isEditing; if (await processMessageEditing(chat, message, previewUrls)) { return; diff --git a/apps/meteor/client/lib/onClientBeforeSendMessage.ts b/apps/meteor/client/lib/onClientBeforeSendMessage.ts index e2e0404b9b301..e312b4f184f37 100644 --- a/apps/meteor/client/lib/onClientBeforeSendMessage.ts +++ b/apps/meteor/client/lib/onClientBeforeSendMessage.ts @@ -2,4 +2,4 @@ import type { AtLeast, IMessage } from '@rocket.chat/core-typings'; import { createAsyncTransformChain } from '../../lib/transforms'; -export const onClientBeforeSendMessage = createAsyncTransformChain>(); +export const onClientBeforeSendMessage = createAsyncTransformChain & { isEditing?: boolean }>(); diff --git a/apps/meteor/client/views/root/hooks/useOTRMessaging.ts b/apps/meteor/client/views/root/hooks/useOTRMessaging.ts index b3195326fe8c6..8a6e778d15a25 100644 --- a/apps/meteor/client/views/root/hooks/useOTRMessaging.ts +++ b/apps/meteor/client/views/root/hooks/useOTRMessaging.ts @@ -24,14 +24,18 @@ export const useOTRMessaging = (uid: string) => { }; const handleBeforeSendMessage = async ( - message: AtLeast, + message: AtLeast & { isEditing?: boolean }, ): Promise> => { if (!uid) { return message; } - const otrRoom = OTR.getInstanceByRoomId(uid, message.rid); + if (message.isEditing) { + return (({ isEditing: _isEditing, ...rest }) => rest)(message); + } + delete message.isEditing; + const otrRoom = OTR.getInstanceByRoomId(uid, message.rid); if (otrRoom && otrRoom.getState() === OtrRoomState.ESTABLISHED) { const msg = await otrRoom.encrypt(message); return { ...message, msg, t: 'otr' }; diff --git a/packages/i18n/src/locales/en.i18n.json b/packages/i18n/src/locales/en.i18n.json index dbabfaa7b393e..d18622f632885 100644 --- a/packages/i18n/src/locales/en.i18n.json +++ b/packages/i18n/src/locales/en.i18n.json @@ -3690,7 +3690,7 @@ "OTR_Enable_Description": "Enable option to use off-the-record (OTR) messages in direct messages between 2 users. OTR messages are not recorded on the server and exchanged directly and encrypted between the 2 users.", "OTR_Session_ended_other_user_went_offline": "OTR Session has ended. User {{username}} went offline", "OTR_is_only_available_when_both_users_are_online": "OTR is only available when both users are online", - "OTR_message": "OTR Message", + "OTR_message": "OTR message", "OTR_messages_cannot_be_exported": "OTR messages cannot be exported", "OTR_not_available": "OTR not available", "OTR_not_available_e2ee": "This room has E2E encryption enabled, OTR cannot work with encrypted messages.", @@ -6830,4 +6830,4 @@ "__usernames__joined": "{{usernames}} joined", "__usersCount__joined": "{{count}} joined", "__usersCount__people_will_be_invited": "{{usersCount}} people will be invited" -} \ No newline at end of file +} From b36bec579d1747999a93d1219973a252c1db351f Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Fri, 9 May 2025 22:18:29 +0530 Subject: [PATCH 08/11] improve test --- apps/meteor/tests/e2e/otr.spec.ts | 25 ++++++++++--------- .../page-objects/fragments/home-content.ts | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/meteor/tests/e2e/otr.spec.ts b/apps/meteor/tests/e2e/otr.spec.ts index 6757cec4cf0db..f045730836517 100644 --- a/apps/meteor/tests/e2e/otr.spec.ts +++ b/apps/meteor/tests/e2e/otr.spec.ts @@ -71,37 +71,38 @@ test.describe.serial('OTR', () => { await test.step('send OTR messages', async () => { await poHomeChannel.content.sendMessage('hello user1'); - await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-stopwatch')).toBeVisible(); + await expect(poHomeChannel.content.lastUserMessage).toHaveAttribute('aria-roledescription', 'OTR message'); await user1Channel.content.sendMessage('hello admin'); - await expect(user1Channel.content.lastUserMessage.locator('.rcx-icon--name-stopwatch')).toBeVisible(); + await expect(user1Channel.content.lastUserMessage).toHaveAttribute('aria-roledescription', 'OTR message'); }); await test.step('not show edit message action', async () => { await poHomeChannel.content.openLastMessageMenu(); - await expect(page.locator('role=menuitem[name="Edit"]')).not.toBeVisible(); + await expect(poHomeChannel.content.btnOptionEditMessage).not.toBeVisible(); await user1Channel.content.openLastMessageMenu(); - await expect(user1Channel.content.lastUserMessage.locator('role=menuitem[name="Edit"]')).not.toBeVisible(); + await expect(user1Channel.content.btnOptionEditMessage).not.toBeVisible(); await page.keyboard.press('Escape'); await user1Page.keyboard.press('Escape'); }); await test.step('keyboard edit action when using up arrow key should show normal messages', async () => { - await page.locator('[name="msg"]').focus(); + // await page.waitForTimeout(100000); + await poHomeChannel.composer.focus(); await page.keyboard.press('ArrowUp'); - await expect(page.locator('[name="msg"]')).toHaveValue('Normal message'); - await page.locator('[name="msg"]').fill('Normal message edited'); + await expect(poHomeChannel.composer).toHaveValue('Normal message'); + await poHomeChannel.composer.fill('Normal message edited'); await page.keyboard.press('Enter'); - await expect(page.locator('.rcx-toastbar.rcx-toastbar--error')).toBeVisible(); + await expect(poHomeChannel.content.nthMessage(0)).toContainText('Normal message edited'); - await user1Page.locator('[name="msg"]').focus(); + await user1Channel.composer.focus(); await user1Page.keyboard.press('ArrowUp'); - await expect(user1Page.locator('[name="msg"]')).toHaveValue('Normal message'); - await user1Page.locator('[name="msg"]').fill('Normal message edited'); + await expect(user1Channel.composer).toHaveValue('Normal message'); + await user1Channel.composer.fill('Normal message edited'); await user1Page.keyboard.press('Enter'); - await expect(user1Page.locator('.rcx-toastbar.rcx-toastbar--error')).toBeVisible(); + await expect(user1Channel.content.nthMessage(0)).toContainText('Normal message edited'); }); await user1Page.close(); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts index 63e03a71e38aa..59ac608a432ec 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -197,7 +197,7 @@ export class HomeContent { } get btnOptionEditMessage(): Locator { - return this.page.locator('[data-qa-id="edit-message"]'); + return this.page.locator('role=menu[name="More"] >> role=menuitem[name="Edit"]'); } get btnOptionDeleteMessage(): Locator { From 78fd4069d04c160ce84f2f682918723df970cbf9 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Sat, 10 May 2025 02:00:13 +0530 Subject: [PATCH 09/11] fix other OTR test --- apps/meteor/tests/e2e/otr.spec.ts | 2 +- apps/meteor/tests/e2e/page-objects/fragments/home-content.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/meteor/tests/e2e/otr.spec.ts b/apps/meteor/tests/e2e/otr.spec.ts index f045730836517..555641cf330ab 100644 --- a/apps/meteor/tests/e2e/otr.spec.ts +++ b/apps/meteor/tests/e2e/otr.spec.ts @@ -38,7 +38,7 @@ test.describe.serial('OTR', () => { await poHomeChannel.content.sendMessage('hello OTR'); await poHomeChannel.tabs.kebab.click({ force: true }); await poHomeChannel.tabs.btnExportMessages.click(); - await poHomeChannel.content.getMessageByText('hello OTR').click(); + await poHomeChannel.content.getOTRMessageByText('hello OTR').click(); await expect(poHomeChannel.content.btnClearSelection).toBeDisabled(); await user1Page.close(); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts index 59ac608a432ec..5fcb7a044fe87 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -446,6 +446,10 @@ export class HomeContent { return this.page.locator('[role="listitem"][aria-roledescription="message"]', { hasText: text }); } + getOTRMessageByText(text: string): Locator { + return this.page.locator('[role="listitem"][aria-roledescription="OTR message"]', { hasText: text }); + } + getMessageById(id: string): Locator { return this.page.locator(`[data-qa-type="message"][id="${id}"]`); } From e1648bb2bb709d0a0165c86f8af51fe184ecf1a0 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Sat, 10 May 2025 02:09:23 +0530 Subject: [PATCH 10/11] remove comment --- apps/meteor/tests/e2e/otr.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/meteor/tests/e2e/otr.spec.ts b/apps/meteor/tests/e2e/otr.spec.ts index 555641cf330ab..e909673a4fb83 100644 --- a/apps/meteor/tests/e2e/otr.spec.ts +++ b/apps/meteor/tests/e2e/otr.spec.ts @@ -89,7 +89,6 @@ test.describe.serial('OTR', () => { }); await test.step('keyboard edit action when using up arrow key should show normal messages', async () => { - // await page.waitForTimeout(100000); await poHomeChannel.composer.focus(); await page.keyboard.press('ArrowUp'); await expect(poHomeChannel.composer).toHaveValue('Normal message'); From 2a8b74055c6a06a479d245d2e0e962c9c0b8af6f Mon Sep 17 00:00:00 2001 From: dougfabris Date: Mon, 12 May 2025 14:24:59 -0300 Subject: [PATCH 11/11] fix: review --- .../message/variants/ThreadMessagePreview.tsx | 12 ++++++------ packages/i18n/src/locales/en.i18n.json | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/meteor/client/components/message/variants/ThreadMessagePreview.tsx b/apps/meteor/client/components/message/variants/ThreadMessagePreview.tsx index 9b905fd085c6b..af0aadefbf308 100644 --- a/apps/meteor/client/components/message/variants/ThreadMessagePreview.tsx +++ b/apps/meteor/client/components/message/variants/ThreadMessagePreview.tsx @@ -1,4 +1,4 @@ -import type { IThreadMessage } from '@rocket.chat/core-typings'; +import { isOTRAckMessage, isOTRMessage, type IThreadMessage } from '@rocket.chat/core-typings'; import { Skeleton, ThreadMessage, @@ -45,10 +45,10 @@ const ThreadMessagePreview = ({ message, showUserAvatar, sequential, ...props }: const { t } = useTranslation(); const isSelecting = useIsSelecting(); - const isOTRMessage = message.t === 'otr' || message.t === 'otr-ack'; + const isOTRMsg = isOTRMessage(message) || isOTRAckMessage(message); const toggleSelected = useToggleSelect(message._id); - const isSelected = useIsSelectedMessage(message._id, isOTRMessage); + const isSelected = useIsSelectedMessage(message._id, isOTRMsg); useCountSelected(); const messageType = parentMessage.isSuccess ? MessageTypes.getType(parentMessage.data) : null; @@ -67,7 +67,7 @@ const ThreadMessagePreview = ({ message, showUserAvatar, sequential, ...props }: return goToThread({ rid: message.rid, tmid: message.tmid, msg: message._id }); } - if (isOTRMessage) { + if (isOTRMsg) { return; } @@ -77,7 +77,7 @@ const ThreadMessagePreview = ({ message, showUserAvatar, sequential, ...props }: return ( e.code === 'Enter' && handleThreadClick()} @@ -123,7 +123,7 @@ const ThreadMessagePreview = ({ message, showUserAvatar, sequential, ...props }: size='x18' /> )} - {isSelecting && } + {isSelecting && } diff --git a/packages/i18n/src/locales/en.i18n.json b/packages/i18n/src/locales/en.i18n.json index d18622f632885..c7ac749857224 100644 --- a/packages/i18n/src/locales/en.i18n.json +++ b/packages/i18n/src/locales/en.i18n.json @@ -3689,6 +3689,7 @@ "OTR_Description": "Off-the-record chats are secure, private and disappear once ended.", "OTR_Enable_Description": "Enable option to use off-the-record (OTR) messages in direct messages between 2 users. OTR messages are not recorded on the server and exchanged directly and encrypted between the 2 users.", "OTR_Session_ended_other_user_went_offline": "OTR Session has ended. User {{username}} went offline", + "OTR_thread_message_preview": "OTR thread message preview", "OTR_is_only_available_when_both_users_are_online": "OTR is only available when both users are online", "OTR_message": "OTR message", "OTR_messages_cannot_be_exported": "OTR messages cannot be exported", @@ -6649,6 +6650,7 @@ "this_app_is_included_with_subscription": "This app is included with {{bundleName}} plans", "thread": "thread", "thread_message": "thread message", + "thread_message_preview": "thread message preview", "threads_counter_one": "{{count}} unread threaded message", "threads_counter_other": "{{count}} unread threaded messages", "to_see_more_details_on_how_to_integrate": "to see more details on how to integrate.",