Skip to content

Commit

Permalink
fix last message text display
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Mar 1, 2024
1 parent b5003f9 commit c2613a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -585,8 +586,13 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, 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 ?? '')
);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,16 @@ function canShowReportRecipientLocalTime(personalDetails: OnyxCollection<Persona
/**
* Shorten last message text to fixed length and trim spaces.
*/
function formatReportLastMessageText(lastMessageText: string, isModifiedExpenseMessage = false): string {
function formatReportLastMessageText(lastMessageText: string, isModifiedExpenseMessage = false, isAddComment = false): string {
if (isModifiedExpenseMessage) {
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.LINE_BREAK, ' ').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim();
}

Expand Down
5 changes: 2 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,12 @@ function addActions(reportID: string, text = '', file?: FileObject) {
const lastAction = attachmentAction ?? reportCommentAction;
const currentTime = DateUtils.getDBTimeWithSkew();
const lastComment = lastAction?.message?.[0];
const lastCommentText = ReportUtils.formatReportLastMessageText(lastComment?.text ?? '');

const optimisticReport: Partial<Report> = {
lastVisibleActionCreated: currentTime,
lastMessageTranslationKey: lastComment?.translationKey ?? '',
lastMessageText: lastCommentText,
lastMessageHtml: lastCommentText,
lastMessageText: text,
lastMessageHtml: text,
lastActorAccountID: currentUserAccountID,
lastReadTime: currentTime,
};
Expand Down

0 comments on commit c2613a7

Please sign in to comment.