Implement a store for RoomView

This allows for a truely flux-y way of storing the currently viewed room, making some callbacks (like onRoomIdResolved) redundant and making sure that the currently viewed room (ID) is only stored in one place as opposed to the previous many places.

This was required for the `join_room` action which can be dispatched to join the currently viewed room.

Another change was to introduce `LifeCycleStore` which is a start at encorporating state related to the lifecycle of the app into a flux store. Currently it only contains an action which will be dispatched when the sync state has become PREPARED. This was necessary to do a deferred dispatch of `join_room` following the registration of a PWLU (PassWord-Less User).

The following actions are introduced:
 - RoomViewStore:
    - `view_room`: dispatch to change the currently viewed room ID
    - `join_room`: dispatch to join the currently viewed room
 - LifecycleStore:
    - `do_after_sync_prepared`: dispatch to store an action which will be dispatched when `sync_state` is dispatched with `state = 'PREPARED'`
 - MatrixChat:
    - `sync_state`: dispatched when the sync state changes. Ideally there'd be a SyncStateStore that emitted an `update` upon receiving this, but for now the `LifecycleStore` will listen for `sync_state` directly.
This commit is contained in:
Luke Barnard 2017-05-24 16:56:13 +01:00
parent b0a824c941
commit 298c5e4df3
11 changed files with 399 additions and 241 deletions

View file

@ -57,6 +57,11 @@ function createRoom(opts) {
createOpts.is_direct = true;
}
// By default, view the room after creating it
if (opts.andView === undefined) {
opts.andView = true;
}
// Allow guests by default since the room is private and they'd
// need an invite. This means clicking on a 3pid invite email can
// actually drop you right in to a chat.
@ -90,10 +95,12 @@ function createRoom(opts) {
// room has been created, so we race here with the client knowing that
// the room exists, causing things like
// https://github.com/vector-im/vector-web/issues/1813
dis.dispatch({
action: 'view_room',
room_id: roomId
});
if (opts.andView) {
dis.dispatch({
action: 'view_room',
room_id: roomId,
});
}
return roomId;
}, function(err) {
console.error("Failed to create room " + roomId + " " + err);