@@ -138,13 +138,20 @@ module.exports = {
138138 currentRoom : payload . room_id ,
139139 page_type : this . PageTypes . RoomView ,
140140 } ) ;
141- var presentedId = payload . room_id ;
142- var room = MatrixClientPeg . get ( ) . getRoom ( payload . room_id ) ;
143- if ( room ) {
144- var theAlias = MatrixTools . getCanonicalAliasForRoom ( room ) ;
145- if ( theAlias ) presentedId = theAlias ;
141+ if ( this . sdkReady ) {
142+ // if the SDK is not ready yet, remember what room
143+ // we're supposed to be on but don't notify about
144+ // the new screen yet (we won't be showing it yet)
145+ // The normal case where this happens is navigating
146+ // to the room in the URL bar on page load.
147+ var presentedId = payload . room_id ;
148+ var room = MatrixClientPeg . get ( ) . getRoom ( payload . room_id ) ;
149+ if ( room ) {
150+ var theAlias = MatrixTools . getCanonicalAliasForRoom ( room ) ;
151+ if ( theAlias ) presentedId = theAlias ;
152+ }
153+ this . notifyNewScreen ( 'room/' + presentedId ) ;
146154 }
147- this . notifyNewScreen ( 'room/' + presentedId ) ;
148155 break ;
149156 case 'view_prev_room' :
150157 roomIndexDelta = - 1 ;
@@ -200,20 +207,30 @@ module.exports = {
200207 var cli = MatrixClientPeg . get ( ) ;
201208 var self = this ;
202209 cli . on ( 'syncComplete' , function ( ) {
210+ self . sdkReady = true ;
203211 if ( ! self . state . currentRoom ) {
204212 var firstRoom = null ;
205213 if ( cli . getRooms ( ) && cli . getRooms ( ) . length ) {
206214 firstRoom = RoomListSorter . mostRecentActivityFirst (
207215 cli . getRooms ( )
208216 ) [ 0 ] . roomId ;
209217 self . setState ( { ready : true , currentRoom : firstRoom , page_type : self . PageTypes . RoomView } ) ;
210- self . notifyNewScreen ( 'room/' + firstRoom ) ;
211218 } else {
212219 self . setState ( { ready : true , page_type : self . PageTypes . RoomDirectory } ) ;
213220 }
214221 } else {
215222 self . setState ( { ready : true , currentRoom : self . state . currentRoom } ) ;
216223 }
224+
225+ // we notifyNewScreen now because now the room will actually be displayed,
226+ // and (mostly) now we can get the correct alias.
227+ var presentedId = self . state . currentRoom ;
228+ var room = MatrixClientPeg . get ( ) . getRoom ( self . state . currentRoom ) ;
229+ if ( room ) {
230+ var theAlias = MatrixTools . getCanonicalAliasForRoom ( room ) ;
231+ if ( theAlias ) presentedId = theAlias ;
232+ }
233+ self . notifyNewScreen ( 'room/' + presentedId ) ;
217234 dis . dispatch ( { action : 'focus_composer' } ) ;
218235 } ) ;
219236 cli . on ( 'Call.incoming' , function ( call ) {
0 commit comments