From d482a25fc9e9f37990c27c1d5906227eb6204cf2 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 27 Feb 2024 23:20:31 +0300 Subject: [PATCH] enable back navigation on leaving chat threads --- src/libs/actions/Report.ts | 48 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f29f8a4fbaab..8712541ee1e2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2254,6 +2254,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 @@ -2262,20 +2263,22 @@ 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, + }, }, ]; @@ -2283,12 +2286,13 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: isWorkspaceMemberLeavingWorkspaceRoom - ? {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN} - : Object.keys(report).reduce>((acc, key) => { - acc[key] = null; - return acc; - }, {}), + value: + isWorkspaceMemberLeavingWorkspaceRoom || isChatThread + ? {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN} + : Object.keys(report).reduce>((acc, key) => { + acc[key] = null; + return acc; + }, {}), }, ]; @@ -2344,15 +2348,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)); } }