You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Add IS v1 API fallback for lookup
This commit is contained in:
@@ -17,8 +17,6 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { SERVICE_TYPES } from './service-types';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an internal module. MatrixBaseApis is currently only meant to be used
|
* This is an internal module. MatrixBaseApis is currently only meant to be used
|
||||||
* by {@link client~MatrixClient}.
|
* by {@link client~MatrixClient}.
|
||||||
@@ -26,6 +24,9 @@ import { SERVICE_TYPES } from './service-types';
|
|||||||
* @module base-apis
|
* @module base-apis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SERVICE_TYPES } from './service-types';
|
||||||
|
import logger from './logger';
|
||||||
|
|
||||||
const httpApi = require("./http-api");
|
const httpApi = require("./http-api");
|
||||||
const utils = require("./utils");
|
const utils = require("./utils");
|
||||||
|
|
||||||
@@ -1800,7 +1801,7 @@ MatrixBaseApis.prototype.submitMsisdnToken = function(sid, clientSecret, token)
|
|||||||
* exists
|
* exists
|
||||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
*/
|
*/
|
||||||
MatrixBaseApis.prototype.lookupThreePid = function(
|
MatrixBaseApis.prototype.lookupThreePid = async function(
|
||||||
medium,
|
medium,
|
||||||
address,
|
address,
|
||||||
callback,
|
callback,
|
||||||
@@ -1811,11 +1812,26 @@ MatrixBaseApis.prototype.lookupThreePid = function(
|
|||||||
address: address,
|
address: address,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Testing only - add fallback to v1
|
try {
|
||||||
return this._http.idServerRequest(
|
const response = await this._http.idServerRequest(
|
||||||
callback, "GET", "/lookup",
|
undefined, "GET", "/lookup",
|
||||||
params, httpApi.PREFIX_IDENTITY_V2, isAccessToken,
|
params, httpApi.PREFIX_IDENTITY_V2, isAccessToken,
|
||||||
);
|
);
|
||||||
|
// TODO: Fold callback into above call once v1 path below is removed
|
||||||
|
if (callback) callback(null, response);
|
||||||
|
return response;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.cors === "rejected" || err.httpStatus === 404) {
|
||||||
|
// Fall back to deprecated v1 API for now
|
||||||
|
logger.warn("IS doesn't support v2, falling back to deprecated v1");
|
||||||
|
return await this._http.idServerRequest(
|
||||||
|
callback, "GET", "/lookup",
|
||||||
|
params, httpApi.PREFIX_IDENTITY_V1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (callback) callback(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user