From eb36a2b24219ab87c11b69cbf72eadb73cfe59c5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 12 Aug 2015 17:06:45 +0100 Subject: [PATCH] If we were loaded with a room alias, don't lose that alias when we try to load the corresponding room. --- src/controllers/pages/MatrixChat.js | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index 15dddd000..622e546b3 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -138,13 +138,20 @@ module.exports = { currentRoom: payload.room_id, page_type: this.PageTypes.RoomView, }); - var presentedId = payload.room_id; - var room = MatrixClientPeg.get().getRoom(payload.room_id); - if (room) { - var theAlias = MatrixTools.getCanonicalAliasForRoom(room); - if (theAlias) presentedId = theAlias; + if (this.sdkReady) { + // if the SDK is not ready yet, remember what room + // we're supposed to be on but don't notify about + // the new screen yet (we won't be showing it yet) + // The normal case where this happens is navigating + // to the room in the URL bar on page load. + var presentedId = payload.room_id; + var room = MatrixClientPeg.get().getRoom(payload.room_id); + if (room) { + var theAlias = MatrixTools.getCanonicalAliasForRoom(room); + if (theAlias) presentedId = theAlias; + } + this.notifyNewScreen('room/'+presentedId); } - this.notifyNewScreen('room/'+presentedId); break; case 'view_prev_room': roomIndexDelta = -1; @@ -200,6 +207,7 @@ module.exports = { var cli = MatrixClientPeg.get(); var self = this; cli.on('syncComplete', function() { + self.sdkReady = true; if (!self.state.currentRoom) { var firstRoom = null; if (cli.getRooms() && cli.getRooms().length) { @@ -207,13 +215,22 @@ module.exports = { cli.getRooms() )[0].roomId; self.setState({ready: true, currentRoom: firstRoom, page_type: self.PageTypes.RoomView}); - self.notifyNewScreen('room/'+firstRoom); } else { self.setState({ready: true, page_type: self.PageTypes.RoomDirectory}); } } else { self.setState({ready: true, currentRoom: self.state.currentRoom}); } + + // we notifyNewScreen now because now the room will actually be displayed, + // and (mostly) now we can get the correct alias. + var presentedId = self.state.currentRoom; + var room = MatrixClientPeg.get().getRoom(self.state.currentRoom); + if (room) { + var theAlias = MatrixTools.getCanonicalAliasForRoom(room); + if (theAlias) presentedId = theAlias; + } + self.notifyNewScreen('room/'+presentedId); dis.dispatch({action: 'focus_composer'}); }); cli.on('Call.incoming', function(call) {