Skip to content

Commit

Permalink
Merge pull request #27380 from tienifr/fix/27054
Browse files Browse the repository at this point in the history
fix: 27054 Conversations do not load if you interrupt the Internet connection when logging in
  • Loading branch information
deetergp authored Sep 20, 2023
2 parents e2a1343 + c9f3f2b commit 8000576
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ const ONYXKEYS = {
/** Is report data loading? */
IS_LOADING_REPORT_DATA: 'isLoadingReportData',

/** Is report data loading? */
IS_LOADING_APP: 'isLoadingApp',

/** Is Keyboard shortcuts modal open? */
IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen',

Expand Down
17 changes: 16 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import DemoSetupPage from '../../../pages/DemoSetupPage';

let timezone;
let currentAccountID;
let isLoadingApp;

Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
Expand Down Expand Up @@ -75,6 +77,13 @@ Onyx.connect({
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_APP,
callback: (val) => {
isLoadingApp = val;
},
});

const RootStack = createCustomStackNavigator();

// We want to delay the re-rendering for components(e.g. ReportActionCompose)
Expand Down Expand Up @@ -126,7 +135,13 @@ class AuthScreens extends React.Component {

componentDidMount() {
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => App.reconnectApp(this.props.lastUpdateIDAppliedToClient));
NetworkConnection.onReconnect(() => {
if (isLoadingApp) {
App.openApp();
} else {
App.reconnectApp(this.props.lastUpdateIDAppliedToClient);
}
});
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
Expand Down
34 changes: 31 additions & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ function getPolicyParamsForOpenOrReconnect() {

/**
* Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
* @param {Boolean} isOpenApp
* @returns {Object}
*/
function getOnyxDataForOpenOrReconnect() {
return {
function getOnyxDataForOpenOrReconnect(isOpenApp = false) {
const defaultData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -167,14 +168,41 @@ function getOnyxDataForOpenOrReconnect() {
},
],
};
if (!isOpenApp) return defaultData;
return {
optimisticData: [
...defaultData.optimisticData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: true,
},
],
successData: [
...defaultData.successData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
},
],
failureData: [
...defaultData.failureData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
},
],
};
}

/**
* Fetches data needed for app initialization
*/
function openApp() {
getPolicyParamsForOpenOrReconnect().then((policyParams) => {
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect());
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect(true));
});
}

Expand Down

0 comments on commit 8000576

Please sign in to comment.