diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8f2382111f34..f6fe4ce8c661 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1531,14 +1531,14 @@ function isWaitingForAssigneeToCompleteTask(report: OnyxEntry, parentRep return isTaskReport(report) && isReportManager(report) && isOpenTaskReport(report, parentReportAction); } -function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { - if (!report) { +function isUnreadWithMention(reportOrOption: OnyxEntry | OptionData): boolean { + if (!reportOrOption) { return false; } // lastMentionedTime and lastReadTime are both datetime strings and can be compared directly - const lastMentionedTime = report.lastMentionedTime ?? ''; - const lastReadTime = report.lastReadTime ?? ''; - return lastReadTime < lastMentionedTime; + const lastMentionedTime = reportOrOption.lastMentionedTime ?? ''; + const lastReadTime = reportOrOption.lastReadTime ?? ''; + return Boolean('isUnreadWithMention' in reportOrOption && reportOrOption.isUnreadWithMention) || lastReadTime < lastMentionedTime; } /** @@ -1550,29 +1550,25 @@ function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { * @param option (report or optionItem) * @param parentReportAction (the report action the current report is a thread of) */ -function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData, parentReportAction: EmptyObject | OnyxEntry = {}) { - if (!option) { - return false; - } - - if (isArchivedRoom(option)) { +function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | OptionData, parentReportAction: EmptyObject | OnyxEntry = {}) { + if (!optionOrReport) { return false; } - if (isArchivedRoom(getReport(option.parentReportID))) { + if (isArchivedRoom(optionOrReport) || isArchivedRoom(getReport(optionOrReport.parentReportID))) { return false; } - if (Boolean('isUnreadWithMention' in option && option.isUnreadWithMention) || isUnreadWithMention(option)) { + if (isUnreadWithMention(optionOrReport)) { return true; } - if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { + if (isWaitingForAssigneeToCompleteTask(optionOrReport, parentReportAction)) { return true; } // Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user - if (option.hasOutstandingChildRequest) { + if (optionOrReport.hasOutstandingChildRequest) { return true; } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index bace29e06d28..3e4d27fa9704 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -187,7 +187,8 @@ function getOrderedReportIDs( report.iouReportAmount = ReportUtils.getMoneyRequestReimbursableTotal(report, allReports); const isPinned = report.isPinned ?? false; - if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report)) { + const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? ''); + if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { pinnedAndGBRReports.push(report); } else if (report.hasDraft) { draftReports.push(report); diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index e0c98b1793f1..e6b06e2aff5b 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -310,6 +310,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, managerID: currentUserAccountID, + isUnreadWithMention: false, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS.OPEN, };