Skip to content

Commit

Permalink
Merge pull request #18822 from honnamkuan/17896
Browse files Browse the repository at this point in the history
align lastMessageText formatting with backend by trimming leading and trailing spaces
  • Loading branch information
robertjchen authored May 16, 2023
2 parents 1bf45c7 + aa8d418 commit dd5fbb6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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);
return String(messageText).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/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,12 @@ 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 @@ -1032,7 +1032,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 dd5fbb6

Please sign in to comment.