From 20cbe507bb06921e0e8c59333a032b4a6feaae21 Mon Sep 17 00:00:00 2001 From: honnamkuan Date: Fri, 12 May 2023 11:08:46 +0800 Subject: [PATCH 1/2] align lastMessageText formatting with backend by trimming leading and trailing spaces --- src/libs/ReportActionsUtils.js | 5 ++++- src/libs/ReportUtils.js | 7 +++++-- src/libs/actions/Report.js | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index de77e7f5243e..314d7a6740a1 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -158,7 +158,10 @@ function getLastVisibleMessageText(reportID, actionsToMerge = {}) { const htmlText = lodashGet(lastVisibleAction, 'message[0].html', ''); const parser = new ExpensiMark(); const messageText = parser.htmlToText(htmlText); - return String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); + return String(messageText) + .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '') + .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) + .trim(); } /** diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 18a479675110..649627f2b1bd 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -525,12 +525,15 @@ function canShowReportRecipientLocalTime(personalDetails, report) { } /** - * Trim the last message text to a fixed limit. + * Html decode, shorten last message text to fixed length and trim spaces. * @param {String} lastMessageText * @returns {String} */ function formatReportLastMessageText(lastMessageText) { - return String(lastMessageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); + return Str.htmlDecode(String(lastMessageText)) + .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '') + .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) + .trim(); } /** diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 26d9b9da7357..d881994302ab 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -218,7 +218,7 @@ function addActions(reportID, text = '', file) { const optimisticReport = { lastVisibleActionCreated: currentTime, - lastMessageText: Str.htmlDecode(lastCommentText), + lastMessageText: lastCommentText, lastActorEmail: currentUserEmail, lastReadTime: currentTime, }; @@ -979,7 +979,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { const reportComment = parser.htmlToText(htmlForNewComment); const lastMessageText = ReportUtils.formatReportLastMessageText(reportComment); const optimisticReport = { - lastMessageText: Str.htmlDecode(lastMessageText), + lastMessageText, }; optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From aa8d4182f45a9fc5096372c6844a24de9b42e7d6 Mon Sep 17 00:00:00 2001 From: honnamkuan Date: Fri, 12 May 2023 15:17:21 +0800 Subject: [PATCH 2/2] apply prettier formatting --- src/libs/ReportActionsUtils.js | 5 +---- src/libs/ReportUtils.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 314d7a6740a1..4ab84faad6e4 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -158,10 +158,7 @@ function getLastVisibleMessageText(reportID, actionsToMerge = {}) { const htmlText = lodashGet(lastVisibleAction, 'message[0].html', ''); const parser = new ExpensiMark(); const messageText = parser.htmlToText(htmlText); - return String(messageText) - .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '') - .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) - .trim(); + return String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(); } /** diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 649627f2b1bd..dc295460175b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -530,10 +530,7 @@ function canShowReportRecipientLocalTime(personalDetails, report) { * @returns {String} */ function formatReportLastMessageText(lastMessageText) { - return Str.htmlDecode(String(lastMessageText)) - .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '') - .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH) - .trim(); + return Str.htmlDecode(String(lastMessageText)).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(); } /**