Merge pull request #995 from matrix-org/luke/new-guest-access-fix-wrong-room-shown
Fix to show the correct room
This commit is contained in:
commit
d81160d52f
3 changed files with 55 additions and 24 deletions
|
@ -171,7 +171,7 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start listening for RoomViewStore updates
|
// Start listening for RoomViewStore updates
|
||||||
RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
||||||
this._onRoomViewStoreUpdate(true);
|
this._onRoomViewStoreUpdate(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ module.exports = React.createClass({
|
||||||
this.setState({
|
this.setState({
|
||||||
roomId: RoomViewStore.getRoomId(),
|
roomId: RoomViewStore.getRoomId(),
|
||||||
roomAlias: RoomViewStore.getRoomAlias(),
|
roomAlias: RoomViewStore.getRoomAlias(),
|
||||||
|
roomLoading: RoomViewStore.isRoomLoading(),
|
||||||
|
roomLoadError: RoomViewStore.getRoomLoadError(),
|
||||||
joining: RoomViewStore.isJoining(),
|
joining: RoomViewStore.isJoining(),
|
||||||
joinError: RoomViewStore.getJoinError(),
|
joinError: RoomViewStore.getJoinError(),
|
||||||
}, () => {
|
}, () => {
|
||||||
|
@ -343,6 +345,11 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
document.removeEventListener("keydown", this.onKeyDown);
|
document.removeEventListener("keydown", this.onKeyDown);
|
||||||
|
|
||||||
|
// Remove RoomStore listener
|
||||||
|
if (this._roomStoreToken) {
|
||||||
|
this._roomStoreToken.remove();
|
||||||
|
}
|
||||||
|
|
||||||
// cancel any pending calls to the rate_limited_funcs
|
// cancel any pending calls to the rate_limited_funcs
|
||||||
this._updateRoomMembers.cancelPendingCall();
|
this._updateRoomMembers.cancelPendingCall();
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,9 @@ class RoomViewStore extends Store {
|
||||||
case 'view_room':
|
case 'view_room':
|
||||||
this._viewRoom(payload);
|
this._viewRoom(payload);
|
||||||
break;
|
break;
|
||||||
|
case 'view_room_error':
|
||||||
|
this._viewRoomError(payload);
|
||||||
|
break;
|
||||||
case 'will_join':
|
case 'will_join':
|
||||||
this._setState({
|
this._setState({
|
||||||
joining: true,
|
joining: true,
|
||||||
|
@ -80,33 +83,47 @@ class RoomViewStore extends Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
_viewRoom(payload) {
|
_viewRoom(payload) {
|
||||||
const address = payload.room_alias || payload.room_id;
|
// Always set the room ID if present
|
||||||
if (address[0] == '#') {
|
if (payload.room_id) {
|
||||||
this._setState({
|
this._setState({
|
||||||
roomLoading: true,
|
roomId: payload.room_id,
|
||||||
});
|
|
||||||
MatrixClientPeg.get().getRoomIdForAlias(address).then(
|
|
||||||
(result) => {
|
|
||||||
this._setState({
|
|
||||||
roomId: result.room_id,
|
|
||||||
roomAlias: address,
|
|
||||||
roomLoading: false,
|
roomLoading: false,
|
||||||
roomLoadError: null,
|
roomLoadError: null,
|
||||||
});
|
});
|
||||||
|
} else if (payload.room_alias) {
|
||||||
|
this._setState({
|
||||||
|
roomId: null,
|
||||||
|
roomAlias: payload.room_alias,
|
||||||
|
roomLoading: true,
|
||||||
|
roomLoadError: null,
|
||||||
|
});
|
||||||
|
MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias).done(
|
||||||
|
(result) => {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'view_room',
|
||||||
|
room_id: result.room_id,
|
||||||
|
room_alias: payload.room_alias,
|
||||||
|
});
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.error(err);
|
dis.dispatch({
|
||||||
this._setState({
|
action: 'view_room_error',
|
||||||
roomLoading: false,
|
room_id: null,
|
||||||
roomLoadError: err,
|
room_alias: payload.room_alias,
|
||||||
|
err: err,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this._setState({
|
|
||||||
roomId: address,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_viewRoomError(payload) {
|
||||||
|
this._setState({
|
||||||
|
roomId: payload.room_id,
|
||||||
|
roomAlias: payload.room_alias,
|
||||||
|
roomLoading: false,
|
||||||
|
roomLoadError: payload.err,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_joinRoom(payload) {
|
_joinRoom(payload) {
|
||||||
this._setState({
|
this._setState({
|
||||||
joining: true,
|
joining: true,
|
||||||
|
@ -140,6 +157,10 @@ class RoomViewStore extends Store {
|
||||||
return this._state.roomLoading;
|
return this._state.roomLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRoomLoadError() {
|
||||||
|
return this._state.roomLoadError;
|
||||||
|
}
|
||||||
|
|
||||||
isJoining() {
|
isJoining() {
|
||||||
return this._state.joining;
|
return this._state.joining;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,15 @@ describe('RoomViewStore', function() {
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch({ action: 'view_room', room_alias: '#somealias2:aser.ver' });
|
RoomViewStore.addListener(() => {
|
||||||
|
// Wait until the room alias has resolved and the room ID is
|
||||||
// Wait for the next event loop to allow for room alias resolution
|
if (!RoomViewStore.isRoomLoading()) {
|
||||||
setTimeout(() => {
|
expect(RoomViewStore.getRoomId()).toBe("!randomcharacters:aser.ver");
|
||||||
dispatch({ action: 'join_room' });
|
dispatch({ action: 'join_room' });
|
||||||
expect(RoomViewStore.isJoining()).toBe(true);
|
expect(RoomViewStore.isJoining()).toBe(true);
|
||||||
}, 0);
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({ action: 'view_room', room_alias: '#somealias2:aser.ver' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue