You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-11 19:37:30 +03:00
Merge pull request #1018 from matrix-org/dbkr/getversions
Add getIdServer() & doesServerRequireIdServerParam()
This commit is contained in:
@@ -238,7 +238,9 @@ 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;
|
// Cache of the server's /versions response
|
||||||
|
// TODO: This should expire: https://github.com/matrix-org/matrix-js-sdk/issues/1020
|
||||||
|
this._serverVersionsCache = null;
|
||||||
|
|
||||||
this._cachedCapabilities = null; // { capabilities: {}, lastUpdated: timestamp }
|
this._cachedCapabilities = null; // { capabilities: {}, lastUpdated: timestamp }
|
||||||
|
|
||||||
@@ -4041,12 +4043,13 @@ MatrixClient.prototype.stopClient = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Query the server to see if it support members lazy loading
|
* Get the API versions supported by the server, along with any
|
||||||
* @return {Promise<boolean>} true if server supports lazy loading
|
* unstable APIs it supports
|
||||||
|
* @return {Promise<object>} The server /versions response
|
||||||
*/
|
*/
|
||||||
MatrixClient.prototype.doesServerSupportLazyLoading = async function() {
|
MatrixClient.prototype.getVersions = async function() {
|
||||||
if (this._serverSupportsLazyLoading === null) {
|
if (this._serverVersionsCache === null) {
|
||||||
const response = await this._http.request(
|
this._serverVersionsCache = await this._http.request(
|
||||||
undefined, // callback
|
undefined, // callback
|
||||||
"GET", "/_matrix/client/versions",
|
"GET", "/_matrix/client/versions",
|
||||||
undefined, // queryParams
|
undefined, // queryParams
|
||||||
@@ -4055,15 +4058,38 @@ MatrixClient.prototype.doesServerSupportLazyLoading = async function() {
|
|||||||
prefix: '',
|
prefix: '',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return this._serverVersionsCache;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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() {
|
||||||
|
const response = await this.getVersions();
|
||||||
|
|
||||||
const versions = response["versions"];
|
const versions = response["versions"];
|
||||||
const unstableFeatures = response["unstable_features"];
|
const unstableFeatures = response["unstable_features"];
|
||||||
|
|
||||||
this._serverSupportsLazyLoading =
|
return (versions && versions.includes("r0.5.0"))
|
||||||
(versions && versions.includes("r0.5.0"))
|
|
||||||
|| (unstableFeatures && unstableFeatures["m.lazy_load_members"]);
|
|| (unstableFeatures && unstableFeatures["m.lazy_load_members"]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Query the server to see if the `id_server` parameter is required
|
||||||
|
* when registering with an 3pid, adding a 3pid or resetting password.
|
||||||
|
* @return {Promise<boolean>} true if id_server parameter is required
|
||||||
|
*/
|
||||||
|
MatrixClient.prototype.doesServerRequireIdServerParam = async function() {
|
||||||
|
const response = await this.getVersions();
|
||||||
|
|
||||||
|
const unstableFeatures = response["unstable_features"];
|
||||||
|
if (unstableFeatures["m.require_identity_server"] === undefined) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return unstableFeatures["m.require_identity_server"];
|
||||||
}
|
}
|
||||||
return this._serverSupportsLazyLoading;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user