From 97aa0b52fad7a0fdbd63bd183bf4c107545b3834 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 11 Feb 2019 12:12:47 +0000 Subject: [PATCH 1/5] Avoid room directory error without a client --- src/components/structures/RoomDirectory.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 5309b02041..e13eab8eb3 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -78,6 +78,11 @@ module.exports = React.createClass({ this.protocols = null; this.setState({protocolsLoading: true}); + if (!MatrixClientPeg.get()) { + // We may not have a client yet when invoked from welcome page + this.setState({protocolsLoading: false}); + return; + } MatrixClientPeg.get().getThirdpartyProtocols().done((response) => { this.protocols = response; this.setState({protocolsLoading: false}); From 477d5ac0dcc612202fba4b04d10da290c479a468 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 11 Feb 2019 13:31:27 +0000 Subject: [PATCH 2/5] View welcome behind modals when not showing logged in view --- src/components/structures/MatrixChat.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 1453007b18..7c03aaec57 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -574,11 +574,8 @@ export default React.createClass({ const UserSettingsDialog = sdk.getComponent("dialogs.UserSettingsDialog"); Modal.createTrackedDialog('User settings', '', UserSettingsDialog, {}, 'mx_SettingsDialog'); - // View the home page if we need something to look at - if (!this.state.currentGroupId && !this.state.currentRoomId) { - this._setPage(PageTypes.HomePage); - this.notifyNewScreen('home'); - } + // View the welcome or home page if we need something to look at + this._viewSomethingBehindModal(); break; } case 'view_create_room': @@ -595,11 +592,8 @@ export default React.createClass({ config: this.props.config, }, 'mx_RoomDirectory_dialogWrapper'); - // View the home page if we need something to look at - if (!this.state.currentGroupId && !this.state.currentRoomId) { - this._setPage(PageTypes.HomePage); - this.notifyNewScreen('home'); - } + // View the welcome or home page if we need something to look at + this._viewSomethingBehindModal(); } break; case 'view_my_groups': @@ -887,6 +881,16 @@ export default React.createClass({ this.notifyNewScreen('group/' + groupId); }, + _viewSomethingBehindModal() { + if (this.state.view !== VIEWS.LOGGED_IN) { + this._viewWelcome(); + return; + } + if (!this.state.currentGroupId && !this.state.currentRoomId) { + this._viewHome(); + } + }, + _viewWelcome() { this.setStateForNewView({ view: VIEWS.WELCOME, From 4101d4e9de0e4735106930bc7b8a0366901c56fd Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 11 Feb 2019 13:49:18 +0000 Subject: [PATCH 3/5] Always change to LOGGED_IN view to show a room --- src/components/structures/MatrixChat.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 7c03aaec57..4bb4e34033 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -819,6 +819,7 @@ export default React.createClass({ this.focusComposer = true; const newState = { + view: VIEWS.LOGGED_IN, currentRoomId: roomInfo.room_id || null, page_type: PageTypes.RoomView, thirdPartyInvite: roomInfo.third_party_invite, @@ -1556,11 +1557,7 @@ export default React.createClass({ payload.room_id = roomString; } - // we can't view a room unless we're logged in - // (a guest account is fine) - if (this.state.view === VIEWS.LOGGED_IN) { - dis.dispatch(payload); - } + dis.dispatch(payload); } else if (screen.indexOf('user/') == 0) { const userId = screen.substring(5); From 9d3ba2b3d9a9fcc0f8ee1fc222c9da9d26ce3d25 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 11 Feb 2019 14:33:19 +0000 Subject: [PATCH 4/5] Guard against invalid room object on join --- src/components/structures/RoomView.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 50fa18e075..f75393c6db 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -877,13 +877,12 @@ module.exports = React.createClass({ // If the user is a ROU, allow them to transition to a PWLU if (cli && cli.isGuest()) { // Join this room once the user has registered and logged in - const signUrl = this.props.thirdPartyInvite ? - this.props.thirdPartyInvite.inviteSignUrl : undefined; + // (If we failed to peek, we may not have a valid room object.) dis.dispatch({ action: 'do_after_sync_prepared', deferred_action: { action: 'view_room', - room_id: this.state.room.roomId, + room_id: this.state.room ? this.state.room.roomId : this.state.roomId, }, }); From 44e34d9074ccaaf446b89b4b600109d65bb19fef Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 12 Feb 2019 08:59:38 +0000 Subject: [PATCH 5/5] Explain roomId workaround --- src/components/structures/RoomView.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index f75393c6db..b233662898 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -283,6 +283,15 @@ module.exports = React.createClass({ } }, + _getRoomId() { + // According to `_onRoomViewStoreUpdate`, `state.roomId` can be null + // if we have a room alias we haven't resolved yet. To work around this, + // first we'll try the room object if it's there, and then fallback to + // the bare room ID. (We may want to update `state.roomId` after + // resolving aliases, so we could always trust it.) + return this.state.room ? this.state.room.roomId : this.state.roomId; + }, + _onWidgetEchoStoreUpdate: function() { this.setState({ showApps: this._shouldShowApps(this.state.room), @@ -882,7 +891,7 @@ module.exports = React.createClass({ action: 'do_after_sync_prepared', deferred_action: { action: 'view_room', - room_id: this.state.room ? this.state.room.roomId : this.state.roomId, + room_id: this._getRoomId(), }, });