From db3d9c057349099e7186e8ab51d76f5e24a0a972 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 16 Jun 2017 12:20:52 +0100 Subject: [PATCH] Make Lifecycle.loadSession return an explicit result - rather than inferring it from the fact it didn't call logging_in. --- src/Lifecycle.js | 10 +++++++--- src/components/structures/MatrixChat.js | 24 ++++++------------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 1c5d35a642..3733ba1ea5 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -62,6 +62,8 @@ import { _t } from './languageHandler'; * true; defines the IS to use. * * @returns {Promise} a promise which resolves when the above process completes. + * Resolves to `true` if we ended up starting a session, or `false` if we + * failed. */ export function loadSession(opts) { const fragmentQueryParams = opts.fragmentQueryParams || {}; @@ -86,12 +88,12 @@ export function loadSession(opts) { homeserverUrl: guestHsUrl, identityServerUrl: guestIsUrl, guest: true, - }, true); + }, true).then(() => true); } return _restoreFromLocalStorage().then((success) => { if (success) { - return; + return true; } if (enableGuest) { @@ -99,6 +101,7 @@ export function loadSession(opts) { } // fall back to login screen + return false; }); } @@ -176,9 +179,10 @@ function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) { homeserverUrl: hsUrl, identityServerUrl: isUrl, guest: true, - }, true); + }, true).then(() => true); }, (err) => { console.error("Failed to register as guest: " + err + " " + err.data); + return false; }); } diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 2c95386811..831fcdd9b2 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -335,10 +335,12 @@ module.exports = React.createClass({ }); }).catch((e) => { console.error("Unable to load session", e); - }).then(()=>{ - // stuff this through the dispatcher so that it happens - // after the on_logged_in action. - dis.dispatch({action: 'load_completed'}); + return false; + }).then((loadedSession) => { + if (!loadedSession) { + // fall back to showing the login screen + dis.dispatch({action: "start_login"}); + } }); }).done(); }, @@ -560,9 +562,6 @@ module.exports = React.createClass({ case 'will_start_client': this._onWillStartClient(); break; - case 'load_completed': - this._onLoadCompleted(); - break; case 'new_version': this.onVersion( payload.currentVersion, payload.newVersion, @@ -892,17 +891,6 @@ module.exports = React.createClass({ }); }, - /** - * Called when the sessionloader has finished - */ - _onLoadCompleted: function() { - // if we've got this far without leaving the 'loading' view, then - // login must have failed, so start the login process - if (this.state.view === VIEWS.LOADING) { - dis.dispatch({action: "start_login"}); - } - }, - /** * Called whenever someone changes the theme *