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 with server if it supports member lazy loading
This commit is contained in:
@@ -203,6 +203,8 @@ function MatrixClient(opts) {
|
|||||||
|
|
||||||
// The pushprocessor caches useful things, so keep one and re-use it
|
// The pushprocessor caches useful things, so keep one and re-use it
|
||||||
this._pushProcessor = new PushProcessor(this);
|
this._pushProcessor = new PushProcessor(this);
|
||||||
|
|
||||||
|
this._serverSupportsLazyLoading = null;
|
||||||
}
|
}
|
||||||
utils.inherits(MatrixClient, EventEmitter);
|
utils.inherits(MatrixClient, EventEmitter);
|
||||||
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
|
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
|
||||||
@@ -3055,7 +3057,14 @@ MatrixClient.prototype.startClient = async function(opts) {
|
|||||||
opts = Object.assign({}, opts);
|
opts = Object.assign({}, opts);
|
||||||
|
|
||||||
if (opts.lazyLoadMembers) {
|
if (opts.lazyLoadMembers) {
|
||||||
|
const supported = await this.doesServerSupportLazyLoading();
|
||||||
|
if (supported) {
|
||||||
opts.filter = await this.createFilter(LAZY_LOADING_SYNC_FILTER);
|
opts.filter = await this.createFilter(LAZY_LOADING_SYNC_FILTER);
|
||||||
|
} else {
|
||||||
|
console.log("LL: lazy loading requested but not supported " +
|
||||||
|
"by server, so disabling");
|
||||||
|
opts.lazyLoadMembers = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.crypto = this._crypto;
|
opts.crypto = this._crypto;
|
||||||
@@ -3093,6 +3102,28 @@ MatrixClient.prototype.stopClient = function() {
|
|||||||
global.clearTimeout(this._checkTurnServersTimeoutID);
|
global.clearTimeout(this._checkTurnServersTimeoutID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Query the server to see if it support members lazy loading
|
||||||
|
* @return {Promise<boolean>} true if server supports lazy loading
|
||||||
|
*/
|
||||||
|
MatrixClient.prototype.doesServerSupportLazyLoading = async function() {
|
||||||
|
if (this._serverSupportsLazyLoading === null) {
|
||||||
|
const response = await this._http.request(
|
||||||
|
undefined, // callback
|
||||||
|
"GET", "/_matrix/client/versions",
|
||||||
|
undefined, // queryParams
|
||||||
|
undefined, // data
|
||||||
|
{
|
||||||
|
prefix: '',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const unstableFeatures = response["unstable_features"];
|
||||||
|
this._serverSupportsLazyLoading =
|
||||||
|
unstableFeatures && unstableFeatures["m.lazy_load_members"];
|
||||||
|
}
|
||||||
|
return this._serverSupportsLazyLoading;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a function which is called when /sync returns a 'limited' response.
|
* Set a function which is called when /sync returns a 'limited' response.
|
||||||
* It is called with a room ID and returns a boolean. It should return 'true' if the SDK
|
* It is called with a room ID and returns a boolean. It should return 'true' if the SDK
|
||||||
|
|||||||
Reference in New Issue
Block a user