diff --git a/apps/meteor/client/startup/incomingMessages.ts b/apps/meteor/client/startup/incomingMessages.ts index 4efd3dba0fbf7..eafdb5e1838d3 100644 --- a/apps/meteor/client/startup/incomingMessages.ts +++ b/apps/meteor/client/startup/incomingMessages.ts @@ -3,6 +3,7 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { sdk } from '../../app/utils/client/lib/SDKClient'; import { onLoggedIn } from '../lib/loggedIn'; import { getUserId } from '../lib/user'; +import { upsertThreadMessageInCache } from '../lib/utils/threadMessageUtils'; import { Messages } from '../stores'; onLoggedIn(() => { @@ -12,6 +13,10 @@ onLoggedIn(() => { msg.u = msg.u || { username: 'rocket.cat' }; msg.private = true; + if (msg.tmid) { + upsertThreadMessageInCache(msg, msg.rid, msg.tmid); + } + return Messages.state.store(msg); }).stop; }); diff --git a/apps/meteor/tests/e2e/message-mentions.spec.ts b/apps/meteor/tests/e2e/message-mentions.spec.ts index d03c62edd4f5b..17ea83daa44a8 100644 --- a/apps/meteor/tests/e2e/message-mentions.spec.ts +++ b/apps/meteor/tests/e2e/message-mentions.spec.ts @@ -137,17 +137,17 @@ test.describe.serial('message-mentions', () => { }); await test.step('show "Do nothing" action', async () => { - await expect(adminPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible(); + await expect(adminPage.content.getLastMessageActionButton('Do nothing')).toBeVisible(); }); await test.step('show "Add them" action', async () => { - await expect(adminPage.content.lastUserMessage.locator('button >> text="Add them"')).toBeVisible(); + await expect(adminPage.content.getLastMessageActionButton('Add them')).toBeVisible(); }); await test.step('show "Let them know" action', async () => { - await expect(adminPage.content.lastUserMessage.locator('button >> text="Let them know"')).toBeVisible(); + await expect(adminPage.content.getLastMessageActionButton('Let them know')).toBeVisible(); }); await test.step('dismiss', async () => { - await adminPage.content.lastUserMessage.locator('button >> text="Do nothing"').click(); + await adminPage.content.getLastMessageActionButton('Do nothing').click(); }); await test.step('receive second bot message', async () => { @@ -155,7 +155,7 @@ test.describe.serial('message-mentions', () => { await expect(adminPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText); }); await test.step('send message to users', async () => { - await adminPage.content.lastUserMessage.locator('button >> text="Let them know"').click(); + await adminPage.content.getLastMessageActionButton('Let them know').click(); await expect(adminPage.content.lastUserMessageBody).toContainText(getMentionText(Users.user1.data.username, 3)); }); @@ -164,11 +164,34 @@ test.describe.serial('message-mentions', () => { await expect(adminPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText); }); await test.step('add users to room', async () => { - await adminPage.content.lastUserMessage.locator('button >> text="Add them"').click(); + await adminPage.content.getLastMessageActionButton('Add them').click(); await expect(adminPage.content.lastSystemMessageBody).toContainText('added'); }); }); + test('should show non-member mention warning inside threads', async ({ page }) => { + const adminPage = new HomeChannel(page); + const mentionText = getMentionText(Users.user2.data.username, 1); + + await test.step('open thread', async () => { + await adminPage.navbar.openChat(targetChannel); + await adminPage.content.sendMessage('thread parent for non-member mention warning'); + await adminPage.content.openReplyInThread(); + await adminPage.content.waitForThread(); + }); + + await test.step('receive bot message inside thread', async () => { + await adminPage.content.sendMessageInThread(getMentionText(Users.user2.data.username)); + await expect(adminPage.content.lastUserThreadMessage).toContainText(mentionText); + }); + + await test.step('show actions inside thread', async () => { + await expect(adminPage.content.getLastThreadMessageActionButton('Do nothing')).toBeVisible(); + await expect(adminPage.content.getLastThreadMessageActionButton('Add them')).toBeVisible(); + await expect(adminPage.content.getLastThreadMessageActionButton('Let them know')).toBeVisible(); + }); + }); + test.describe(() => { test.use({ storageState: Users.user1.state }); @@ -183,17 +206,17 @@ test.describe.serial('message-mentions', () => { }); await test.step('show "Do nothing" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Do nothing')).toBeVisible(); }); await test.step('show "Let them know" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Let them know')).toBeVisible(); }); await test.step('not show "Add them action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).not.toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Add them')).not.toBeVisible(); }); await test.step('dismiss', async () => { - await userPage.content.lastUserMessage.locator('button >> text="Do nothing"').click(); + await userPage.content.getLastMessageActionButton('Do nothing').click(); }); await test.step('receive second bot message', async () => { @@ -202,7 +225,7 @@ test.describe.serial('message-mentions', () => { await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText); }); await test.step('send message to users', async () => { - await userPage.content.lastUserMessage.locator('button >> text="Let them know"').click(); + await userPage.content.getLastMessageActionButton('Let them know').click(); await expect(userPage.content.lastUserMessageBody).toContainText(getMentionText(Users.user2.data.username, 3)); }); }); @@ -237,17 +260,17 @@ test.describe.serial('message-mentions', () => { await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText); }); await test.step('show "Do nothing" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Do nothing')).toBeVisible(); }); await test.step('show "Add them" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Add them')).toBeVisible(); }); await test.step('not show "Let them know" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).not.toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Let them know')).not.toBeVisible(); }); await test.step('dismiss', async () => { - await userPage.content.lastUserMessage.locator('button >> text="Do nothing"').click(); + await userPage.content.getLastMessageActionButton('Do nothing').click(); }); await test.step('receive second bot message', async () => { @@ -256,7 +279,7 @@ test.describe.serial('message-mentions', () => { await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText); }); await test.step('add users to room', async () => { - await userPage.content.lastUserMessage.locator('button >> text="Add them"').click(); + await userPage.content.getLastMessageActionButton('Add them').click(); await expect(userPage.content.lastSystemMessageBody).toContainText('added'); }); }); @@ -285,13 +308,13 @@ test.describe.serial('message-mentions', () => { }); await test.step('not show "Do nothing" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).not.toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Do nothing')).not.toBeVisible(); }); await test.step('not show "Add them" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).not.toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Add them')).not.toBeVisible(); }); await test.step('not show "Let them know" action', async () => { - await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).not.toBeVisible(); + await expect(userPage.content.getLastMessageActionButton('Let them know')).not.toBeVisible(); }); }); }); 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 4feef449186aa..a17e56af0e652 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -544,6 +544,14 @@ export class HomeContent { return this.page.locator('[role="listitem"][aria-roledescription="message"]', { hasText: text }); } + getLastMessageActionButton(name: string): Locator { + return this.lastUserMessage.getByRole('button', { name, exact: true }); + } + + getLastThreadMessageActionButton(name: string): Locator { + return this.lastUserThreadMessage.getByRole('button', { name, exact: true }); + } + getMessageById(id: string): Locator { return this.page.locator(`[role="listitem"][aria-roledescription="message"][id="${id}"]`); }