Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c265ec9

Browse files
committed
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 element-hq/element-web#5041
1 parent fd1f9ac commit c265ec9

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

src/components/structures/RoomView.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ module.exports = React.createClass({
123123
// store the error here.
124124
roomLoadError: null,
125125

126+
// Have we sent a request to join the room that we're waiting to complete?
127+
joining: false,
128+
126129
// this is true if we are fully scrolled-down, and are looking at
127130
// the end of the live timeline. It has the effect of hiding the
128131
// 'scroll to bottom' knob, among a couple of other things.
@@ -185,10 +188,6 @@ module.exports = React.createClass({
185188
shouldPeek: RoomViewStore.shouldPeek(),
186189
};
187190

188-
// finished joining, start waiting for a room and show a spinner. See onRoom.
189-
newState.waitingForRoom = this.state.joining && !newState.joining &&
190-
!RoomViewStore.getJoinError();
191-
192191
// Temporary logging to diagnose https://github.com/vector-im/riot-web/issues/4307
193192
console.log(
194193
'RVS update:',
@@ -197,7 +196,6 @@ module.exports = React.createClass({
197196
'loading?', newState.roomLoading,
198197
'joining?', newState.joining,
199198
'initial?', initial,
200-
'waiting?', newState.waitingForRoom,
201199
'shouldPeek?', newState.shouldPeek,
202200
);
203201

@@ -650,7 +648,6 @@ module.exports = React.createClass({
650648
}
651649
this.setState({
652650
room: room,
653-
waitingForRoom: false,
654651
}, () => {
655652
this._onRoomLoaded(room);
656653
});
@@ -706,14 +703,7 @@ module.exports = React.createClass({
706703

707704
onRoomMemberMembership: function(ev, member, oldMembership) {
708705
if (member.userId == MatrixClientPeg.get().credentials.userId) {
709-
710-
if (member.membership === 'join') {
711-
this.setState({
712-
waitingForRoom: false,
713-
});
714-
} else {
715-
this.forceUpdate();
716-
}
706+
this.forceUpdate();
717707
}
718708
},
719709

@@ -1463,10 +1453,6 @@ module.exports = React.createClass({
14631453
const Loader = sdk.getComponent("elements.Spinner");
14641454
const TimelinePanel = sdk.getComponent("structures.TimelinePanel");
14651455

1466-
// Whether the preview bar spinner should be shown. We do this when joining or
1467-
// when waiting for a room to be returned by js-sdk when joining
1468-
const previewBarSpinner = this.state.joining || this.state.waitingForRoom;
1469-
14701456
if (!this.state.room) {
14711457
if (this.state.roomLoading || this.state.peekLoading) {
14721458
return (
@@ -1500,7 +1486,7 @@ module.exports = React.createClass({
15001486
onRejectClick={ this.onRejectThreepidInviteButtonClicked }
15011487
canPreview={ false } error={ this.state.roomLoadError }
15021488
roomAlias={roomAlias}
1503-
spinner={previewBarSpinner}
1489+
spinner={this.state.joining}
15041490
inviterName={inviterName}
15051491
invitedEmail={invitedEmail}
15061492
room={this.state.room}
@@ -1543,7 +1529,7 @@ module.exports = React.createClass({
15431529
onRejectClick={ this.onRejectButtonClicked }
15441530
inviterName={ inviterName }
15451531
canPreview={ false }
1546-
spinner={previewBarSpinner}
1532+
spinner={this.state.joining}
15471533
room={this.state.room}
15481534
/>
15491535
</div>
@@ -1618,7 +1604,7 @@ module.exports = React.createClass({
16181604
<RoomPreviewBar onJoinClick={this.onJoinButtonClicked}
16191605
onForgetClick={ this.onForgetClick }
16201606
onRejectClick={this.onRejectThreepidInviteButtonClicked}
1621-
spinner={previewBarSpinner}
1607+
spinner={this.state.joining}
16221608
inviterName={inviterName}
16231609
invitedEmail={invitedEmail}
16241610
canPreview={this.state.canPeek}

src/stores/RoomViewStore.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Modal from '../Modal';
2121
import { _t } from '../languageHandler';
2222

2323
const INITIAL_STATE = {
24-
// Whether we're joining the currently viewed room
24+
// Whether we're joining the currently viewed room (see isJoining())
2525
joining: false,
2626
// Any error that has occurred during joining
2727
joinError: null,
@@ -90,9 +90,6 @@ class RoomViewStore extends Store {
9090
case 'join_room':
9191
this._joinRoom(payload);
9292
break;
93-
case 'joined_room':
94-
this._joinedRoom(payload);
95-
break;
9693
case 'join_room_error':
9794
this._joinRoomError(payload);
9895
break;
@@ -185,9 +182,11 @@ class RoomViewStore extends Store {
185182
MatrixClientPeg.get().joinRoom(
186183
this._state.roomAlias || this._state.roomId, payload.opts,
187184
).done(() => {
188-
dis.dispatch({
189-
action: 'joined_room',
190-
});
185+
// We don't actually need to do anything here: we do *not*
186+
// clear the 'joining' flag because the Room object and/or
187+
// our 'joined' member event may not have come down the sync
188+
// stream yet, and that's the point at which we'd consider
189+
// the user joined to the room.
191190
}, (err) => {
192191
dis.dispatch({
193192
action: 'join_room_error',
@@ -202,12 +201,6 @@ class RoomViewStore extends Store {
202201
});
203202
}
204203

205-
_joinedRoom(payload) {
206-
this._setState({
207-
joining: false,
208-
});
209-
}
210-
211204
_joinRoomError(payload) {
212205
this._setState({
213206
joining: false,
@@ -249,7 +242,25 @@ class RoomViewStore extends Store {
249242
return this._state.roomLoadError;
250243
}
251244

252-
// Whether we're joining the currently viewed room
245+
// True if we're expecting the user to be joined to the room currently being
246+
// viewed. Note that this is left true after the join request has finished,
247+
// since we should still consider a join to be in progress until the room
248+
// & member events come down the sync.
249+
//
250+
// This flag remains true after the room has been sucessfully joined,
251+
// (this store doesn't listen for the appropriate member events)
252+
// so you should always consider the room to be joined if the user's
253+
// member events says they are joined.
254+
// ie. The correct logic is:
255+
// if (room && myMember.membership == 'joined') {
256+
// // user is joined to the room
257+
// } else {
258+
// if (RoomViewStore.isJoining()) {
259+
// // show spinner
260+
// } else {
261+
// // show join prompt
262+
// }
263+
// }
253264
isJoining() {
254265
return this._state.joining;
255266
}

0 commit comments

Comments
 (0)