Skip to content

Commit

Permalink
Merge pull request #1018 from matrix-org/dbkr/getversions
Browse files Browse the repository at this point in the history
Add getIdServer() & doesServerRequireIdServerParam()
  • Loading branch information
dbkr committed Aug 19, 2019
2 parents 081ff4d + 3c69b85 commit 898fa0e
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ function MatrixClient(opts) {
// The pushprocessor caches useful things, so keep one and re-use it
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 }

Expand Down Expand Up @@ -4041,12 +4043,13 @@ MatrixClient.prototype.stopClient = function() {
};

/*
* Query the server to see if it support members lazy loading
* @return {Promise<boolean>} true if server supports lazy loading
* Get the API versions supported by the server, along with any
* unstable APIs it supports
* @return {Promise<object>} The server /versions response
*/
MatrixClient.prototype.doesServerSupportLazyLoading = async function() {
if (this._serverSupportsLazyLoading === null) {
const response = await this._http.request(
MatrixClient.prototype.getVersions = async function() {
if (this._serverVersionsCache === null) {
this._serverVersionsCache = await this._http.request(
undefined, // callback
"GET", "/_matrix/client/versions",
undefined, // queryParams
Expand All @@ -4055,15 +4058,38 @@ MatrixClient.prototype.doesServerSupportLazyLoading = async function() {
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 unstableFeatures = response["unstable_features"];
const versions = response["versions"];
const unstableFeatures = response["unstable_features"];

this._serverSupportsLazyLoading =
(versions && versions.includes("r0.5.0"))
|| (unstableFeatures && unstableFeatures["m.lazy_load_members"]);
return (versions && versions.includes("r0.5.0"))
|| (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;
};

/*
Expand Down

0 comments on commit 898fa0e

Please sign in to comment.