Skip to content

Commit

Permalink
align lastMessageText formatting with backend
Browse files Browse the repository at this point in the history
by trimming leading and trailing spaces
  • Loading branch information
honnamkuan committed May 12, 2023
1 parent 5fd5419 commit 20cbe50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function addActions(reportID, text = '', file) {

const optimisticReport = {
lastVisibleActionCreated: currentTime,
lastMessageText: Str.htmlDecode(lastCommentText),
lastMessageText: lastCommentText,
lastActorEmail: currentUserEmail,
lastReadTime: currentTime,
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 20cbe50

Please sign in to comment.