Fix to show the correct room

This commit is contained in:
Luke Barnard 2017-06-01 18:01:30 +01:00
parent 8192374481
commit 16c4c14a16
2 changed files with 51 additions and 23 deletions

View file

@ -171,7 +171,7 @@ module.exports = React.createClass({
});
// Start listening for RoomViewStore updates
RoomViewStore.addListener(this._onRoomViewStoreUpdate);
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
this._onRoomViewStoreUpdate(true);
},
@ -182,6 +182,8 @@ module.exports = React.createClass({
this.setState({
roomId: RoomViewStore.getRoomId(),
roomAlias: RoomViewStore.getRoomAlias(),
roomLoading: RoomViewStore.isRoomLoading(),
roomLoadError: RoomViewStore.getRoomLoadError(),
joining: RoomViewStore.isJoining(),
joinError: RoomViewStore.getJoinError(),
}, () => {
@ -343,6 +345,11 @@ module.exports = React.createClass({
document.removeEventListener("keydown", this.onKeyDown);
// Remove RoomStore listener
if (this._roomStoreToken) {
this._roomStoreToken.remove();
}
// cancel any pending calls to the rate_limited_funcs
this._updateRoomMembers.cancelPendingCall();

View file

@ -58,6 +58,9 @@ class RoomViewStore extends Store {
case 'view_room':
this._viewRoom(payload);
break;
case 'view_room_error':
this._viewRoomError(payload);
break;
case 'will_join':
this._setState({
joining: true,
@ -80,31 +83,45 @@ class RoomViewStore extends Store {
}
_viewRoom(payload) {
const address = payload.room_alias || payload.room_id;
if (address[0] == '#') {
// Always set the room ID if present
if (payload.room_id) {
this._setState({
roomLoading: true,
});
MatrixClientPeg.get().getRoomIdForAlias(address).then(
(result) => {
this._setState({
roomId: result.room_id,
roomAlias: address,
roomLoading: false,
roomLoadError: null,
});
}, (err) => {
console.error(err);
this._setState({
roomLoading: false,
roomLoadError: err,
});
});
} else {
this._setState({
roomId: address,
roomId: payload.room_id,
});
}
if (payload.room_alias && !payload.room_id) {
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) => {
dis.dispatch({
action: 'view_room_error',
room_id: null,
room_alias: payload.room_alias,
err: err,
});
});
}
}
_viewRoomError(payload) {
this._setState({
roomId: payload.room_id,
roomAlias: payload.room_alias,
roomLoading: false,
roomLoadError: payload.err,
});
}
_joinRoom(payload) {
@ -140,6 +157,10 @@ class RoomViewStore extends Store {
return this._state.roomLoading;
}
getRoomLoadError() {
return this._state.roomLoadError;
}
isJoining() {
return this._state.joining;
}