cram OpenRoomsStore between RoomViewStore and dispatcher
the idea is that it will keep a RoomViewStore for every room on the screen, and also keep track of which one is the current one. For now, it just replicates the existing functionality of having just 1 room on the screen. Since the RoomViewStore just has access to a local dispatcher and not the global anymore, all dispatching of actions needs to be moved to the OpenRoomsStore, so room alias resolving, event forwarding, ... is moved there.
This commit is contained in:
parent
7bd6bb6eb6
commit
869c81eb90
2 changed files with 174 additions and 37 deletions
|
@ -53,8 +53,8 @@ const INITIAL_STATE = {
|
|||
* with a subset of the js-sdk.
|
||||
* ```
|
||||
*/
|
||||
class RoomViewStore extends Store {
|
||||
constructor() {
|
||||
export class RoomViewStore extends Store {
|
||||
constructor(dis) {
|
||||
super(dis);
|
||||
|
||||
// Initialise state
|
||||
|
@ -85,6 +85,8 @@ class RoomViewStore extends Store {
|
|||
});
|
||||
break;
|
||||
case 'view_room_error':
|
||||
// should not go over dispatcher anymore
|
||||
// but be internal to RoomViewStore
|
||||
this._viewRoomError(payload);
|
||||
break;
|
||||
case 'will_join':
|
||||
|
@ -150,22 +152,11 @@ class RoomViewStore extends Store {
|
|||
// pull the user out of Room Settings
|
||||
isEditingSettings: false,
|
||||
};
|
||||
|
||||
if (this._state.forwardingEvent) {
|
||||
dis.dispatch({
|
||||
action: 'send_event',
|
||||
room_id: newState.roomId,
|
||||
event: this._state.forwardingEvent,
|
||||
});
|
||||
}
|
||||
|
||||
this._setState(newState);
|
||||
|
||||
if (payload.auto_join) {
|
||||
this._joinRoom(payload);
|
||||
}
|
||||
} else if (payload.room_alias) {
|
||||
// Resolve the alias and then do a second dispatch with the room ID acquired
|
||||
this._setState({
|
||||
roomId: null,
|
||||
initialEventId: null,
|
||||
|
@ -175,25 +166,6 @@ class RoomViewStore extends Store {
|
|||
roomLoading: true,
|
||||
roomLoadError: null,
|
||||
});
|
||||
MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias).done(
|
||||
(result) => {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: result.room_id,
|
||||
event_id: payload.event_id,
|
||||
highlighted: payload.highlighted,
|
||||
room_alias: payload.room_alias,
|
||||
auto_join: payload.auto_join,
|
||||
oob_data: payload.oob_data,
|
||||
});
|
||||
}, (err) => {
|
||||
dis.dispatch({
|
||||
action: 'view_room_error',
|
||||
room_id: null,
|
||||
room_alias: payload.room_alias,
|
||||
err: err,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,8 +302,7 @@ class RoomViewStore extends Store {
|
|||
}
|
||||
}
|
||||
|
||||
let singletonRoomViewStore = null;
|
||||
if (!singletonRoomViewStore) {
|
||||
singletonRoomViewStore = new RoomViewStore();
|
||||
}
|
||||
module.exports = singletonRoomViewStore;
|
||||
const MatrixDispatcher = require("../matrix-dispatcher");
|
||||
const blubber = new RoomViewStore(new MatrixDispatcher());
|
||||
|
||||
export default blubber;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue