Skip to content

Commit

Permalink
Merge pull request Expensify#37355 from FitseTLT/fix-navigation-after…
Browse files Browse the repository at this point in the history
…-leaving-chat-thread

Fix-unable to navigate back after leaving chat threads
  • Loading branch information
techievivek authored Feb 29, 2024
2 parents a416ca2 + d482a25 commit 48b24ec
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal
if (!report) {
return;
}
const isChatThread = ReportUtils.isChatThread(report);

// Pusher's leavingStatus should be sent earlier.
// Place the broadcast before calling the LeaveRoom API to prevent a race condition
Expand All @@ -2259,33 +2260,36 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal

// If a workspace member is leaving a workspace room, they don't actually lose the room from Onyx.
// Instead, their notification preference just gets set to "hidden".
// Same applies for chat threads too
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: isWorkspaceMemberLeavingWorkspaceRoom
? {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
}
: {
reportID: null,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
value:
isWorkspaceMemberLeavingWorkspaceRoom || isChatThread
? {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
}
: {
reportID: null,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: isWorkspaceMemberLeavingWorkspaceRoom
? {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}
: Object.keys(report).reduce<Record<string, null>>((acc, key) => {
acc[key] = null;
return acc;
}, {}),
value:
isWorkspaceMemberLeavingWorkspaceRoom || isChatThread
? {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}
: Object.keys(report).reduce<Record<string, null>>((acc, key) => {
acc[key] = null;
return acc;
}, {}),
},
];

Expand Down Expand Up @@ -2341,15 +2345,19 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal
const lastAccessedReportID = filteredReportsByLastRead.at(-1)?.reportID;

if (lastAccessedReportID) {
// We should call Navigation.goBack to pop the current route first before navigating to Concierge.
Navigation.goBack();
// If it is not a chat thread we should call Navigation.goBack to pop the current route first before navigating to last accessed report.
if (!isChatThread) {
Navigation.goBack();
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID));
} else {
const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins([CONST.EMAIL.CONCIERGE]);
const chat = ReportUtils.getChatByParticipants(participantAccountIDs);
if (chat?.reportID) {
// We should call Navigation.goBack to pop the current route first before navigating to Concierge.
Navigation.goBack();
// If it is not a chat thread we should call Navigation.goBack to pop the current route first before navigating to Concierge.
if (!isChatThread) {
Navigation.goBack();
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(chat.reportID));
}
}
Expand Down

0 comments on commit 48b24ec

Please sign in to comment.