Fix RoomView stuck in 'accept invite' state

After accepting a 3pid invite.

Rather than clear the joining flag when the join request completes,
leave it so the RoomView can see that we're expecting the user to
be joined in the various stages that might go through (waiting for
join request, waiting for room object, waiting for 'joined' member
event). The problem in this case was that we had to wait a bit for
the last one, and there was no bit of state to represent it.

This hopefully also makes the logic somewhat simpler.

Fixes https://github.com/vector-im/riot-web/issues/5041
This commit is contained in:
David Baker 2017-09-15 15:07:09 +01:00
parent fd1f9ac124
commit c265ec9571
2 changed files with 32 additions and 35 deletions

View file

@ -21,7 +21,7 @@ import Modal from '../Modal';
import { _t } from '../languageHandler';
const INITIAL_STATE = {
// Whether we're joining the currently viewed room
// Whether we're joining the currently viewed room (see isJoining())
joining: false,
// Any error that has occurred during joining
joinError: null,
@ -90,9 +90,6 @@ class RoomViewStore extends Store {
case 'join_room':
this._joinRoom(payload);
break;
case 'joined_room':
this._joinedRoom(payload);
break;
case 'join_room_error':
this._joinRoomError(payload);
break;
@ -185,9 +182,11 @@ class RoomViewStore extends Store {
MatrixClientPeg.get().joinRoom(
this._state.roomAlias || this._state.roomId, payload.opts,
).done(() => {
dis.dispatch({
action: 'joined_room',
});
// We don't actually need to do anything here: we do *not*
// clear the 'joining' flag because the Room object and/or
// our 'joined' member event may not have come down the sync
// stream yet, and that's the point at which we'd consider
// the user joined to the room.
}, (err) => {
dis.dispatch({
action: 'join_room_error',
@ -202,12 +201,6 @@ class RoomViewStore extends Store {
});
}
_joinedRoom(payload) {
this._setState({
joining: false,
});
}
_joinRoomError(payload) {
this._setState({
joining: false,
@ -249,7 +242,25 @@ class RoomViewStore extends Store {
return this._state.roomLoadError;
}
// Whether we're joining the currently viewed room
// True if we're expecting the user to be joined to the room currently being
// viewed. Note that this is left true after the join request has finished,
// since we should still consider a join to be in progress until the room
// & member events come down the sync.
//
// This flag remains true after the room has been sucessfully joined,
// (this store doesn't listen for the appropriate member events)
// so you should always consider the room to be joined if the user's
// member events says they are joined.
// ie. The correct logic is:
// if (room && myMember.membership == 'joined') {
// // user is joined to the room
// } else {
// if (RoomViewStore.isJoining()) {
// // show spinner
// } else {
// // show join prompt
// }
// }
isJoining() {
return this._state.joining;
}