From 03441e314dbc8bab6c2b6a8d290ee81785888dde Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 2 Apr 2025 17:15:13 +0700 Subject: [PATCH 1/2] fix: keep public room after login --- src/libs/actions/App.ts | 29 ++++++++++++++++++++++++++--- src/pages/signin/SignInModal.tsx | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 226299c4ad41..90ef4a23d0ca 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -16,6 +16,7 @@ import Log from '@libs/Log'; import getCurrentUrl from '@libs/Navigation/currentUrl'; import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; +import {isPublicRoom, isValidReport} from '@libs/ReportUtils'; import {isLoggingInAsNewUser as isLoggingInAsNewUserSessionUtils} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import CONST from '@src/CONST'; @@ -113,6 +114,15 @@ Onyx.connect({ }, }); +let allReports: OnyxCollection; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (value) => { + allReports = value; + }, +}); + const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.ACCOUNT, ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, @@ -237,7 +247,7 @@ function getPolicyParamsForOpenOrReconnect(): Promise isPublicRoom(report) && isValidReport(report)); + publicReports?.forEach((report) => { + result.successData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`, + value: { + ...report, + }, + }); + }); + } + return result; } /** * Fetches data needed for app initialization */ -function openApp() { +function openApp(shouldKeepPublicRooms = false) { return getPolicyParamsForOpenOrReconnect().then((policyParams: PolicyParamsForOpenOrReconnect) => { const params: OpenAppParams = {enablePriorityModeFilter: true, ...policyParams}; - return API.write(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true), { + return API.write(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true, undefined, shouldKeepPublicRooms), { checkAndFixConflictingRequest: (persistedRequests) => resolveDuplicationConflictAction(persistedRequests, (request) => request.command === WRITE_COMMANDS.OPEN_APP), }); }); diff --git a/src/pages/signin/SignInModal.tsx b/src/pages/signin/SignInModal.tsx index 8cfa3ba3dcc8..707613a1a7a5 100644 --- a/src/pages/signin/SignInModal.tsx +++ b/src/pages/signin/SignInModal.tsx @@ -30,7 +30,7 @@ function SignInModal() { // This ensures that any communication gaps between the client and server during OpenReport processing do not cause the queue to pause, // which would prevent us from processing or clearing the queue. waitForIdle().then(() => { - App.openApp(); + App.openApp(true); }); } }, [session?.authTokenType]); From d88cf9f9b2d967fbcc4a0745b40fa0d09c950d1c Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 2 Apr 2025 17:19:09 +0700 Subject: [PATCH 2/2] fix: lint --- src/pages/signin/SignInModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/signin/SignInModal.tsx b/src/pages/signin/SignInModal.tsx index 707613a1a7a5..18396782d7cc 100644 --- a/src/pages/signin/SignInModal.tsx +++ b/src/pages/signin/SignInModal.tsx @@ -4,9 +4,9 @@ import {useSession} from '@components/OnyxProvider'; import ScreenWrapper from '@components/ScreenWrapper'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; +import {openApp} from '@libs/actions/App'; import Navigation from '@libs/Navigation/Navigation'; import {waitForIdle} from '@libs/Network/SequentialQueue'; -import * as App from '@userActions/App'; import CONST from '@src/CONST'; import SCREENS from '@src/SCREENS'; import SignInPage from './SignInPage'; @@ -30,7 +30,7 @@ function SignInModal() { // This ensures that any communication gaps between the client and server during OpenReport processing do not cause the queue to pause, // which would prevent us from processing or clearing the queue. waitForIdle().then(() => { - App.openApp(true); + openApp(true); }); } }, [session?.authTokenType]);