From b3a2daf690bd3616edee815c0b4a1082d138687e Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 25 Jul 2024 13:58:07 +0700 Subject: [PATCH 1/2] fix: leaving from multilevel threads navigates to wrong thread --- src/libs/ReportUtils.ts | 13 +++++++------ src/libs/actions/Report.ts | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9194ce15ef42..4c965810e641 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1207,14 +1207,15 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean { return accountIDs.some((accountID) => Str.extractEmailDomain(allPersonalDetails?.[accountID]?.login ?? '') === CONST.EMAIL.GUIDES_DOMAIN); } -function getMostRecentlyVisitedReport(reports: Array>, reportMetadata: OnyxCollection): OnyxEntry { - const filteredReports = reports.filter( - (report) => !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime), - ); +function getMostRecentlyVisitedReport(reports: Array>, reportMetadata: OnyxCollection, shouldKeepLeavedThread = true): OnyxEntry { + const filteredReports = reports.filter((report) => { + const shouldKeep = shouldKeepLeavedThread || !isChatThread(report) || (isChatThread(report) && report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime); + }); return lodashMaxBy(filteredReports, (a) => new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? '').valueOf()); } -function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string): OnyxEntry { +function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string, shouldKeepLeavedThread = true): OnyxEntry { // If it's the user's first time using New Expensify, then they could either have: // - just a Concierge report, if so we'll return that // - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account. @@ -1286,7 +1287,7 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa } // We are getting the last read report from the metadata of the report. - const lastRead = getMostRecentlyVisitedReport(reportsValues, allReportMetadata); + const lastRead = getMostRecentlyVisitedReport(reportsValues, allReportMetadata, shouldKeepLeavedThread); return adminReport ?? lastRead; } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index b4d1360b2d94..01965539133e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2654,8 +2654,8 @@ function getCurrentUserAccountID(): number { return currentUserAccountID; } -function navigateToMostRecentReport(currentReport: OnyxEntry) { - const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID; +function navigateToMostRecentReport(currentReport: OnyxEntry, shouldKeepLeavedThread = true) { + const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID, shouldKeepLeavedThread)?.reportID; if (lastAccessedReportID) { const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID ?? '-1'); @@ -2793,7 +2793,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal return; } // In other cases, the report is deleted and we should move the user to another report. - navigateToMostRecentReport(report); + navigateToMostRecentReport(report, false); } /** Invites people to a room */ From 947c16c61a295af0d5683b532c1a775dcb9a1c94 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 26 Jul 2024 12:21:26 +0700 Subject: [PATCH 2/2] fix: remove shouldKeepLeavedThread --- src/libs/ReportUtils.ts | 8 ++++---- src/libs/actions/Report.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4c965810e641..3572884786e8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1207,15 +1207,15 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean { return accountIDs.some((accountID) => Str.extractEmailDomain(allPersonalDetails?.[accountID]?.login ?? '') === CONST.EMAIL.GUIDES_DOMAIN); } -function getMostRecentlyVisitedReport(reports: Array>, reportMetadata: OnyxCollection, shouldKeepLeavedThread = true): OnyxEntry { +function getMostRecentlyVisitedReport(reports: Array>, reportMetadata: OnyxCollection): OnyxEntry { const filteredReports = reports.filter((report) => { - const shouldKeep = shouldKeepLeavedThread || !isChatThread(report) || (isChatThread(report) && report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + const shouldKeep = !isChatThread(report) || report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime); }); return lodashMaxBy(filteredReports, (a) => new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? '').valueOf()); } -function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string, shouldKeepLeavedThread = true): OnyxEntry { +function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string): OnyxEntry { // If it's the user's first time using New Expensify, then they could either have: // - just a Concierge report, if so we'll return that // - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account. @@ -1287,7 +1287,7 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa } // We are getting the last read report from the metadata of the report. - const lastRead = getMostRecentlyVisitedReport(reportsValues, allReportMetadata, shouldKeepLeavedThread); + const lastRead = getMostRecentlyVisitedReport(reportsValues, allReportMetadata); return adminReport ?? lastRead; } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 01965539133e..b4d1360b2d94 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2654,8 +2654,8 @@ function getCurrentUserAccountID(): number { return currentUserAccountID; } -function navigateToMostRecentReport(currentReport: OnyxEntry, shouldKeepLeavedThread = true) { - const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID, shouldKeepLeavedThread)?.reportID; +function navigateToMostRecentReport(currentReport: OnyxEntry) { + const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID; if (lastAccessedReportID) { const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID ?? '-1'); @@ -2793,7 +2793,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal return; } // In other cases, the report is deleted and we should move the user to another report. - navigateToMostRecentReport(report, false); + navigateToMostRecentReport(report); } /** Invites people to a room */