1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Use stable API prefix for 3PID APIs when supported

If the server advertises spec version r0.6.0, it must have the 3PID APIs
available under the stable API prefix.

Fixes https://github.com/vector-im/riot-web/issues/11246
This commit is contained in:
J. Ryan Stinnett
2019-11-06 18:02:10 +00:00
parent 35adb75d80
commit 20f5c3ea28
2 changed files with 22 additions and 12 deletions

View File

@@ -1374,12 +1374,12 @@ MatrixBaseApis.prototype.addThreePid = function(creds, bind, callback) {
* @return {module:client.Promise} Resolves: on success * @return {module:client.Promise} Resolves: on success
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
MatrixBaseApis.prototype.addThreePidOnly = function(data) { MatrixBaseApis.prototype.addThreePidOnly = async function(data) {
const path = "/account/3pid/add"; const path = "/account/3pid/add";
const prefix = await this.isVersionSupported("r0.6.0") ?
httpApi.PREFIX_R0 : httpApi.PREFIX_UNSTABLE;
return this._http.authedRequest( return this._http.authedRequest(
undefined, "POST", path, null, data, { undefined, "POST", path, null, data, { prefix },
prefix: httpApi.PREFIX_UNSTABLE,
},
); );
}; };
@@ -1397,12 +1397,12 @@ MatrixBaseApis.prototype.addThreePidOnly = function(data) {
* @return {module:client.Promise} Resolves: on success * @return {module:client.Promise} Resolves: on success
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
MatrixBaseApis.prototype.bindThreePid = function(data) { MatrixBaseApis.prototype.bindThreePid = async function(data) {
const path = "/account/3pid/bind"; const path = "/account/3pid/bind";
const prefix = await this.isVersionSupported("r0.6.0") ?
httpApi.PREFIX_R0 : httpApi.PREFIX_UNSTABLE;
return this._http.authedRequest( return this._http.authedRequest(
undefined, "POST", path, null, data, { undefined, "POST", path, null, data, { prefix },
prefix: httpApi.PREFIX_UNSTABLE,
},
); );
}; };
@@ -1417,17 +1417,17 @@ MatrixBaseApis.prototype.bindThreePid = function(data) {
* @return {module:client.Promise} Resolves: on success * @return {module:client.Promise} Resolves: on success
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
MatrixBaseApis.prototype.unbindThreePid = function(medium, address) { MatrixBaseApis.prototype.unbindThreePid = async function(medium, address) {
const path = "/account/3pid/unbind"; const path = "/account/3pid/unbind";
const data = { const data = {
medium, medium,
address, address,
id_server: this.getIdentityServerUrl(true), id_server: this.getIdentityServerUrl(true),
}; };
const prefix = await this.isVersionSupported("r0.6.0") ?
httpApi.PREFIX_R0 : httpApi.PREFIX_UNSTABLE;
return this._http.authedRequest( return this._http.authedRequest(
undefined, "POST", path, null, data, { undefined, "POST", path, null, data, { prefix },
prefix: httpApi.PREFIX_UNSTABLE,
},
); );
}; };

View File

@@ -4210,6 +4210,16 @@ MatrixClient.prototype.getVersions = async function() {
return this._serverVersionsCache; return this._serverVersionsCache;
}; };
/**
* Check if a particular spec version is supported by the server.
* @param {string} version The spec version (such as "r0.5.0") to check for.
* @return {Promise<bool>} Whether it is supported
*/
MatrixClient.prototype.isVersionSupported = async function(version) {
const { versions } = await this.getVersions();
return versions && versions.includes(version);
};
/** /**
* Query the server to see if it support members lazy loading * Query the server to see if it support members lazy loading
* @return {Promise<boolean>} true if server supports lazy loading * @return {Promise<boolean>} true if server supports lazy loading