1
- import { ExpensiMark , fastMerge } from 'expensify-common' ;
1
+ import { fastMerge } from 'expensify-common' ;
2
2
import _ from 'lodash' ;
3
3
import lodashFindLast from 'lodash/findLast' ;
4
4
import type { OnyxCollection , OnyxCollectionInputValue , OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
@@ -21,6 +21,7 @@ import isReportMessageAttachment from './isReportMessageAttachment';
21
21
import * as Localize from './Localize' ;
22
22
import Log from './Log' ;
23
23
import type { MessageElementBase , MessageTextElement } from './MessageElement' ;
24
+ import { parseHtmlToText } from './OnyxAwareParser' ;
24
25
import * as PersonalDetailsUtils from './PersonalDetailsUtils' ;
25
26
import type { OptimisticIOUReportAction , PartialReportAction } from './ReportUtils' ;
26
27
import StringUtils from './StringUtils' ;
@@ -189,7 +190,7 @@ function getWhisperedTo(reportAction: OnyxInputOrEntry<ReportAction>): number[]
189
190
return [ ] ;
190
191
}
191
192
const originalMessage = getOriginalMessage ( reportAction ) ;
192
- const message = reportAction ?. message ;
193
+ const message = getReportActionMessage ( reportAction ) ;
193
194
194
195
if ( ! ( originalMessage && 'whisperedTo' in originalMessage ) && ! ( message && 'whisperedTo' in message ) ) {
195
196
return [ ] ;
@@ -1127,14 +1128,15 @@ function getReportActionHtml(reportAction: PartialReportAction): string {
1127
1128
}
1128
1129
1129
1130
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 ) : '' ;
1133
1136
}
1134
1137
1135
1138
function getTextFromHtml ( html ?: string ) : string {
1136
- const parser = new ExpensiMark ( ) ;
1137
- return html ? parser . htmlToText ( html ) : '' ;
1139
+ return html ? parseHtmlToText ( html ) : '' ;
1138
1140
}
1139
1141
1140
1142
function getMemberChangeMessageFragment ( reportAction : OnyxEntry < ReportAction > ) : Message {
@@ -1200,7 +1202,9 @@ function getMessageOfOldDotReportAction(reportAction: OnyxEntry<ReportAction>):
1200
1202
if ( ! Array . isArray ( reportAction ?. message ) ) {
1201
1203
return getReportActionText ( reportAction ) ;
1202
1204
}
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 ( '' ) ?? '' ;
1204
1208
}
1205
1209
1206
1210
function getMemberChangeMessagePlainText ( reportAction : OnyxEntry < ReportAction > ) : string {
@@ -1326,7 +1330,9 @@ function getReportActionMessageText(reportAction: OnyxEntry<ReportAction> | Empt
1326
1330
if ( ! Array . isArray ( reportAction ?. message ) ) {
1327
1331
return getReportActionText ( reportAction ) ;
1328
1332
}
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 ) } ` , '' ) ?? '' ;
1330
1336
}
1331
1337
1332
1338
function getDismissedViolationMessageText ( originalMessage : ReportAction < typeof CONST . REPORT . ACTIONS . TYPE . DISMISSED_VIOLATION > [ 'originalMessage' ] ) : string {
0 commit comments