From 03f4f269ce82e4e6959fe3ad6da1475ba84e721e Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 2 Jun 2017 11:53:10 +0100 Subject: [PATCH 1/3] Propagate room join errors to the UI Dispatch so we can set the state in RoomViewStore. Show the error when the room join fails (unsure if it's better to do this from the component or the store). Remove unused joinError from roomview. --- src/components/structures/RoomView.js | 1 - src/stores/RoomViewStore.js | 47 +++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 9a930d3d06..3151fd28f9 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -185,7 +185,6 @@ module.exports = React.createClass({ roomLoading: RoomViewStore.isRoomLoading(), roomLoadError: RoomViewStore.getRoomLoadError(), joining: RoomViewStore.isJoining(), - joinError: RoomViewStore.getJoinError(), }, () => { this._onHaveRoom(); this.onRoom(MatrixClientPeg.get().getRoom(this.state.roomId)); diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index b94e772b02..b0957ec3df 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -16,6 +16,9 @@ limitations under the License. import dis from '../dispatcher'; import {Store} from 'flux/utils'; import MatrixClientPeg from '../MatrixClientPeg'; +import sdk from '../index'; +import Modal from '../Modal'; +import { _t } from '../languageHandler'; const INITIAL_STATE = { // Whether we're joining the currently viewed room @@ -76,6 +79,12 @@ 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; case 'on_logged_out': this.reset(); break; @@ -128,19 +137,43 @@ class RoomViewStore extends Store { this._setState({ joining: true, }); - MatrixClientPeg.get().joinRoom(this._state.roomId, payload.opts).then( - () => { - this._setState({ - joining: false, + MatrixClientPeg.get().joinRoom(this._state.roomId, payload.opts).done(() => { + dis.dispatch({ + action: 'joined_room', + room_id: this._state.roomId, }); }, (err) => { - this._setState({ - joining: false, - joinError: err, + dis.dispatch({ + action: 'join_room_error', + room_id: this._state.roomId, + err: err, + }); + const msg = err.message ? err.message : JSON.stringify(err); + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: _t("Failed to join room"), + description: msg, }); }); } + _joinedRoom(payload) { + if (payload.room_id === this._state.roomId) { + this._setState({ + joining: false, + }); + } + } + + _joinRoomError(payload) { + if (payload.room_id === this._state.roomId) { + this._setState({ + joining: false, + joinError: payload.err, + }); + } + } + reset() { this._state = Object.assign({}, INITIAL_STATE); } From f52035f3cd7aa63db1a3c56ef23af16092dce868 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 2 Jun 2017 13:41:41 +0100 Subject: [PATCH 2/3] Set state from dispatch payload unconditionally As apparently doing it confitionally is bad --- src/stores/RoomViewStore.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index b0957ec3df..6ba0e45f68 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -158,20 +158,16 @@ class RoomViewStore extends Store { } _joinedRoom(payload) { - if (payload.room_id === this._state.roomId) { - this._setState({ - joining: false, - }); - } + this._setState({ + joining: false, + }); } _joinRoomError(payload) { - if (payload.room_id === this._state.roomId) { - this._setState({ - joining: false, - joinError: payload.err, - }); - } + this._setState({ + joining: false, + joinError: payload.err, + }); } reset() { From ac0f2f79d18d6b9e2ec2a98b85f4d9150acc24d6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 2 Jun 2017 16:02:20 +0100 Subject: [PATCH 3/3] Remove redundant room_id --- src/stores/RoomViewStore.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index 6ba0e45f68..cc8959af7a 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -140,12 +140,10 @@ class RoomViewStore extends Store { MatrixClientPeg.get().joinRoom(this._state.roomId, payload.opts).done(() => { dis.dispatch({ action: 'joined_room', - room_id: this._state.roomId, }); }, (err) => { dis.dispatch({ action: 'join_room_error', - room_id: this._state.roomId, err: err, }); const msg = err.message ? err.message : JSON.stringify(err);