From a1b924cf4964e5b3a358b3c1b974a861fdb49114 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Fri, 3 Oct 2025 02:21:14 +0530 Subject: [PATCH 1/2] Ensure correct reportId is used when opening an offline-created chat --- src/libs/actions/Report.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 79c3467c1900..29e8d5e6d324 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1391,24 +1391,37 @@ function navigateToAndOpenReport( } const report = isEmptyObject(chat) ? newChat : chat; + // Helper to resolve the latest chat after potential server reconciliation (e.g., preexistingReportID replacement) + const getLatestTargetReportID = (): string | undefined => { + // Prefer a freshly resolved existing chat if available + const latestChat = getChatByParticipants([...participantAccountIDs, currentUserAccountID]); + return latestChat?.reportID ?? report?.reportID; + }; + if (shouldDismissModal) { Navigation.onModalDismissedOnce(() => { Navigation.onModalDismissedOnce(() => { - if (!report?.reportID) { + const targetReportID = getLatestTargetReportID(); + if (!targetReportID) { return; } - - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(targetReportID)); }); }); - Navigation.dismissModal(); - } else if (report?.reportID) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); + } else { + const targetReportID = getLatestTargetReportID(); + if (targetReportID) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(targetReportID)); + } } - // In some cases when RHP modal gets hidden and then we navigate to report Composer focus breaks, wrapping navigation in setTimeout fixes this + setTimeout(() => { - Navigation.isNavigationReady().then(() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID))); + const targetReportID = getLatestTargetReportID(); + if (!targetReportID) { + return; + } + Navigation.isNavigationReady().then(() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(targetReportID))); }, 0); } From 376b64fb6d9248e6ab43fb433fb383a8b868e07a Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:18:42 +0530 Subject: [PATCH 2/2] Update --- src/libs/PersonalDetailsUtils.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 52360cc79d60..dcb0901dd1f1 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -149,12 +149,16 @@ function getPersonalDetailByEmail(email: string): PersonalDetails | undefined { */ function getAccountIDsByLogins(logins: string[]): number[] { return logins.reduce((foundAccountIDs, login) => { - const currentDetail = personalDetails.find((detail) => detail?.login === login?.toLowerCase()); - if (!currentDetail) { + const normalizedLogin = login?.toLowerCase(); + const matchingDetails = personalDetails.filter((detail) => detail?.login === normalizedLogin); + // Prefer the confirmed personal detail once it arrives, fall back to the optimistic entry otherwise + const preferredDetail = matchingDetails.find((detail) => !detail?.isOptimisticPersonalDetail) ?? matchingDetails.at(0); + + if (!preferredDetail) { // generate an account ID because in this case the detail is probably new, so we don't have a real accountID yet foundAccountIDs.push(generateAccountID(login)); } else { - foundAccountIDs.push(Number(currentDetail.accountID)); + foundAccountIDs.push(preferredDetail.accountID); } return foundAccountIDs; }, []);