Merge pull request #1115 from matrix-org/rav/fix_registration_race

Fix race in registration for pusher config
This commit is contained in:
Richard van der Hoff 2017-06-19 10:56:56 +01:00 committed by GitHub
commit ac269e6392
3 changed files with 13 additions and 9 deletions

View file

@ -294,10 +294,12 @@ export function initRtsClient(url) {
* storage before starting the new client. * storage before starting the new client.
* *
* @param {MatrixClientCreds} credentials The credentials to use * @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) { export function setLoggedIn(credentials) {
stopMatrixClient(); stopMatrixClient();
_doSetLoggedIn(credentials, true); return _doSetLoggedIn(credentials, true);
} }
/** /**
@ -307,7 +309,7 @@ export function setLoggedIn(credentials) {
* @param {MatrixClientCreds} credentials * @param {MatrixClientCreds} credentials
* @param {Boolean} clearStorage * @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) { async function _doSetLoggedIn(credentials, clearStorage) {
credentials.guest = Boolean(credentials.guest); credentials.guest = Boolean(credentials.guest);
@ -374,6 +376,7 @@ async function _doSetLoggedIn(credentials, clearStorage) {
}); });
startMatrixClient(); startMatrixClient();
return MatrixClientPeg.get();
} }
function _persistCredentialsToLocalStorage(credentials) { function _persistCredentialsToLocalStorage(credentials) {

View file

@ -1280,13 +1280,14 @@ module.exports = React.createClass({
} }
}, },
// returns a promise which resolves to the new MatrixClient
onRegistered: function(credentials, teamToken) { onRegistered: function(credentials, teamToken) {
// XXX: These both should be in state or ideally store(s) because we risk not // 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. // rendering the most up-to-date view of state otherwise.
// teamToken may not be truthy // teamToken may not be truthy
this._teamToken = teamToken; this._teamToken = teamToken;
this._is_registered = true; this._is_registered = true;
Lifecycle.setLoggedIn(credentials); return Lifecycle.setLoggedIn(credentials);
}, },
onFinishPostRegistration: function() { onFinishPostRegistration: function() {

View file

@ -218,29 +218,29 @@ module.exports = React.createClass({
} }
trackPromise.then((teamToken) => { trackPromise.then((teamToken) => {
this.props.onLoggedIn({ return this.props.onLoggedIn({
userId: response.user_id, userId: response.user_id,
deviceId: response.device_id, deviceId: response.device_id,
homeserverUrl: this._matrixClient.getHomeserverUrl(), homeserverUrl: this._matrixClient.getHomeserverUrl(),
identityServerUrl: this._matrixClient.getIdentityServerUrl(), identityServerUrl: this._matrixClient.getIdentityServerUrl(),
accessToken: response.access_token accessToken: response.access_token
}, teamToken); }, teamToken);
}).then(() => { }).then((cli) => {
return this._setupPushers(); return this._setupPushers(cli);
}); });
}, },
_setupPushers: function() { _setupPushers: function(matrixClient) {
if (!this.props.brand) { if (!this.props.brand) {
return q(); return q();
} }
return MatrixClientPeg.get().getPushers().then((resp)=>{ return matrixClient.getPushers().then((resp)=>{
const pushers = resp.pushers; const pushers = resp.pushers;
for (let i = 0; i < pushers.length; ++i) { for (let i = 0; i < pushers.length; ++i) {
if (pushers[i].kind == 'email') { if (pushers[i].kind == 'email') {
const emailPusher = pushers[i]; const emailPusher = pushers[i];
emailPusher.data = { brand: this.props.brand }; emailPusher.data = { brand: this.props.brand };
MatrixClientPeg.get().setPusher(emailPusher).done(() => { matrixClient.setPusher(emailPusher).done(() => {
console.log("Set email branding to " + this.props.brand); console.log("Set email branding to " + this.props.brand);
}, (error) => { }, (error) => {
console.error("Couldn't set email branding: " + error); console.error("Couldn't set email branding: " + error);