diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 3bebd5a0813a..fcaf56f1fefa 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -272,14 +272,8 @@ 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, - ); - visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1]; + const reportActionsForDisplay = sortedReportActions.filter((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)); + visibleReportActionItems[reportID] = reportActionsForDisplay[0]; }, }); @@ -559,7 +553,7 @@ function getAlternateText( * 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; let lastMessageTextFromReport = ''; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index c0d0c9020a64..74fab75dcc18 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -36,13 +36,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, - ); + const reportActionsForDisplay = actionsArray.filter((reportAction) => ReportActionsUtils.shouldReportActionBeVisibleAsLastAction(reportAction)); visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1]; },