Make Lifecycle.loadSession return an explicit result

- rather than inferring it from the fact it didn't call logging_in.
pull/21833/head
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.
*
* @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;
});
}

View File

@ -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
*