From ad9ba61167e344cf3123b763d2a6c72c3b40d7dc Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 29 Nov 2023 13:35:45 +0700 Subject: [PATCH 1/5] fix: room name in invite message does not show link --- src/libs/ReportUtils.ts | 9 +++++-- .../report/ContextMenu/ContextMenuActions.js | 24 ++++++++++++------- src/types/onyx/OriginalMessage.ts | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d93661778b83..8ea82d91e0bf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -23,6 +23,7 @@ import DeepValueOf from '@src/types/utils/DeepValueOf'; import {EmptyObject, isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; +import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; @@ -346,6 +347,9 @@ type OnyxDataTaskAssigneeChat = { optimisticChatCreatedReportAction?: OptimisticCreatedReportAction; }; +let environmentURL: string; +Environment.getEnvironmentURL().then((url: string) => (environmentURL = url)); + let currentUserEmail: string | undefined; let currentUserAccountID: number | undefined; let isAnonymousUser = false; @@ -4164,13 +4168,14 @@ function getChannelLogMemberMessage(reportAction: OnyxEntry): stri message = `${verb} ${mentions?.join(', ')}, and ${lastMention}`; } + const reportID = (reportAction?.originalMessage as ChangeLog)?.reportID ?? 0; const roomName = (reportAction?.originalMessage as ChangeLog)?.roomName ?? ''; - if (roomName) { + if (reportID && roomName) { const preposition = reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ? ' to' : ' from'; - message += `${preposition} ${roomName}`; + message += `${preposition} ${roomName}`; } return message; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 4f35926c5957..973971c60f72 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -23,6 +23,20 @@ import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import {clearActiveReportAction, hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; +/** + * Sets the HTML string to Clipboard. + * @param {String} content + */ +function setClipboardHtmlMessage(content) { + const parser = new ExpensiMark(); + if (!Clipboard.canSetHtml()) { + Clipboard.setString(parser.htmlToMarkdown(content)); + } else { + const plainText = parser.htmlToText(content); + Clipboard.setHtml(content, plainText); + } +} + /** * Gets the HTML version of the message in an action. * @param {Object} reportAction @@ -283,15 +297,9 @@ export default [ Clipboard.setString(displayMessage); } else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) { const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction); - Clipboard.setString(logMessage); + setClipboardHtmlMessage(logMessage); } else if (content) { - const parser = new ExpensiMark(); - if (!Clipboard.canSetHtml()) { - Clipboard.setString(parser.htmlToMarkdown(content)); - } else { - const plainText = parser.htmlToText(content); - Clipboard.setHtml(content, plainText); - } + setClipboardHtmlMessage(content); } } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 0dc532ebeded..b00dee0df96a 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -140,6 +140,7 @@ type ChronosOOOTimestamp = { type ChangeLog = { targetAccountIDs?: number[]; roomName?: string; + reportID?: number; }; type ChronosOOOEvent = { From ebcd66fd9fe5ccb98c384281342e2e162bf29b20 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 29 Nov 2023 13:50:25 +0700 Subject: [PATCH 2/5] remove redundat escape charaters --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8ea82d91e0bf..728cf44d7d9f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4175,7 +4175,7 @@ function getChannelLogMemberMessage(reportAction: OnyxEntry): stri reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ? ' to' : ' from'; - message += `${preposition} ${roomName}`; + message += `${preposition} ${roomName}`; } return message; From fd0a9a9eb6325ba8e0643b3d250217831244d336 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 29 Nov 2023 13:57:06 +0700 Subject: [PATCH 3/5] fix: mention in copied invite message shown as hidden --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 728cf44d7d9f..49af0c71c8fb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4151,8 +4151,8 @@ function getChannelLogMemberMessage(reportAction: OnyxEntry): stri ? 'invited' : 'removed'; - const mentions = (reportAction?.originalMessage as ChangeLog)?.targetAccountIDs?.map(() => { - const personalDetail = allPersonalDetails?.accountID; + const mentions = (reportAction?.originalMessage as ChangeLog)?.targetAccountIDs?.map((accountID) => { + const personalDetail = allPersonalDetails?.[accountID]; const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') || (personalDetail?.displayName ?? '') || Localize.translateLocal('common.hidden'); return `@${displayNameOrLogin}`; }); From 72da1620987b0a30fbed8a13c30e0dc7a0d13df3 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 20 Dec 2023 16:01:58 +0700 Subject: [PATCH 4/5] copy mention --- src/libs/ReportActionsUtils.ts | 2 +- src/libs/ReportUtils.ts | 3 --- .../report/ContextMenu/ContextMenuActions.js | 26 ++++++++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 9a3099ba6c02..4847eee2c8c6 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -735,7 +735,7 @@ function getMemberChangeMessageFragment(reportAction: OnyxEntry): .map((messageElement) => { switch (messageElement.kind) { case 'userMention': - return ``; + return `${messageElement.content}`; case 'roomReference': return `${messageElement.roomName}`; default: diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 86a746b02386..ae7095bdf826 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -348,9 +348,6 @@ type OnyxDataTaskAssigneeChat = { optimisticChatCreatedReportAction?: OptimisticCreatedReportAction; }; -let environmentURL: string; -Environment.getEnvironmentURL().then((url: string) => (environmentURL = url)); - let currentUserEmail: string | undefined; let currentUserAccountID: number | undefined; let isAnonymousUser = false; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index a5e946e6a78a..3682ef602a2b 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -35,6 +35,20 @@ function getActionText(reportAction) { return lodashGet(message, 'html', ''); } +/** + * Sets the HTML string to Clipboard. + * @param {String} content + */ +function setClipboardMessage(content) { + const parser = new ExpensiMark(); + if (!Clipboard.canSetHtml()) { + Clipboard.setString(parser.htmlToMarkdown(content)); + } else { + const plainText = parser.htmlToText(content); + Clipboard.setHtml(content, plainText); + } +} + const CONTEXT_MENU_TYPES = { LINK: 'LINK', REPORT_ACTION: 'REPORT_ACTION', @@ -291,19 +305,13 @@ export default [ const taskPreviewMessage = TaskUtils.getTaskCreatedMessage(reportAction); Clipboard.setString(taskPreviewMessage); } else if (ReportActionsUtils.isMemberChangeAction(reportAction)) { - const logMessage = ReportActionsUtils.getMemberChangeMessagePlainText(reportAction); - Clipboard.setString(logMessage); + const logMessage = ReportActionsUtils.getMemberChangeMessageFragment(reportAction).html; + setClipboardMessage(logMessage); } else if (ReportActionsUtils.isSubmittedExpenseAction(reportAction)) { const submittedMessage = _.reduce(reportAction.message, (acc, curr) => `${acc}${curr.text}`, ''); Clipboard.setString(submittedMessage); } else if (content) { - const parser = new ExpensiMark(); - if (!Clipboard.canSetHtml()) { - Clipboard.setString(parser.htmlToMarkdown(content)); - } else { - const plainText = parser.htmlToText(content); - Clipboard.setHtml(content, plainText); - } + setClipboardMessage(content); } } From 51f9bb02e8654fe59f18c04587ca85b8c5bcda01 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 20 Dec 2023 16:02:38 +0700 Subject: [PATCH 5/5] remove redundant imports --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ae7095bdf826..8ac32675bb4e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -25,7 +25,6 @@ import DeepValueOf from '@src/types/utils/DeepValueOf'; import {EmptyObject, isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; -import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize';