You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Check filters before we reuse them
Make sure that we check the content of existing filters before we blindly reuse them. Fixes https://github.com/vector-im/vector-web/issues/988
This commit is contained in:
31
lib/sync.js
31
lib/sync.js
@@ -338,7 +338,6 @@ SyncApi.prototype.sync = function() {
|
|||||||
self._getOrCreateFilter(
|
self._getOrCreateFilter(
|
||||||
getFilterName(client.credentials.userId), filter
|
getFilterName(client.credentials.userId), filter
|
||||||
).done(function(filterId) {
|
).done(function(filterId) {
|
||||||
debuglog("Using existing filter ID %s", filterId);
|
|
||||||
self._sync({ filterId: filterId });
|
self._sync({ filterId: filterId });
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
self._startKeepAlives().done(function() {
|
self._startKeepAlives().done(function() {
|
||||||
@@ -702,17 +701,43 @@ SyncApi.prototype._pokeKeepAlive = function() {
|
|||||||
*/
|
*/
|
||||||
SyncApi.prototype._getOrCreateFilter = function(filterName, filter) {
|
SyncApi.prototype._getOrCreateFilter = function(filterName, filter) {
|
||||||
var client = this.client;
|
var client = this.client;
|
||||||
|
|
||||||
var filterId = client.store.getFilterIdByName(filterName);
|
var filterId = client.store.getFilterIdByName(filterName);
|
||||||
|
var promise = q();
|
||||||
|
|
||||||
if (filterId) {
|
if (filterId) {
|
||||||
|
// check that the existing filter matches our expectations
|
||||||
|
promise = client.getFilter(client.credentials.userId,
|
||||||
|
filterId, true
|
||||||
|
).then(function(existingFilter) {
|
||||||
|
var oldStr = JSON.stringify(existingFilter.getDefinition());
|
||||||
|
var newStr = JSON.stringify(filter.getDefinition());
|
||||||
|
|
||||||
|
if ( oldStr == newStr ) {
|
||||||
// super, just use that.
|
// super, just use that.
|
||||||
|
debuglog("Using existing filter ID %s: %s", filterId, oldStr);
|
||||||
return q(filterId);
|
return q(filterId);
|
||||||
}
|
}
|
||||||
|
debuglog("Existing filter ID %s: %s; new filter: %s",
|
||||||
|
filterId, oldStr, newStr);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// create a filter
|
return promise.then(function(existingId) {
|
||||||
return client.createFilter(filter.getDefinition()).then(function(createdFilter) {
|
if (existingId) {
|
||||||
|
return existingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a new filter
|
||||||
|
return client.createFilter(filter.getDefinition()
|
||||||
|
).then(function(createdFilter) {
|
||||||
|
debuglog("Created new filter ID %s: %s", createdFilter.filterId,
|
||||||
|
JSON.stringify(createdFilter.getDefinition()));
|
||||||
client.store.setFilterIdByName(filterName, createdFilter.filterId);
|
client.store.setFilterIdByName(filterName, createdFilter.filterId);
|
||||||
return createdFilter.filterId;
|
return createdFilter.filterId;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user