From 3b518f2c597d68ec811bc3424e86ef80d862d6dd Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 19 Jun 2017 10:22:18 +0100 Subject: [PATCH] Fix race in registration for pusher config we no longer immediately create the MatrixClient, so don't assume we do. --- src/Lifecycle.js | 7 +++++-- src/components/structures/MatrixChat.js | 3 ++- src/components/structures/login/Registration.js | 12 ++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 3733ba1ea5..59580e7cb6 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -294,10 +294,12 @@ export function initRtsClient(url) { * storage before starting the new client. * * @param {MatrixClientCreds} credentials The credentials to use + * + * @returns {Promise} promise which resolves to the new MatrixClient once it has been started */ export function setLoggedIn(credentials) { stopMatrixClient(); - _doSetLoggedIn(credentials, true); + return _doSetLoggedIn(credentials, true); } /** @@ -307,7 +309,7 @@ export function setLoggedIn(credentials) { * @param {MatrixClientCreds} credentials * @param {Boolean} clearStorage * - * returns a Promise which resolves once the client has been started + * @returns {Promise} promise which resolves to the new MatrixClient once it has been started */ async function _doSetLoggedIn(credentials, clearStorage) { credentials.guest = Boolean(credentials.guest); @@ -374,6 +376,7 @@ async function _doSetLoggedIn(credentials, clearStorage) { }); startMatrixClient(); + return MatrixClientPeg.get(); } function _persistCredentialsToLocalStorage(credentials) { diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 26f0edf309..e2bb5764cc 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1280,13 +1280,14 @@ module.exports = React.createClass({ } }, + // returns a promise which resolves to the new MatrixClient onRegistered: function(credentials, teamToken) { // XXX: These both should be in state or ideally store(s) because we risk not // rendering the most up-to-date view of state otherwise. // teamToken may not be truthy this._teamToken = teamToken; this._is_registered = true; - Lifecycle.setLoggedIn(credentials); + return Lifecycle.setLoggedIn(credentials); }, onFinishPostRegistration: function() { diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 17fbf445b2..388198bb02 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -218,29 +218,29 @@ module.exports = React.createClass({ } trackPromise.then((teamToken) => { - this.props.onLoggedIn({ + return this.props.onLoggedIn({ userId: response.user_id, deviceId: response.device_id, homeserverUrl: this._matrixClient.getHomeserverUrl(), identityServerUrl: this._matrixClient.getIdentityServerUrl(), accessToken: response.access_token }, teamToken); - }).then(() => { - return this._setupPushers(); + }).then((cli) => { + return this._setupPushers(cli); }); }, - _setupPushers: function() { + _setupPushers: function(matrixClient) { if (!this.props.brand) { return q(); } - return MatrixClientPeg.get().getPushers().then((resp)=>{ + return matrixClient.getPushers().then((resp)=>{ const pushers = resp.pushers; for (let i = 0; i < pushers.length; ++i) { if (pushers[i].kind == 'email') { const emailPusher = pushers[i]; emailPusher.data = { brand: this.props.brand }; - MatrixClientPeg.get().setPusher(emailPusher).done(() => { + matrixClient.setPusher(emailPusher).done(() => { console.log("Set email branding to " + this.props.brand); }, (error) => { console.error("Couldn't set email branding: " + error);