Skip to content
Merged
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
29 changes: 26 additions & 3 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,6 +114,15 @@ Onyx.connect({
},
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
allReports = value;
},
});

const KEYS_TO_PRESERVE: OnyxKey[] = [
ONYXKEYS.ACCOUNT,
ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
Expand Down Expand Up @@ -237,7 +247,7 @@ function getPolicyParamsForOpenOrReconnect(): Promise<PolicyParamsForOpenOrRecon
/**
* Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
*/
function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = false): OnyxData {
function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = false, shouldKeepPublicRooms = false): OnyxData {
const result: OnyxData = {
optimisticData: [
{
Expand Down Expand Up @@ -284,16 +294,29 @@ function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = fals
});
}

if (shouldKeepPublicRooms) {
const publicReports = Object.values(allReports ?? {}).filter((report) => 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),
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/signin/SignInModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
openApp(true);
});
}
}, [session?.authTokenType]);
Expand Down