You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
move getOrCreateClient from sync.js to client.js
This commit is contained in:
@@ -2277,6 +2277,54 @@ MatrixClient.prototype.getFilter = function(userId, filterId, allowCached) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} filterName
|
||||||
|
* @param {Filter} filter
|
||||||
|
* @return {Promise<String>} Filter ID
|
||||||
|
*/
|
||||||
|
MatrixClient.prototype.getOrCreateFilter = function(filterName, filter) {
|
||||||
|
|
||||||
|
var filterId = this.store.getFilterIdByName(filterName);
|
||||||
|
var promise = q();
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (filterId) {
|
||||||
|
// check that the existing filter matches our expectations
|
||||||
|
promise = self.getFilter(self.credentials.userId,
|
||||||
|
filterId, true
|
||||||
|
).then(function(existingFilter) {
|
||||||
|
var oldDef = existingFilter.getDefinition();
|
||||||
|
var newDef = filter.getDefinition();
|
||||||
|
|
||||||
|
if (utils.deepCompare(oldDef, newDef)) {
|
||||||
|
// super, just use that.
|
||||||
|
// debuglog("Using existing filter ID %s: %s", filterId,
|
||||||
|
// JSON.stringify(oldDef));
|
||||||
|
return q(filterId);
|
||||||
|
}
|
||||||
|
// debuglog("Existing filter ID %s: %s; new filter: %s",
|
||||||
|
// filterId, JSON.stringify(oldDef), JSON.stringify(newDef));
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then(function(existingId) {
|
||||||
|
if (existingId) {
|
||||||
|
return existingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a new filter
|
||||||
|
return self.createFilter(filter.getDefinition()
|
||||||
|
).then(function(createdFilter) {
|
||||||
|
// debuglog("Created new filter ID %s: %s", createdFilter.filterId,
|
||||||
|
// JSON.stringify(createdFilter.getDefinition()));
|
||||||
|
self.store.setFilterIdByName(filterName, createdFilter.filterId);
|
||||||
|
return createdFilter.filterId;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a bearer token from the Home Server that the user can
|
* Gets a bearer token from the Home Server that the user can
|
||||||
* present to a third party in order to prove their ownership
|
* present to a third party in order to prove their ownership
|
||||||
|
|||||||
51
lib/sync.js
51
lib/sync.js
@@ -148,7 +148,7 @@ SyncApi.prototype.syncLeftRooms = function() {
|
|||||||
timeout: 0 // don't want to block since this is a single isolated req
|
timeout: 0 // don't want to block since this is a single isolated req
|
||||||
};
|
};
|
||||||
|
|
||||||
return this._getOrCreateFilter(
|
return client.getOrCreateFilter(
|
||||||
getFilterName(client.credentials.userId, "LEFT_ROOMS"), filter
|
getFilterName(client.credentials.userId, "LEFT_ROOMS"), filter
|
||||||
).then(function(filterId) {
|
).then(function(filterId) {
|
||||||
qps.filter = filterId;
|
qps.filter = filterId;
|
||||||
@@ -389,7 +389,7 @@ SyncApi.prototype.sync = function() {
|
|||||||
var filter = new Filter(client.credentials.userId);
|
var filter = new Filter(client.credentials.userId);
|
||||||
filter.setTimelineLimit(self.opts.initialSyncLimit);
|
filter.setTimelineLimit(self.opts.initialSyncLimit);
|
||||||
|
|
||||||
self._getOrCreateFilter(
|
client.getOrCreateFilter(
|
||||||
getFilterName(client.credentials.userId), filter
|
getFilterName(client.credentials.userId), filter
|
||||||
).done(function(filterId) {
|
).done(function(filterId) {
|
||||||
self._sync({ filterId: filterId });
|
self._sync({ filterId: filterId });
|
||||||
@@ -837,53 +837,6 @@ SyncApi.prototype._pokeKeepAlive = function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} filterName
|
|
||||||
* @param {Filter} filter
|
|
||||||
* @return {Promise<String>} Filter ID
|
|
||||||
*/
|
|
||||||
SyncApi.prototype._getOrCreateFilter = function(filterName, filter) {
|
|
||||||
var client = this.client;
|
|
||||||
|
|
||||||
var filterId = client.store.getFilterIdByName(filterName);
|
|
||||||
var promise = q();
|
|
||||||
|
|
||||||
if (filterId) {
|
|
||||||
// check that the existing filter matches our expectations
|
|
||||||
promise = client.getFilter(client.credentials.userId,
|
|
||||||
filterId, true
|
|
||||||
).then(function(existingFilter) {
|
|
||||||
var oldDef = existingFilter.getDefinition();
|
|
||||||
var newDef = filter.getDefinition();
|
|
||||||
|
|
||||||
if (utils.deepCompare(oldDef, newDef)) {
|
|
||||||
// super, just use that.
|
|
||||||
debuglog("Using existing filter ID %s: %s", filterId,
|
|
||||||
JSON.stringify(oldDef));
|
|
||||||
return q(filterId);
|
|
||||||
}
|
|
||||||
debuglog("Existing filter ID %s: %s; new filter: %s",
|
|
||||||
filterId, JSON.stringify(oldDef), JSON.stringify(newDef));
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise.then(function(existingId) {
|
|
||||||
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);
|
|
||||||
return createdFilter.filterId;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} obj
|
* @param {Object} obj
|
||||||
* @return {Object[]}
|
* @return {Object[]}
|
||||||
|
|||||||
Reference in New Issue
Block a user