Skip to content

Commit

Permalink
Merge pull request Expensify#28364 from rojiphil/19722-deleted-messag…
Browse files Browse the repository at this point in the history
…e-in-lhn

[Deleted message] in LHN subtitle
  • Loading branch information
chiragsalian authored Oct 17, 2023
2 parents 9aa14f8 + 901499a commit b22fbba
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ function getLastMessageTextForReport(report) {
ReportActionUtils.isMoneyRequestAction(reportAction),
);
lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true);
} else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) {
lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction);
} else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) {
const properSchemaForModifiedExpenseMessage = ReportUtils.getModifiedExpenseMessage(lastReportAction);
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true);
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,11 @@ function shouldReportActionBeVisibleAsLastAction(reportAction) {
}

// If a whisper action is the REPORTPREVIEW action, we are displaying it.
// If the action's message text is empty and it is not a deleted parent with visible child actions, hide it. Else, consider the action to be displayable.
return (
shouldReportActionBeVisible(reportAction, reportAction.reportActionID) &&
!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) &&
!isDeletedAction(reportAction)
!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction))
);
}

Expand Down
42 changes: 42 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,46 @@ function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantR
});
}

/**
* For a deleted parent report action within a chat report,
* let us return the appropriate display message
*
* @param {Object} reportAction - The deleted report action of a chat report for which we need to return message.
* @return {String}
*/
function getDeletedParentActionMessageForChatReport(reportAction) {
// By default, let us display [Deleted message]
let deletedMessageText = Localize.translateLocal('parentReportAction.deletedMessage');
if (ReportActionsUtils.isCreatedTaskReportAction(reportAction)) {
// For canceled task report, let us display [Deleted task]
deletedMessageText = Localize.translateLocal('parentReportAction.deletedTask');
}
return deletedMessageText;
}

/**
* Returns the last visible message for a given report after considering the given optimistic actions
*
* @param {String} reportID - the report for which last visible message has to be fetched
* @param {Object} [actionsToMerge] - the optimistic merge actions that needs to be considered while fetching last visible message
* @return {Object}
*/
function getLastVisibleMessage(reportID, actionsToMerge = {}) {
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) && isChatReport(report)) {
const lastMessageText = getDeletedParentActionMessageForChatReport(lastVisibleAction);
return {
lastMessageText,
};
}

// Fetch the last visible message for report represented by reportID and based on actions to merge.
return ReportActionsUtils.getLastVisibleMessage(reportID, actionsToMerge);
}

/**
* Determines if a report has an IOU that is waiting for an action from the current user (either Pay or Add a credit bank account)
*
Expand Down Expand Up @@ -3943,6 +3983,8 @@ export {
getReport,
getReportIDFromLink,
getRouteFromLink,
getDeletedParentActionMessageForChatReport,
getLastVisibleMessage,
navigateToDetailsPage,
generateReportID,
hasReportNameError,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ function deleteReportComment(reportID, reportAction) {
isLastMessageDeletedParentAction: true,
};
} else {
const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(originalReportID, optimisticReportActions);
const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions);
if (lastMessageText || lastMessageTranslationKey) {
const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions);
const lastVisibleActionCreated = lastVisibleAction.created;
Expand Down

0 comments on commit b22fbba

Please sign in to comment.