From bef0b2dc003b4914d27c2bddba31c5ed20fc677b Mon Sep 17 00:00:00 2001 From: Hugo Costa Date: Fri, 1 Jul 2022 20:06:34 -0300 Subject: [PATCH] Chore: Adding default message parser template (#26064) Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com> --- .../meteor/app/lib/server/startup/settings.ts | 6 ++--- apps/meteor/app/markdown/server/settings.ts | 1 + .../app/ui-utils/client/lib/messageContext.js | 4 ++-- apps/meteor/app/ui/client/views/app/room.html | 8 +++---- .../Attachment/AttachmentDescription.tsx | 2 +- .../Attachment/AttachmentTitleLink.tsx | 10 ++++++++- .../preferences/PreferencesGlobalSection.js | 14 ++++++------ .../MessageList/components/MessageHeader.tsx | 2 ++ .../MessageList/components/MessageSystem.tsx | 8 ++++++- apps/meteor/package.json | 2 +- .../rocketchat-i18n/i18n/en.i18n.json | 6 ++--- .../meteor/server/startup/migrations/index.ts | 1 + apps/meteor/server/startup/migrations/v276.ts | 18 +++++++++++++++ apps/meteor/tests/e2e/06-messaging.spec.ts | 16 +++++++------- apps/meteor/tests/e2e/07-emoji.spec.ts | 4 ++-- apps/meteor/tests/e2e/13-permissions.spec.ts | 2 +- .../tests/e2e/pageobjects/MainContent.ts | 22 +++++++++---------- .../tests/end-to-end/api/00-miscellaneous.js | 2 +- 18 files changed, 82 insertions(+), 46 deletions(-) create mode 100644 apps/meteor/server/startup/migrations/v276.ts diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index 1f60c71c1992..9500c7138b08 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -548,11 +548,11 @@ settingsRegistry.addGroup('Accounts', function () { i18nLabel: 'Notifications_Sound_Volume', }); - this.add('Accounts_Default_User_Preferences_enableNewMessageTemplate', false, { + this.add('Accounts_Default_User_Preferences_useLegacyMessageTemplate', false, { type: 'boolean', public: true, - i18nLabel: 'Enable_New_Message_Template', - alert: 'Enable_New_Message_Template_alert', + i18nLabel: 'Use_Legacy_Message_Template', + alert: 'Use_Legacy_Message_Template_alert', }); }); diff --git a/apps/meteor/app/markdown/server/settings.ts b/apps/meteor/app/markdown/server/settings.ts index e25ed0a1872d..b2f231059097 100644 --- a/apps/meteor/app/markdown/server/settings.ts +++ b/apps/meteor/app/markdown/server/settings.ts @@ -19,6 +19,7 @@ settingsRegistry.add('Markdown_Parser', 'original', { group: 'Message', section: 'Markdown', public: true, + alert: 'Use_Legacy_Message_Template_alert', }); const enableQueryOriginal = { _id: 'Markdown_Parser', value: 'original' }; diff --git a/apps/meteor/app/ui-utils/client/lib/messageContext.js b/apps/meteor/app/ui-utils/client/lib/messageContext.js index afce9a16d217..b8367a85d7f2 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageContext.js +++ b/apps/meteor/app/ui-utils/client/lib/messageContext.js @@ -17,7 +17,7 @@ import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; const fields = { 'name': 1, 'username': 1, - 'settings.preferences.enableNewMessageTemplate': 1, + 'settings.preferences.useLegacyMessageTemplate': 1, 'settings.preferences.autoImageLoad': 1, 'settings.preferences.saveMobileBandwidth': 1, 'settings.preferences.collapseMediaByDefault': 1, @@ -115,7 +115,7 @@ export function messageContext({ rid } = Template.instance()) { settings: { translateLanguage: AutoTranslate.getLanguage(rid), autoImageLoad: getUserPreference(user, 'autoImageLoad'), - enableNewMessageTemplate: getUserPreference(user, 'enableNewMessageTemplate'), + useLegacyMessageTemplate: getUserPreference(user, 'useLegacyMessageTemplate'), saveMobileBandwidth: Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth'), collapseMediaByDefault: getUserPreference(user, 'collapseMediaByDefault'), showreply: true, diff --git a/apps/meteor/app/ui/client/views/app/room.html b/apps/meteor/app/ui/client/views/app/room.html index ee5c2c3a951d..0463f491648f 100644 --- a/apps/meteor/app/ui/client/views/app/room.html +++ b/apps/meteor/app/ui/client/views/app/room.html @@ -110,14 +110,14 @@ {{/if}} {{/if}} - {{# if $eq (preference 'enableNewMessageTemplate') true}} + {{# unless $eq (preference 'useLegacyMessageTemplate') true}} {{> MessageList rid=rid }} - {{/if}} - {{# unless $eq (preference 'enableNewMessageTemplate') true}} + {{/unless}} + {{# if $eq (preference 'useLegacyMessageTemplate') true}} {{# with messageContext}} {{#each msg in messagesHistory}}{{> message showRoles=true index=@index shouldCollapseReplies=false msg=msg room=room actions=actions subscription=subscription settings=settings u=u}}{{/each}} {{/with}} - {{/unless}} + {{/if}} {{#if hasMoreNext}}
  • diff --git a/apps/meteor/client/components/message/Attachments/Attachment/AttachmentDescription.tsx b/apps/meteor/client/components/message/Attachments/Attachment/AttachmentDescription.tsx index 252ff98bf367..e99c5cdfdc26 100644 --- a/apps/meteor/client/components/message/Attachments/Attachment/AttachmentDescription.tsx +++ b/apps/meteor/client/components/message/Attachments/Attachment/AttachmentDescription.tsx @@ -2,7 +2,7 @@ import { Box } from '@rocket.chat/fuselage'; import React, { ComponentProps, ReactElement } from 'react'; const AttachmentDescription = ({ ...props }: ComponentProps): ReactElement => ( - + ); export default AttachmentDescription; diff --git a/apps/meteor/client/components/message/Attachments/Attachment/AttachmentTitleLink.tsx b/apps/meteor/client/components/message/Attachments/Attachment/AttachmentTitleLink.tsx index 0e4b9bee7558..d4d35b24bef6 100644 --- a/apps/meteor/client/components/message/Attachments/Attachment/AttachmentTitleLink.tsx +++ b/apps/meteor/client/components/message/Attachments/Attachment/AttachmentTitleLink.tsx @@ -3,7 +3,15 @@ import React, { FC } from 'react'; import Title from './AttachmentTitle'; const AttachmentTitleLink: FC<{ link: string; title?: string | undefined }> = ({ link, title }) => ( - + <Title + is='a' + href={`${link}?download`} + color={undefined} + target='_blank' + download={title} + rel='noopener noreferrer' + data-qa-type='attachment-title-link' + > {title} ); diff --git a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.js b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.js index b1715e072914..e04c1f63d352 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.js +++ b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.js @@ -8,7 +8,7 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }) => { const t = useTranslation(); const userDontAskAgainList = useUserPreference('dontAskAgainList'); - const userEnableNewMessageTemplate = useUserPreference('enableNewMessageTemplate'); + const userLegacyMessageTemplate = useUserPreference('useLegacyMessageTemplate'); const options = useMemo(() => (userDontAskAgainList || []).map(({ action, label }) => [action, label]), [userDontAskAgainList]); @@ -17,14 +17,14 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }) => { const { values, handlers, commit } = useForm( { dontAskAgainList: selectedOptions, - enableNewMessageTemplate: userEnableNewMessageTemplate, + useLegacyMessageTemplate: userLegacyMessageTemplate, }, onChange, ); - const { dontAskAgainList, enableNewMessageTemplate } = values; + const { dontAskAgainList, useLegacyMessageTemplate } = values; - const { handleDontAskAgainList, handleEnableNewMessageTemplate } = handlers; + const { handleDontAskAgainList, handleUseLegacyMessageTemplate } = handlers; commitRef.current.global = commit; @@ -43,12 +43,12 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }) => { - {t('Enable_New_Message_Template')} + {t('Use_Legacy_Message_Template')} - + - {t('Enable_New_Message_Template_alert')} + {t('Use_Legacy_Message_Template_alert')} ); diff --git a/apps/meteor/client/views/room/MessageList/components/MessageHeader.tsx b/apps/meteor/client/views/room/MessageList/components/MessageHeader.tsx index 76df593012db..d131c611ccc2 100644 --- a/apps/meteor/client/views/room/MessageList/components/MessageHeader.tsx +++ b/apps/meteor/client/views/room/MessageList/components/MessageHeader.tsx @@ -37,6 +37,7 @@ const MessageHeader: FC<{ message: IMessage }> = ({ message }) => { return ( = ({ message }) => { {showUsername && ( diff --git a/apps/meteor/client/views/room/MessageList/components/MessageSystem.tsx b/apps/meteor/client/views/room/MessageList/components/MessageSystem.tsx index 651ca7715bad..dcc4702d2e8f 100644 --- a/apps/meteor/client/views/room/MessageList/components/MessageSystem.tsx +++ b/apps/meteor/client/views/room/MessageList/components/MessageSystem.tsx @@ -44,7 +44,12 @@ export const MessageSystem: FC<{ message: IMessage }> = ({ message }) => { useCountSelected(); return ( - + {!isSelecting && } {isSelecting && } @@ -65,6 +70,7 @@ export const MessageSystem: FC<{ message: IMessage }> = ({ message }) => { )} {messageType && ( { await anotherContext.mainContent.page.close(); }); test('expect received message is visible for two context', async () => { - const anotherUserMessage = mainContent.page.locator('li.message[data-own="false"]').last(); - const mainUserMessage = anotherContext.mainContent.page.locator('li.message[data-own="false"]').last(); + const anotherUserMessage = mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); + const mainUserMessage = anotherContext.mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); await expect(anotherUserMessage).toBeVisible(); await expect(mainUserMessage).toBeVisible(); @@ -76,8 +76,8 @@ test.describe('[Messaging]', () => { await anotherContext.mainContent.page.close(); }); test('expect received message is visible for two context', async () => { - const anotherUserMessage = mainContent.page.locator('li.message[data-own="false"]').last(); - const mainUserMessage = anotherContext.mainContent.page.locator('li.message[data-own="false"]').last(); + const anotherUserMessage = mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); + const mainUserMessage = anotherContext.mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); await expect(anotherUserMessage).toBeVisible(); await expect(mainUserMessage).toBeVisible(); @@ -96,8 +96,8 @@ test.describe('[Messaging]', () => { await anotherContext.mainContent.page.close(); }); test('expect received message is visible for two context', async () => { - const anotherUserMessage = mainContent.page.locator('li.message[data-own="false"]').last(); - const mainUserMessage = anotherContext.mainContent.page.locator('li.message[data-own="false"]').last(); + const anotherUserMessage = mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); + const mainUserMessage = anotherContext.mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); await expect(anotherUserMessage).toBeVisible(); await expect(mainUserMessage).toBeVisible(); @@ -116,8 +116,8 @@ test.describe('[Messaging]', () => { await anotherContext.mainContent.page.close(); }); test('expect received message is visible for two context', async () => { - const anotherUserMessage = mainContent.page.locator('li.message[data-own="false"]').last(); - const mainUserMessage = anotherContext.mainContent.page.locator('li.message[data-own="false"]').last(); + const anotherUserMessage = mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); + const mainUserMessage = anotherContext.mainContent.page.locator('[data-qa-type="message"][data-own="false"]').last(); await expect(anotherUserMessage).toBeVisible(); await expect(mainUserMessage).toBeVisible(); diff --git a/apps/meteor/tests/e2e/07-emoji.spec.ts b/apps/meteor/tests/e2e/07-emoji.spec.ts index 26e8eb5947e9..649c4bf72aad 100644 --- a/apps/meteor/tests/e2e/07-emoji.spec.ts +++ b/apps/meteor/tests/e2e/07-emoji.spec.ts @@ -147,8 +147,8 @@ test.describe('[Emoji]', () => { await mainContent.waitForLastMessageEqualsHtml('0 1 2 3 4 5 6 7 8 9'); }); test('should render special characters', async () => { - await mainContent.sendMessage('# * ® © ™'); - await mainContent.waitForLastMessageEqualsHtml('# * ® © ™'); + await mainContent.sendMessage('® © ™ # *'); + await mainContent.waitForLastMessageEqualsHtml('® © ™ # *'); }); }); }); diff --git a/apps/meteor/tests/e2e/13-permissions.spec.ts b/apps/meteor/tests/e2e/13-permissions.spec.ts index efdced3073b5..96d9ad1ac339 100644 --- a/apps/meteor/tests/e2e/13-permissions.spec.ts +++ b/apps/meteor/tests/e2e/13-permissions.spec.ts @@ -84,7 +84,7 @@ test.describe('[Permissions]', () => { test('expect not be abble to "mention all"', async () => { await mainContent.sendMessage('@all any_message'); - await expect(mainContent.lastMessage).toContainText('not allowed'); + await expect(mainContent.lastMessageForMessageTest).toContainText('not allowed'); }); test('expect not be able to "delete own message"', async () => { diff --git a/apps/meteor/tests/e2e/pageobjects/MainContent.ts b/apps/meteor/tests/e2e/pageobjects/MainContent.ts index e49b35791282..fde9f8e5f9c8 100644 --- a/apps/meteor/tests/e2e/pageobjects/MainContent.ts +++ b/apps/meteor/tests/e2e/pageobjects/MainContent.ts @@ -58,15 +58,15 @@ export class MainContent extends BasePage { } get lastUserMessage(): Locator { - return this.page.locator('[data-qa-id=UserMessage]').last(); + return this.page.locator('[data-qa-type="message"][data-sequential="false"]').last().locator('[data-qa-type="username"]'); } get btnLastUserMessage(): Locator { - return this.page.locator('[data-qa-id=UserMessage]:not(.sequential) > button').last(); + return this.page.locator('[data-qa-type="message"][data-sequential="false"]').last().locator('[data-qa-type="username"]'); } get lastMessageFileName(): Locator { - return this.page.locator('[data-qa-type="message"]:last-child div:nth-child(3) div:nth-child(2) div a:nth-child(1)'); + return this.page.locator('[data-qa-type="message"]:last-child [data-qa-type="attachment-title-link"]'); } get lastMessage(): Locator { @@ -74,7 +74,7 @@ export class MainContent extends BasePage { } get lastMessageRoleAdded(): Locator { - return this.page.locator('.message:last-child.subscription-role-added .body'); + return this.page.locator('[data-qa="system-message"] [data-qa-type="system-message-body"]'); } get lastMessageUserTag(): Locator { @@ -82,7 +82,7 @@ export class MainContent extends BasePage { } get lastMessageForMessageTest(): Locator { - return this.page.locator('[data-qa-type="message"]:last-child div.message-body-wrapper div:nth-child(2)'); + return this.page.locator('[data-qa-type="message"]:last-child [data-qa-type="message-body"]'); } get messageOptionsBtns(): Locator { @@ -208,11 +208,11 @@ export class MainContent extends BasePage { } async waitForLastMessageEqualsHtml(text: string): Promise { - await expect(this.page.locator('(//*[contains(@class, "message") and contains(@class, "body")])[last()]')).toContainText(text); + await expect(this.lastMessageForMessageTest).toContainText(text); } async waitForLastMessageEqualsText(text: string): Promise { - await expect(this.page.locator('(//*[contains(@class, "message") and contains(@class, "body")])[last()]')).toContainText(text); + await expect(this.lastMessage).toContainText(text); } async sendMessage(text: string): Promise { @@ -270,7 +270,7 @@ export class MainContent extends BasePage { } get getFileDescription(): Locator { - return this.page.locator('[data-qa-type="message"]:last-child div:nth-child(3) div:nth-child(2) div p'); + return this.page.locator('[data-qa-type="message"]:last-child [data-qa-type="attachment-description"]'); } async selectAction(action: string): Promise { @@ -316,9 +316,9 @@ export class MainContent extends BasePage { } async openMessageActionMenu(): Promise { - await this.page.locator('.messages-box [data-qa-type="message"]:last-child').hover(); - await this.page.locator('[data-qa-type="message"]:last-child div.message-actions__menu').waitFor(); - await this.page.locator('[data-qa-type="message"]:last-child div.message-actions__menu').click(); + await this.page.locator('[data-qa-type="message"]:last-child').hover(); + await this.page.locator('[data-qa-type="message"]:last-child [data-qa-type="message-action-menu"][data-qa-id="menu"]').waitFor(); + await this.page.locator('[data-qa-type="message"]:last-child [data-qa-type="message-action-menu"][data-qa-id="menu"]').click(); } async openMoreActionMenu(): Promise { diff --git a/apps/meteor/tests/end-to-end/api/00-miscellaneous.js b/apps/meteor/tests/end-to-end/api/00-miscellaneous.js index 08c30981e7cc..3f9d6d0d50b9 100644 --- a/apps/meteor/tests/end-to-end/api/00-miscellaneous.js +++ b/apps/meteor/tests/end-to-end/api/00-miscellaneous.js @@ -153,7 +153,7 @@ describe('miscellaneous', function () { 'desktopNotifications', 'pushNotifications', 'enableAutoAway', - 'enableNewMessageTemplate', + 'useLegacyMessageTemplate', // 'highlights', 'desktopNotificationRequireInteraction', 'messageViewMode',