@@ -448,6 +448,7 @@ module.exports = React.createClass({
448
448
} ) ;
449
449
} , 0 ) ;
450
450
}
451
+ this . notifyNewScreen ( 'user/' + payload . member . userId ) ;
451
452
break ;
452
453
case 'view_room' :
453
454
// Takes either a room ID or room alias: if switching to a room the client is already
@@ -1203,21 +1204,44 @@ module.exports = React.createClass({
1203
1204
} else if ( screen . indexOf ( 'user/' ) == 0 ) {
1204
1205
const userId = screen . substring ( 5 ) ;
1205
1206
1206
- if ( params . action === 'chat' ) {
1207
- this . _chatCreateOrReuse ( userId ) ;
1208
- return ;
1209
- }
1207
+ // Wait for the first sync so that `getRoom` gives us a room object if it's
1208
+ // in the sync response
1209
+ const waitFor = this . firstSyncPromise ?
1210
+ this . firstSyncPromise . promise : Promise . resolve ( ) ;
1211
+ waitFor . then ( ( ) => {
1212
+ if ( params . action === 'chat' ) {
1213
+ this . _chatCreateOrReuse ( userId ) ;
1214
+ return ;
1215
+ }
1216
+
1217
+ // Get the member object for the current room, if a current room is set or
1218
+ // we have a last_room in localStorage. The user might not be a member of
1219
+ // this room (in which case member will be falsey).
1220
+ let member ;
1221
+ const roomId = this . state . currentRoomId || localStorage . getItem ( 'mx_last_room_id' ) ;
1222
+ if ( roomId ) {
1223
+ const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
1224
+ if ( room ) {
1225
+ member = room . getMember ( userId ) ;
1226
+ }
1227
+ }
1210
1228
1211
- this . setState ( { viewUserId : userId } ) ;
1212
- this . _setPage ( PageTypes . UserView ) ;
1213
- this . notifyNewScreen ( 'user/' + userId ) ;
1214
- const member = new Matrix . RoomMember ( null , userId ) ;
1215
- if ( member ) {
1229
+ if ( member ) {
1230
+ // This user is a member of this room, so view the room
1231
+ dis . dispatch ( {
1232
+ action : 'view_room' ,
1233
+ room_id : roomId ,
1234
+ } ) ;
1235
+ } else {
1236
+ // This user is not a member of this room, show the user view
1237
+ member = new Matrix . RoomMember ( null , userId ) ;
1238
+ this . _setPage ( PageTypes . UserView ) ;
1239
+ }
1216
1240
dis . dispatch ( {
1217
1241
action : 'view_user' ,
1218
1242
member : member ,
1219
1243
} ) ;
1220
- }
1244
+ } ) ;
1221
1245
} else if ( screen . indexOf ( 'group/' ) == 0 ) {
1222
1246
const groupId = screen . substring ( 6 ) ;
1223
1247
0 commit comments