From c2613a7b32980a62495d809a6974e2426f293865 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Mar 2024 07:25:24 +0700 Subject: [PATCH 1/5] fix last message text display --- src/libs/OptionsListUtils.ts | 10 ++++++++-- src/libs/ReportUtils.ts | 8 +++++++- src/libs/actions/Report.ts | 5 ++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9121eebb3367..3f8176a3f6f5 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1,4 +1,5 @@ /* eslint-disable no-continue */ +import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; // eslint-disable-next-line you-dont-need-lodash-underscore/get import lodashGet from 'lodash/get'; @@ -585,8 +586,13 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); } - - return lastMessageTextFromReport || (report?.lastMessageText ?? ''); + const parser = new ExpensiMark(); + return ( + lastMessageTextFromReport || + (lastActionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT + ? ReportUtils.formatReportLastMessageText(parser.htmlToText(report?.lastMessageHtml ?? ''), false, true) + : report?.lastMessageText ?? '') + ); } /** diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ea0eba523092..92283e95aa81 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1377,10 +1377,16 @@ function canShowReportRecipientLocalTime(personalDetails: OnyxCollection = { lastVisibleActionCreated: currentTime, lastMessageTranslationKey: lastComment?.translationKey ?? '', - lastMessageText: lastCommentText, - lastMessageHtml: lastCommentText, + lastMessageText: text, + lastMessageHtml: text, lastActorAccountID: currentUserAccountID, lastReadTime: currentTime, }; From 1286f6deca3f5b1d8fa8074c71ad8b3155a79e08 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Mar 2024 08:44:01 +0700 Subject: [PATCH 2/5] fix delete comment issue --- src/libs/ReportActionsUtils.ts | 1 + src/libs/ReportUtils.ts | 3 +-- src/libs/actions/Report.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 5c2a25e1d328..693c660880e2 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -502,6 +502,7 @@ function getLastVisibleMessage(reportID: string, actionsToMerge: OnyxCollection< } return { lastMessageText: messageText, + lastMessageHtml: message?.html, }; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 92283e95aa81..9ecd556a0d1f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1805,7 +1805,6 @@ function buildOptimisticCancelPaymentReportAction(expenseReportID: string, amoun function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: ReportActions = {}): LastVisibleMessage { const report = getReport(reportID); const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID ?? '', actionsToMerge); - // For Chat Report with deleted parent actions, let us fetch the correct message if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && !isEmptyObject(report) && isChatReport(report)) { const lastMessageText = getDeletedParentActionMessageForChatReport(lastVisibleAction); @@ -1813,7 +1812,7 @@ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: Rep lastMessageText, }; } - + // Fetch the last visible message for report represented by reportID and based on actions to merge. return ReportActionsUtils.getLastVisibleMessage(reportID ?? '', actionsToMerge); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 229da5756208..2f03055f610c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1169,7 +1169,7 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) { lastMessageText: '', lastVisibleActionCreated: '', }; - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions as ReportActions); + const {lastMessageText = '', lastMessageTranslationKey = '', lastMessageHtml = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions as ReportActions); if (lastMessageText || lastMessageTranslationKey) { const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions as ReportActions); const lastVisibleActionCreated = lastVisibleAction?.created; @@ -1179,6 +1179,7 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) { lastMessageText, lastVisibleActionCreated, lastActorAccountID, + lastMessageHtml }; } From 72ea0daf5fc04c91459ad3532017b1923ded0af1 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Mar 2024 08:50:37 +0700 Subject: [PATCH 3/5] fix lint --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9ecd556a0d1f..8f6c20436030 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1812,7 +1812,7 @@ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: Rep lastMessageText, }; } - + // Fetch the last visible message for report represented by reportID and based on actions to merge. return ReportActionsUtils.getLastVisibleMessage(reportID ?? '', actionsToMerge); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2f03055f610c..27328798897c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1179,7 +1179,7 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) { lastMessageText, lastVisibleActionCreated, lastActorAccountID, - lastMessageHtml + lastMessageHtml, }; } From 8432fa6f814c336e7302c9e686e81362a51e2481 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sun, 3 Mar 2024 23:27:42 +0700 Subject: [PATCH 4/5] fix ellipses is not displayed in native --- src/libs/ReportUtils.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8f6c20436030..3dc511dcd21a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1382,10 +1382,12 @@ function formatReportLastMessageText(lastMessageText: string, isModifiedExpenseM return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, '').trim(); } if (isAddComment) { - return String(lastMessageText) - .trim() - .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, ' '.repeat(CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH)) - .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); + return ( + String(lastMessageText) + .trim() + .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, ' '.repeat(CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH)) + .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) + '\u200B' + ); } return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, ' ').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(); } From d2814217b02d4581243ee9a34cbee67748914ccf Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Mar 2024 00:12:24 +0700 Subject: [PATCH 5/5] fix lint --- src/components/LHNOptionsList/OptionRowLHN.tsx | 2 +- src/libs/ReportUtils.ts | 10 ++++------ tests/ui/UnreadIndicatorsTest.js | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 923337ba9ada..7d281753e38b 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -225,7 +225,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti numberOfLines={1} accessibilityLabel={translate('accessibilityHints.lastChatMessagePreview')} > - {optionItem.alternateText} + {`${optionItem.alternateText}\u200B`} ) : null} diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3dc511dcd21a..8f6c20436030 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1382,12 +1382,10 @@ function formatReportLastMessageText(lastMessageText: string, isModifiedExpenseM return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, '').trim(); } if (isAddComment) { - return ( - String(lastMessageText) - .trim() - .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, ' '.repeat(CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH)) - .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) + '\u200B' - ); + return String(lastMessageText) + .trim() + .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, ' '.repeat(CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH)) + .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); } return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, ' ').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(); } diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index 6051f04f570e..3da4587c55b1 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -618,7 +618,7 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const alternateText = screen.queryAllByLabelText(hintText); expect(alternateText).toHaveLength(1); - expect(alternateText[0].props.children).toBe('Current User Comment 1'); + expect(alternateText[0].props.children).toBe('Current User Comment 1\u200B'); Report.deleteReportComment(REPORT_ID, lastReportAction); return waitForBatchedUpdates(); @@ -627,7 +627,7 @@ describe('Unread Indicators', () => { const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); const alternateText = screen.queryAllByLabelText(hintText); expect(alternateText).toHaveLength(1); - expect(alternateText[0].props.children).toBe('Comment 9'); + expect(alternateText[0].props.children).toBe('Comment 9\u200B'); }) ); });