Make Lifecycle.loadSession return an explicit result

- rather than inferring it from the fact it didn't call logging_in.
This commit is contained in:
Richard van der Hoff 2017-06-16 12:20:52 +01:00
parent 5f689b7929
commit db3d9c0573
2 changed files with 13 additions and 21 deletions

View file

@ -62,6 +62,8 @@ import { _t } from './languageHandler';
* true; defines the IS to use. * true; defines the IS to use.
* *
* @returns {Promise} a promise which resolves when the above process completes. * @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) { export function loadSession(opts) {
const fragmentQueryParams = opts.fragmentQueryParams || {}; const fragmentQueryParams = opts.fragmentQueryParams || {};
@ -86,12 +88,12 @@ export function loadSession(opts) {
homeserverUrl: guestHsUrl, homeserverUrl: guestHsUrl,
identityServerUrl: guestIsUrl, identityServerUrl: guestIsUrl,
guest: true, guest: true,
}, true); }, true).then(() => true);
} }
return _restoreFromLocalStorage().then((success) => { return _restoreFromLocalStorage().then((success) => {
if (success) { if (success) {
return; return true;
} }
if (enableGuest) { if (enableGuest) {
@ -99,6 +101,7 @@ export function loadSession(opts) {
} }
// fall back to login screen // fall back to login screen
return false;
}); });
} }
@ -176,9 +179,10 @@ function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) {
homeserverUrl: hsUrl, homeserverUrl: hsUrl,
identityServerUrl: isUrl, identityServerUrl: isUrl,
guest: true, guest: true,
}, true); }, true).then(() => true);
}, (err) => { }, (err) => {
console.error("Failed to register as guest: " + err + " " + err.data); console.error("Failed to register as guest: " + err + " " + err.data);
return false;
}); });
} }

View file

@ -335,10 +335,12 @@ module.exports = React.createClass({
}); });
}).catch((e) => { }).catch((e) => {
console.error("Unable to load session", e); console.error("Unable to load session", e);
}).then(()=>{ return false;
// stuff this through the dispatcher so that it happens }).then((loadedSession) => {
// after the on_logged_in action. if (!loadedSession) {
dis.dispatch({action: 'load_completed'}); // fall back to showing the login screen
dis.dispatch({action: "start_login"});
}
}); });
}).done(); }).done();
}, },
@ -560,9 +562,6 @@ module.exports = React.createClass({
case 'will_start_client': case 'will_start_client':
this._onWillStartClient(); this._onWillStartClient();
break; break;
case 'load_completed':
this._onLoadCompleted();
break;
case 'new_version': case 'new_version':
this.onVersion( this.onVersion(
payload.currentVersion, payload.newVersion, 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 * Called whenever someone changes the theme
* *