Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/35596: Last message text display incorrectly #37581

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ function getLastVisibleMessage(reportID: string, actionsToMerge: OnyxCollection<
}
return {
lastMessageText: messageText,
lastMessageHtml: message?.html,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the main issue, our solution is to display the LHN text based on the lastMessageHtml. If we do not add lastMessageHtml: message?.html like this, when we remove any message, the LHN text is still the removed message

};
}

Expand Down
9 changes: 7 additions & 2 deletions 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure when we send a multiple lines message, for example:

Line 1
Line 2

the LHN display as Line 1 ... (See issue)

}
return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, ' ').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim();
}

Expand Down Expand Up @@ -1799,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);
Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -1170,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;
Expand All @@ -1180,6 +1179,7 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) {
lastMessageText,
lastVisibleActionCreated,
lastActorAccountID,
lastMessageHtml,
};
}

Expand Down
Loading