Skip to content

Commit 651a5dd

Browse files
authored
Merge pull request #44365 from nkdengineer/fix/39797
[CP Staging] Fix regression when html doesn't exist
2 parents cb40377 + 21b6cf3 commit 651a5dd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/libs/ReportActionsUtils.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ExpensiMark, fastMerge} from 'expensify-common';
1+
import {fastMerge} from 'expensify-common';
22
import _ from 'lodash';
33
import lodashFindLast from 'lodash/findLast';
44
import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
@@ -21,6 +21,7 @@ import isReportMessageAttachment from './isReportMessageAttachment';
2121
import * as Localize from './Localize';
2222
import Log from './Log';
2323
import type {MessageElementBase, MessageTextElement} from './MessageElement';
24+
import {parseHtmlToText} from './OnyxAwareParser';
2425
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
2526
import type {OptimisticIOUReportAction, PartialReportAction} from './ReportUtils';
2627
import StringUtils from './StringUtils';
@@ -189,7 +190,7 @@ function getWhisperedTo(reportAction: OnyxInputOrEntry<ReportAction>): number[]
189190
return [];
190191
}
191192
const originalMessage = getOriginalMessage(reportAction);
192-
const message = reportAction?.message;
193+
const message = getReportActionMessage(reportAction);
193194

194195
if (!(originalMessage && 'whisperedTo' in originalMessage) && !(message && 'whisperedTo' in message)) {
195196
return [];
@@ -1127,14 +1128,15 @@ function getReportActionHtml(reportAction: PartialReportAction): string {
11271128
}
11281129

11291130
function getReportActionText(reportAction: PartialReportAction): string {
1130-
const html = getReportActionHtml(reportAction);
1131-
const parser = new ExpensiMark();
1132-
return html ? parser.htmlToText(html) : '';
1131+
const message = getReportActionMessage(reportAction);
1132+
// Sometime html can be an empty string
1133+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1134+
const text = (message?.html || message?.text) ?? '';
1135+
return text ? parseHtmlToText(text) : '';
11331136
}
11341137

11351138
function getTextFromHtml(html?: string): string {
1136-
const parser = new ExpensiMark();
1137-
return html ? parser.htmlToText(html) : '';
1139+
return html ? parseHtmlToText(html) : '';
11381140
}
11391141

11401142
function getMemberChangeMessageFragment(reportAction: OnyxEntry<ReportAction>): Message {
@@ -1200,7 +1202,9 @@ function getMessageOfOldDotReportAction(reportAction: OnyxEntry<ReportAction>):
12001202
if (!Array.isArray(reportAction?.message)) {
12011203
return getReportActionText(reportAction);
12021204
}
1203-
return reportAction?.message?.map((element) => getTextFromHtml(element?.html)).join('') ?? '';
1205+
// Sometime html can be an empty string
1206+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1207+
return reportAction?.message?.map((element) => getTextFromHtml(element?.html || element?.text)).join('') ?? '';
12041208
}
12051209

12061210
function getMemberChangeMessagePlainText(reportAction: OnyxEntry<ReportAction>): string {
@@ -1326,7 +1330,9 @@ function getReportActionMessageText(reportAction: OnyxEntry<ReportAction> | Empt
13261330
if (!Array.isArray(reportAction?.message)) {
13271331
return getReportActionText(reportAction);
13281332
}
1329-
return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html)}`, '') ?? '';
1333+
// Sometime html can be an empty string
1334+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1335+
return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html || curr?.text)}`, '') ?? '';
13301336
}
13311337

13321338
function getDismissedViolationMessageText(originalMessage: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION>['originalMessage']): string {

0 commit comments

Comments
 (0)