From 8cbddfcf28891ece5a6fbdd8c7c7a93f7f2a49c0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 29 Sep 2016 17:23:07 +0100 Subject: [PATCH 1/5] Fix version going blank after logging in Don't use replaceState in MatrixClient: there's lots of stuff in MatrixClient's state now (including the app version) so replacing the entire state doesn't really make sense (and also blows away all of the nice defaults we set in getInitialState). Instead, setState of the things we actually care about wherever we used replaceState. Also add a couple of state variables to getInitialState that were missing. Fixes https://github.com/vector-im/vector-web/issues/2322 --- src/components/structures/MatrixChat.js | 42 +++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 47d316e966..d9e4dc9c30 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -105,6 +105,9 @@ module.exports = React.createClass({ version: null, newVersion: null, + + upgradeUsername: null, + guestAccessToken: null, }; return s; }, @@ -261,13 +264,20 @@ module.exports = React.createClass({ newState.register_is_url = payload.params.is_url; newState.register_id_sid = payload.params.sid; } - this.replaceState(newState); + this.setState(newState); this.notifyNewScreen('register'); break; case 'start_login': if (this.state.logged_in) return; - this.replaceState({ + this.setState({ screen: 'login', + currentRoomAlias: null, + currentRoomId: null, + viewUserId: null, + logged_in: false, + ready: false, + upgradeUsername: null, + guestAccessToken: null, }); this.notifyNewScreen('login'); break; @@ -279,8 +289,13 @@ module.exports = React.createClass({ case 'start_upgrade_registration': // stash our guest creds so we can backout if needed this.guestCreds = MatrixClientPeg.getCredentials(); - this.replaceState({ + this.setState({ screen: "register", + currentRoomAlias: null, + currentRoomId: null, + viewUserId: null, + logged_in: false, + ready: false, upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(), guestAccessToken: MatrixClientPeg.get().getAccessToken(), }); @@ -288,8 +303,15 @@ module.exports = React.createClass({ break; case 'start_password_recovery': if (this.state.logged_in) return; - this.replaceState({ - screen: 'forgot_password' + this.setState({ + screen: 'forgot_password', + currentRoomAlias: null, + currentRoomId: null, + viewUserId: null, + logged_in: false, + ready: false, + upgradeUsername: null, + guestAccessToken: null, }); this.notifyNewScreen('forgot_password'); break; @@ -595,9 +617,17 @@ module.exports = React.createClass({ */ _onLoggedOut: function() { this.notifyNewScreen('login'); - this.replaceState({ + this.setState({ + screen: undefined, + currentRoomAlias: null, + currentRoomId: null, + viewUserId: null, logged_in: false, ready: false, + upgradeUsername: null, + guestAccessToken: null, + collapse_lhs: false, + collapse_rhs: false, }); }, From 2f7366cb8a133c787c17a37e9df9246581cc8556 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 30 Sep 2016 11:37:50 +0100 Subject: [PATCH 2/5] Comment state fields --- src/components/structures/MatrixChat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index d9e4dc9c30..a303e1ce90 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -106,7 +106,9 @@ module.exports = React.createClass({ version: null, newVersion: null, + // The username to default to when upgrading an account from a guest upgradeUsername: null, + // The access token we had for our guest account, used when upgrading to a normal account guestAccessToken: null, }; return s; From c41a8da4bedd3fba20320f6bcd2c8e50ab3f152a Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 30 Sep 2016 11:40:27 +0100 Subject: [PATCH 3/5] Argh, there's more --- src/components/structures/MatrixChat.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index a303e1ce90..0cf483f223 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -110,6 +110,13 @@ module.exports = React.createClass({ upgradeUsername: null, // The access token we had for our guest account, used when upgrading to a normal account guestAccessToken: null, + + // Parameters used in the registration dance with the IS + register_client_secret: null, + register_session_id: null, + register_hs_url: null, + register_is_url: null, + register_id_sid: null, }; return s; }, From 8aeb0cfb68606c9cb40b8a028869e03ea38e4195 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 30 Sep 2016 11:56:32 +0100 Subject: [PATCH 4/5] Dedicated function for resetting screen state --- src/components/structures/MatrixChat.js | 50 ++++++++++--------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 0cf483f223..ee99fd2b91 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -245,6 +245,21 @@ module.exports = React.createClass({ } }, + setStateForNewScreen: function(state) { + const newState = { + screen: undefined, + currentRoomAlias: null, + currentRoomId: null, + viewUserId: null, + logged_in: false, + ready: false, + upgradeUsername: null, + guestAccessToken: null, + }; + newState.update(state); + this.setState(state); + }, + onAction: function(payload) { var roomIndexDelta = 1; @@ -273,20 +288,13 @@ module.exports = React.createClass({ newState.register_is_url = payload.params.is_url; newState.register_id_sid = payload.params.sid; } - this.setState(newState); + this.setStateForNewScreen(newState); this.notifyNewScreen('register'); break; case 'start_login': if (this.state.logged_in) return; - this.setState({ + this.setStateForNewScreen({ screen: 'login', - currentRoomAlias: null, - currentRoomId: null, - viewUserId: null, - logged_in: false, - ready: false, - upgradeUsername: null, - guestAccessToken: null, }); this.notifyNewScreen('login'); break; @@ -298,13 +306,8 @@ module.exports = React.createClass({ case 'start_upgrade_registration': // stash our guest creds so we can backout if needed this.guestCreds = MatrixClientPeg.getCredentials(); - this.setState({ + this.setStateForNewScreen({ screen: "register", - currentRoomAlias: null, - currentRoomId: null, - viewUserId: null, - logged_in: false, - ready: false, upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(), guestAccessToken: MatrixClientPeg.get().getAccessToken(), }); @@ -312,15 +315,8 @@ module.exports = React.createClass({ break; case 'start_password_recovery': if (this.state.logged_in) return; - this.setState({ + this.setStateForNewScreen({ screen: 'forgot_password', - currentRoomAlias: null, - currentRoomId: null, - viewUserId: null, - logged_in: false, - ready: false, - upgradeUsername: null, - guestAccessToken: null, }); this.notifyNewScreen('forgot_password'); break; @@ -626,15 +622,9 @@ module.exports = React.createClass({ */ _onLoggedOut: function() { this.notifyNewScreen('login'); - this.setState({ - screen: undefined, - currentRoomAlias: null, - currentRoomId: null, - viewUserId: null, + this.setStateForNewScreen({ logged_in: false, ready: false, - upgradeUsername: null, - guestAccessToken: null, collapse_lhs: false, collapse_rhs: false, }); From be99f17ee0f9db603646244862d0603e721f9da7 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 30 Sep 2016 14:05:01 +0100 Subject: [PATCH 5/5] Oops, right variable --- src/components/structures/MatrixChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index ee99fd2b91..61ca72ad60 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -257,7 +257,7 @@ module.exports = React.createClass({ guestAccessToken: null, }; newState.update(state); - this.setState(state); + this.setState(newState); }, onAction: function(payload) {