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
Merge pull request #1632 from matrix-org/matthew/rework-cross-signing-login
Expose APIs needed for reworked cross-signing login flow
This commit is contained in:
@@ -1518,6 +1518,21 @@ MatrixBaseApis.prototype.getDevices = function() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets specific device details for the logged-in user
|
||||||
|
* @param {string} device_id device to query
|
||||||
|
* @return {Promise} Resolves: result object
|
||||||
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
|
*/
|
||||||
|
MatrixBaseApis.prototype.getDevice = function(device_id) {
|
||||||
|
const path = utils.encodeUri("/devices/$device_id", {
|
||||||
|
$device_id: device_id,
|
||||||
|
});
|
||||||
|
return this._http.authedRequest(
|
||||||
|
undefined, 'GET', path, undefined, undefined,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the given device
|
* Update the given device
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -500,19 +500,8 @@ MatrixClient.prototype.rehydrateDevice = async function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let getDeviceResult;
|
const getDeviceResult = this.getDehydratedDevice();
|
||||||
try {
|
if (!getDeviceResult) {
|
||||||
getDeviceResult = await this._http.authedRequest(
|
|
||||||
undefined,
|
|
||||||
"GET",
|
|
||||||
"/dehydrated_device",
|
|
||||||
undefined, undefined,
|
|
||||||
{
|
|
||||||
prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.info("could not get dehydrated device", e.toString());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,6 +563,27 @@ MatrixClient.prototype.rehydrateDevice = async function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current dehydrated device, if any
|
||||||
|
* @return {Promise} A promise of an object containing the dehydrated device
|
||||||
|
*/
|
||||||
|
MatrixClient.prototype.getDehydratedDevice = async function() {
|
||||||
|
try {
|
||||||
|
return await this._http.authedRequest(
|
||||||
|
undefined,
|
||||||
|
"GET",
|
||||||
|
"/dehydrated_device",
|
||||||
|
undefined, undefined,
|
||||||
|
{
|
||||||
|
prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
logger.info("could not get dehydrated device", e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the dehydration key. This will also periodically dehydrate devices to
|
* Set the dehydration key. This will also periodically dehydrate devices to
|
||||||
* the server.
|
* the server.
|
||||||
|
|||||||
@@ -179,7 +179,9 @@ export class ToDeviceChannel {
|
|||||||
const isAcceptingEvent = type === START_TYPE || type === READY_TYPE;
|
const isAcceptingEvent = type === START_TYPE || type === READY_TYPE;
|
||||||
// the request has picked a ready or start event, tell the other devices about it
|
// the request has picked a ready or start event, tell the other devices about it
|
||||||
if (isAcceptingEvent && !wasStarted && isStarted && this._deviceId) {
|
if (isAcceptingEvent && !wasStarted && isStarted && this._deviceId) {
|
||||||
const nonChosenDevices = this._devices.filter(d => d !== this._deviceId);
|
const nonChosenDevices = this._devices.filter(
|
||||||
|
d => d !== this._deviceId && d !== this._client.getDeviceId(),
|
||||||
|
);
|
||||||
if (nonChosenDevices.length) {
|
if (nonChosenDevices.length) {
|
||||||
const message = this.completeContent({
|
const message = this.completeContent({
|
||||||
code: "m.accepted",
|
code: "m.accepted",
|
||||||
|
|||||||
@@ -271,10 +271,10 @@ MatrixHttpApi.prototype = {
|
|||||||
xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000);
|
xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000);
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
|
let resp;
|
||||||
switch (xhr.readyState) {
|
switch (xhr.readyState) {
|
||||||
case global.XMLHttpRequest.DONE:
|
case global.XMLHttpRequest.DONE:
|
||||||
callbacks.clearTimeout(xhr.timeout_timer);
|
callbacks.clearTimeout(xhr.timeout_timer);
|
||||||
var resp;
|
|
||||||
try {
|
try {
|
||||||
if (xhr.status === 0) {
|
if (xhr.status === 0) {
|
||||||
throw new AbortError();
|
throw new AbortError();
|
||||||
|
|||||||
Reference in New Issue
Block a user