mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 04:21:57 +03:00
Ignore remote echos caused by this client
by sending each tag_ordering with a _storeId and ignoring accout data that has a matching _storeId. This will tend to become out of sync with the server over time if requests continually fail, but subsequent successful requests will rectify any differences.
This commit is contained in:
parent
62caa4f096
commit
2a1f8bd394
2 changed files with 18 additions and 1 deletions
|
@ -42,9 +42,14 @@ TagOrderActions.moveTag = function(matrixClient, tag, destinationIx) {
|
||||||
tags = tags.filter((t) => t !== tag);
|
tags = tags.filter((t) => t !== tag);
|
||||||
tags = [...tags.slice(0, destinationIx), tag, ...tags.slice(destinationIx)];
|
tags = [...tags.slice(0, destinationIx), tag, ...tags.slice(destinationIx)];
|
||||||
|
|
||||||
|
const storeId = TagOrderStore.getStoreId();
|
||||||
|
|
||||||
return asyncAction('TagOrderActions.moveTag', () => {
|
return asyncAction('TagOrderActions.moveTag', () => {
|
||||||
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering');
|
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering');
|
||||||
return matrixClient.setAccountData('im.vector.web.tag_ordering', {tags});
|
return matrixClient.setAccountData(
|
||||||
|
'im.vector.web.tag_ordering',
|
||||||
|
{tags, _storeId: storeId},
|
||||||
|
);
|
||||||
}, () => {
|
}, () => {
|
||||||
// For an optimistic update
|
// For an optimistic update
|
||||||
return {tags};
|
return {tags};
|
||||||
|
|
|
@ -63,6 +63,11 @@ class TagOrderStore extends Store {
|
||||||
// Get ordering from account data
|
// Get ordering from account data
|
||||||
case 'MatrixActions.accountData': {
|
case 'MatrixActions.accountData': {
|
||||||
if (payload.event_type !== 'im.vector.web.tag_ordering') break;
|
if (payload.event_type !== 'im.vector.web.tag_ordering') break;
|
||||||
|
|
||||||
|
// Ignore remote echos caused by this store so as to avoid setting
|
||||||
|
// state back to old state.
|
||||||
|
if (payload.event_content._storeId === this.getStoreId()) break;
|
||||||
|
|
||||||
this._setState({
|
this._setState({
|
||||||
orderedTagsAccountData: payload.event_content ? payload.event_content.tags : null,
|
orderedTagsAccountData: payload.event_content ? payload.event_content.tags : null,
|
||||||
});
|
});
|
||||||
|
@ -176,6 +181,13 @@ class TagOrderStore extends Store {
|
||||||
return this._state.orderedTags;
|
return this._state.orderedTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStoreId() {
|
||||||
|
// Generate a random ID to prevent this store from clobbering its
|
||||||
|
// state with redundant remote echos.
|
||||||
|
if (!this._id) this._id = Math.random().toString(16).slice(2, 10);
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
getSelectedTags() {
|
getSelectedTags() {
|
||||||
return this._state.selectedTags;
|
return this._state.selectedTags;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue