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.pull/21833/head
parent
d81160d52f
commit
03f4f269ce
|
@ -185,7 +185,6 @@ module.exports = React.createClass({
|
||||||
roomLoading: RoomViewStore.isRoomLoading(),
|
roomLoading: RoomViewStore.isRoomLoading(),
|
||||||
roomLoadError: RoomViewStore.getRoomLoadError(),
|
roomLoadError: RoomViewStore.getRoomLoadError(),
|
||||||
joining: RoomViewStore.isJoining(),
|
joining: RoomViewStore.isJoining(),
|
||||||
joinError: RoomViewStore.getJoinError(),
|
|
||||||
}, () => {
|
}, () => {
|
||||||
this._onHaveRoom();
|
this._onHaveRoom();
|
||||||
this.onRoom(MatrixClientPeg.get().getRoom(this.state.roomId));
|
this.onRoom(MatrixClientPeg.get().getRoom(this.state.roomId));
|
||||||
|
|
|
@ -16,6 +16,9 @@ limitations under the License.
|
||||||
import dis from '../dispatcher';
|
import dis from '../dispatcher';
|
||||||
import {Store} from 'flux/utils';
|
import {Store} from 'flux/utils';
|
||||||
import MatrixClientPeg from '../MatrixClientPeg';
|
import MatrixClientPeg from '../MatrixClientPeg';
|
||||||
|
import sdk from '../index';
|
||||||
|
import Modal from '../Modal';
|
||||||
|
import { _t } from '../languageHandler';
|
||||||
|
|
||||||
const INITIAL_STATE = {
|
const INITIAL_STATE = {
|
||||||
// Whether we're joining the currently viewed room
|
// Whether we're joining the currently viewed room
|
||||||
|
@ -76,6 +79,12 @@ class RoomViewStore extends Store {
|
||||||
case 'join_room':
|
case 'join_room':
|
||||||
this._joinRoom(payload);
|
this._joinRoom(payload);
|
||||||
break;
|
break;
|
||||||
|
case 'joined_room':
|
||||||
|
this._joinedRoom(payload);
|
||||||
|
break;
|
||||||
|
case 'join_room_error':
|
||||||
|
this._joinRoomError(payload);
|
||||||
|
break;
|
||||||
case 'on_logged_out':
|
case 'on_logged_out':
|
||||||
this.reset();
|
this.reset();
|
||||||
break;
|
break;
|
||||||
|
@ -128,19 +137,43 @@ class RoomViewStore extends Store {
|
||||||
this._setState({
|
this._setState({
|
||||||
joining: true,
|
joining: true,
|
||||||
});
|
});
|
||||||
MatrixClientPeg.get().joinRoom(this._state.roomId, payload.opts).then(
|
MatrixClientPeg.get().joinRoom(this._state.roomId, payload.opts).done(() => {
|
||||||
() => {
|
dis.dispatch({
|
||||||
this._setState({
|
action: 'joined_room',
|
||||||
joining: false,
|
room_id: this._state.roomId,
|
||||||
});
|
});
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
this._setState({
|
dis.dispatch({
|
||||||
joining: false,
|
action: 'join_room_error',
|
||||||
joinError: err,
|
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() {
|
reset() {
|
||||||
this._state = Object.assign({}, INITIAL_STATE);
|
this._state = Object.assign({}, INITIAL_STATE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue