Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Fix regression when html doesn't exist #44365

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -189,7 +190,7 @@ function getWhisperedTo(reportAction: OnyxInputOrEntry<ReportAction>): number[]
return [];
}
const originalMessage = getOriginalMessage(reportAction);
const message = reportAction?.message;
const message = getReportActionMessage(reportAction);

if (!(originalMessage && 'whisperedTo' in originalMessage) && !(message && 'whisperedTo' in message)) {
return [];
Expand Down Expand Up @@ -1127,14 +1128,15 @@ 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);
// 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) : '';
}

function getTextFromHtml(html?: string): string {
const parser = new ExpensiMark();
return html ? parser.htmlToText(html) : '';
return html ? parseHtmlToText(html) : '';
}

function getMemberChangeMessageFragment(reportAction: OnyxEntry<ReportAction>): Message {
Expand Down Expand Up @@ -1200,7 +1202,9 @@ function getMessageOfOldDotReportAction(reportAction: OnyxEntry<ReportAction>):
if (!Array.isArray(reportAction?.message)) {
return getReportActionText(reportAction);
}
return reportAction?.message?.map((element) => getTextFromHtml(element?.html)).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<ReportAction>): string {
Expand Down Expand Up @@ -1326,7 +1330,9 @@ function getReportActionMessageText(reportAction: OnyxEntry<ReportAction> | Empt
if (!Array.isArray(reportAction?.message)) {
return getReportActionText(reportAction);
}
return reportAction?.message?.reduce((acc, curr) => `${acc}${getTextFromHtml(curr?.html)}`, '') ?? '';
// 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)}`, '') ?? '';
}
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

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