Use AccountData im.vector.web.tag_ordering

Also, make defaults sensible
This commit is contained in:
Luke Barnard 2017-12-06 14:13:08 +00:00
parent 7aa5dcef69
commit 4af7def20e

View file

@ -16,10 +16,11 @@ limitations under the License.
import {Store} from 'flux/utils'; import {Store} from 'flux/utils';
import dis from '../dispatcher'; import dis from '../dispatcher';
// import Analytics from '../Analytics'; // import Analytics from '../Analytics';
import SettingsStore from "../settings/SettingsStore"; import MatrixClientPeg from "../MatrixClientPeg";
const INITIAL_STATE = { const INITIAL_STATE = {
orderedTags: null, orderedTags: null,
allTags: null,
}; };
/** /**
@ -40,23 +41,28 @@ class TagOrderStore extends Store {
__onDispatch(payload) { __onDispatch(payload) {
switch (payload.action) { switch (payload.action) {
case 'sync_state':
// Get ordering from account data, once the client has synced // Get ordering from account data, once the client has synced
case 'sync_state':
if (payload.prevState === "PREPARED" && payload.state === "SYNCING") { if (payload.prevState === "PREPARED" && payload.state === "SYNCING") {
this._setState({ const accountDataEvent = MatrixClientPeg.get().getAccountData('im.vector.web.tag_ordering');
orderedTags: SettingsStore.getValue("TagOrderStore.orderedTags"),
}); const orderedTags = accountDataEvent && accountDataEvent.getContent() ?
accountDataEvent.getContent().tags : null;
this._setState({orderedTags});
} }
break; break;
// Initialise the state such that if account data is unset, default to the existing ordering
case 'all_tags': case 'all_tags':
// Initialise the state with all known tags displayed in the TagPanel this._setState({
this._setState({allTags: payload.tags}); allTags: payload.tags.sort(), // Sort lexically
});
break; break;
case 'order_tag': {
if (!payload.tag || !payload.targetTag || payload.tag === payload.targetTag) break;
// Puts payload.tag at payload.targetTag, placing the targetTag before or after the tag // Puts payload.tag at payload.targetTag, placing the targetTag before or after the tag
const tags = SettingsStore.getValue("TagOrderStore.orderedTags") || this._state.allTags; case 'order_tag': {
if (!payload.tag || !payload.targetTag || payload.tag === payload.targetTag) return;
const tags = this._state.orderedTags || this._state.allTags;
let orderedTags = tags.filter((t) => t !== payload.tag); let orderedTags = tags.filter((t) => t !== payload.tag);
const newIndex = orderedTags.indexOf(payload.targetTag) + (payload.after ? 1 : 0); const newIndex = orderedTags.indexOf(payload.targetTag) + (payload.after ? 1 : 0);
@ -69,13 +75,17 @@ class TagOrderStore extends Store {
} }
break; break;
case 'commit_tags': case 'commit_tags':
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", this._state.orderedTags); MatrixClientPeg.get().setAccountData('im.vector.web.tag_ordering', {tags: this._state.orderedTags});
break; break;
} }
} }
getOrderedTags() { getOrderedTags() {
return this._state.orderedTags || SettingsStore.getValue("TagOrderStore.orderedTags"); return this._state.orderedTags;
}
getAllTags() {
return this._state.allTags;
} }
} }