diff --git a/src/client.js b/src/client.js index 40c491158..b9ad51bcb 100644 --- a/src/client.js +++ b/src/client.js @@ -203,6 +203,8 @@ function MatrixClient(opts) { // The pushprocessor caches useful things, so keep one and re-use it this._pushProcessor = new PushProcessor(this); + + this._serverSupportsLazyLoading = null; } utils.inherits(MatrixClient, EventEmitter); utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype); @@ -3055,7 +3057,14 @@ MatrixClient.prototype.startClient = async function(opts) { opts = Object.assign({}, opts); if (opts.lazyLoadMembers) { - opts.filter = await this.createFilter(LAZY_LOADING_SYNC_FILTER); + const supported = await this.doesServerSupportLazyLoading(); + if (supported) { + 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; @@ -3093,6 +3102,28 @@ MatrixClient.prototype.stopClient = function() { global.clearTimeout(this._checkTurnServersTimeoutID); }; +/* + * Query the server to see if it support members lazy loading + * @return {Promise} 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. * It is called with a room ID and returns a boolean. It should return 'true' if the SDK