Handle accountData events from TagOrderStore

This introduces a generic way to register certain events emitted by
the js-sdk as those that should be propagated through as dispatched
actions.

This allows the store to treat the js-sdk as the "Server" in the
Flux data flow model. It also allows for stores to not be aware
specifically of the matrix client if they are only reading from it.
This commit is contained in:
Luke Barnard 2017-12-07 17:10:45 +00:00
parent ee6df105fe
commit 12515441cd
5 changed files with 97 additions and 12 deletions

View file

@ -41,17 +41,14 @@ class TagOrderStore extends Store {
__onDispatch(payload) {
switch (payload.action) {
// Get ordering from account data, once the client has synced
case 'sync_state':
if (payload.prevState === "PREPARED" && payload.state === "SYNCING") {
const accountDataEvent = MatrixClientPeg.get().getAccountData('im.vector.web.tag_ordering');
const orderedTags = accountDataEvent && accountDataEvent.getContent() ?
accountDataEvent.getContent().tags : null;
this._setState({orderedTags});
}
break;
// Get ordering from account data
case 'MatrixActions.accountData': {
if (payload.event_type !== 'im.vector.web.tag_ordering') break;
this._setState({
orderedTags: payload.event_content ? payload.event_content.tags : null,
});
break;
}
// Initialise the state such that if account data is unset, default to joined groups
case 'GroupActions.fetchJoinedGroups.success':
this._setState({