Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ function getPersonalDetailByEmail(email: string): PersonalDetails | undefined {
*/
function getAccountIDsByLogins(logins: string[]): number[] {
return logins.reduce<number[]>((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;
}, []);
Expand Down
29 changes: 21 additions & 8 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading