Skip to content

Commit

Permalink
Merge pull request #52824 from software-mansion-labs/use-reconnect-in…
Browse files Browse the repository at this point in the history
…-hybrid-app

Use reconnect when starting hybrid app
  • Loading branch information
Julesssss authored Nov 21, 2024
2 parents bf883a7 + 97f21aa commit 0250799
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {findFocusedRoute} from '@react-navigation/native';
import React, {memo, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {NativeModules, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx, {withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -276,13 +276,16 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
setDidPusherInit(true);
});

// If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app
// or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp().
if (SessionUtils.didUserLogInDuringSession()) {
App.openApp();
} else {
Log.info('[AuthScreens] Sending ReconnectApp');
App.reconnectApp(initialLastUpdateIDAppliedToClient);
// In Hybrid App we decide to call one of those method when booting ND and we don't want to duplicate calls
if (!NativeModules.HybridAppModule) {
// If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app
// or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp().
if (SessionUtils.didUserLogInDuringSession()) {
App.openApp();
} else {
Log.info('[AuthScreens] Sending ReconnectApp');
App.reconnectApp(initialLastUpdateIDAppliedToClient);
}
}

PriorityMode.autoSwitchToFocusMode();
Expand Down
18 changes: 17 additions & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ function signUpUser() {
API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData});
}

function getLastUpdateIDAppliedToClient(): Promise<number> {
return new Promise((resolve) => {
Onyx.connect({
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value) => resolve(value ?? 0),
});
});
}

function signInAfterTransitionFromOldDot(transitionURL: string) {
const [route, queryParams] = transitionURL.split('?');

Expand Down Expand Up @@ -528,7 +537,14 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {
[ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {completedHybridAppOnboarding: completedHybridAppOnboarding === 'true'}},
}),
)
.then(App.openApp)
.then(() => {
if (clearOnyxOnStart === 'true') {
return App.openApp();
}
return getLastUpdateIDAppliedToClient().then((lastUpdateId) => {
return App.reconnectApp(lastUpdateId);
});
})
.catch((error) => {
Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error});
})
Expand Down

0 comments on commit 0250799

Please sign in to comment.