diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9e51d35fb253..180b20489d39 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1549,14 +1549,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; } /** @@ -1568,29 +1568,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 1da1469a2687..b4873f9cdf40 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -185,7 +185,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, };