From 3fd3d5ab7b49849328505e895a1652614bbf612f Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 25 Jun 2024 10:44:37 +0700 Subject: [PATCH 1/4] Fix regression when html doesn't exist --- src/libs/ReportActionsUtils.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 16032d41b949e..330f03040759a 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1,4 +1,4 @@ -import {ExpensiMark, fastMerge} from 'expensify-common'; +import {fastMerge} from 'expensify-common'; import _ from 'lodash'; import lodashFindLast from 'lodash/findLast'; import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; @@ -21,6 +21,7 @@ import isReportMessageAttachment from './isReportMessageAttachment'; import * as Localize from './Localize'; import Log from './Log'; import type {MessageElementBase, MessageTextElement} from './MessageElement'; +import {parseHtmlToText} from './OnyxAwareParser'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import type {OptimisticIOUReportAction, PartialReportAction} from './ReportUtils'; import StringUtils from './StringUtils'; @@ -1127,14 +1128,14 @@ function getReportActionHtml(reportAction: PartialReportAction): string { } function getReportActionText(reportAction: PartialReportAction): string { - const html = getReportActionHtml(reportAction); - const parser = new ExpensiMark(); - return html ? parser.htmlToText(html) : ''; + const message = getReportActionMessage(reportAction); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const text = (message?.html || message?.text) ?? ''; + return text ? parseHtmlToText(text) : ''; } function getTextFromHtml(html?: string): string { - const parser = new ExpensiMark(); - return html ? parser.htmlToText(html) : ''; + return html ? parseHtmlToText(html) : ''; } function getMemberChangeMessageFragment(reportAction: OnyxEntry): Message { @@ -1200,7 +1201,7 @@ function getMessageOfOldDotReportAction(reportAction: OnyxEntry): if (!Array.isArray(reportAction?.message)) { return getReportActionText(reportAction); } - return reportAction?.message?.map((element) => getTextFromHtml(element?.html)).join('') ?? ''; + return reportAction?.message?.map((element) => getTextFromHtml(element?.html ?? element?.text)).join('') ?? ''; } function getMemberChangeMessagePlainText(reportAction: OnyxEntry): string { @@ -1326,7 +1327,7 @@ function getReportActionMessageText(reportAction: OnyxEntry | Empt if (!Array.isArray(reportAction?.message)) { return getReportActionText(reportAction); } - return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html)}`, '') ?? ''; + return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html ?? curr?.text)}`, '') ?? ''; } function getDismissedViolationMessageText(originalMessage: ReportAction['originalMessage']): string { From e3c25908e32df72234d17c446cbec7b7859073ff Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 25 Jun 2024 11:08:06 +0700 Subject: [PATCH 2/4] fix whisperedTo issue --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 330f03040759a..f03993bb5fdd3 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -190,7 +190,7 @@ function getWhisperedTo(reportAction: OnyxInputOrEntry): number[] return []; } const originalMessage = getOriginalMessage(reportAction); - const message = reportAction?.message; + const message = getReportActionMessage(reportAction); if (!(originalMessage && 'whisperedTo' in originalMessage) && !(message && 'whisperedTo' in message)) { return []; From 098a6d090443668747f6165c9d91dd2ae5cea2e8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 25 Jun 2024 11:20:15 +0700 Subject: [PATCH 3/4] use || --- src/libs/ReportActionsUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index f03993bb5fdd3..17de8be88b250 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1129,6 +1129,7 @@ function getReportActionHtml(reportAction: PartialReportAction): string { function getReportActionText(reportAction: PartialReportAction): string { const message = getReportActionMessage(reportAction); + // Sometime html can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const text = (message?.html || message?.text) ?? ''; return text ? parseHtmlToText(text) : ''; @@ -1201,7 +1202,9 @@ function getMessageOfOldDotReportAction(reportAction: OnyxEntry): if (!Array.isArray(reportAction?.message)) { return getReportActionText(reportAction); } - return reportAction?.message?.map((element) => getTextFromHtml(element?.html ?? element?.text)).join('') ?? ''; + // Sometime html can be an empty string + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + return reportAction?.message?.map((element) => getTextFromHtml(element?.html || element?.text)).join('') ?? ''; } function getMemberChangeMessagePlainText(reportAction: OnyxEntry): string { @@ -1327,6 +1330,8 @@ function getReportActionMessageText(reportAction: OnyxEntry | Empt if (!Array.isArray(reportAction?.message)) { return getReportActionText(reportAction); } + // Sometime html can be an empty string + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html ?? curr?.text)}`, '') ?? ''; } From 21b6cf3c417491acffbccc0e260d464bf07176eb Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 25 Jun 2024 16:43:47 +0700 Subject: [PATCH 4/4] update to use || --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 17de8be88b250..f21dd187f4660 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1332,7 +1332,7 @@ function getReportActionMessageText(reportAction: OnyxEntry | Empt } // Sometime html can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html ?? curr?.text)}`, '') ?? ''; + return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html || curr?.text)}`, '') ?? ''; } function getDismissedViolationMessageText(originalMessage: ReportAction['originalMessage']): string {