From afc6bca0ce2a182009bcb6a9205268ae26d3420c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 8 May 2024 11:04:47 +0800 Subject: [PATCH] fix inconsistent last message --- src/libs/OptionsListUtils.ts | 10 +++------- src/libs/SidebarUtils.ts | 6 +----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 082952e58f9e..1e321e194c26 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -285,13 +285,9 @@ Onyx.connect({ // The report is only visible if it is the last action not deleted that // does not match a closed or created state. const reportActionsForDisplay = sortedReportActions.filter( - (reportAction, actionKey) => - ReportActionUtils.shouldReportActionBeVisible(reportAction, actionKey) && - !ReportActionUtils.isWhisperAction(reportAction) && - reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED && - reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + (reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED, ); - visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1]; + visibleReportActionItems[reportID] = reportActionsForDisplay[0]; }, }); @@ -568,7 +564,7 @@ function getAlternateText(option: ReportUtils.OptionData, {showChatPreviewLine = * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - const lastReportAction = allSortedReportActions[report?.reportID ?? '']?.find((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)) ?? null; + const lastReportAction = visibleReportActionItems[report?.reportID ?? ''] ?? null; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action const lastOriginalReportAction = lastReportActions[report?.reportID ?? ''] ?? null; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index c0d0c9020a64..7e5745eba502 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -37,11 +37,7 @@ Onyx.connect({ // The report is only visible if it is the last action not deleted that // does not match a closed or created state. const reportActionsForDisplay = actionsArray.filter( - (reportAction, actionKey) => - ReportActionsUtils.shouldReportActionBeVisible(reportAction, actionKey) && - !ReportActionsUtils.isWhisperAction(reportAction) && - reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED && - reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + (reportAction) => ReportActionsUtils.shouldReportActionBeVisibleAsLastAction(reportAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED, ); visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1];