Skip to content

Commit 0b7b35f

Browse files
authored
Merge pull request #1632 from matrix-org/matthew/rework-cross-signing-login
Expose APIs needed for reworked cross-signing login flow
2 parents 481acb2 + 9fb2fba commit 0b7b35f

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

src/base-apis.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,21 @@ MatrixBaseApis.prototype.getDevices = function() {
15181518
);
15191519
};
15201520

1521+
/**
1522+
* Gets specific device details for the logged-in user
1523+
* @param {string} device_id device to query
1524+
* @return {Promise} Resolves: result object
1525+
* @return {module:http-api.MatrixError} Rejects: with an error response.
1526+
*/
1527+
MatrixBaseApis.prototype.getDevice = function(device_id) {
1528+
const path = utils.encodeUri("/devices/$device_id", {
1529+
$device_id: device_id,
1530+
});
1531+
return this._http.authedRequest(
1532+
undefined, 'GET', path, undefined, undefined,
1533+
);
1534+
};
1535+
15211536
/**
15221537
* Update the given device
15231538
*

src/client.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,8 @@ MatrixClient.prototype.rehydrateDevice = async function() {
500500
return;
501501
}
502502

503-
let getDeviceResult;
504-
try {
505-
getDeviceResult = await this._http.authedRequest(
506-
undefined,
507-
"GET",
508-
"/dehydrated_device",
509-
undefined, undefined,
510-
{
511-
prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2",
512-
},
513-
);
514-
} catch (e) {
515-
logger.info("could not get dehydrated device", e.toString());
503+
const getDeviceResult = this.getDehydratedDevice();
504+
if (!getDeviceResult) {
516505
return;
517506
}
518507

@@ -574,6 +563,27 @@ MatrixClient.prototype.rehydrateDevice = async function() {
574563
}
575564
};
576565

566+
/**
567+
* Get the current dehydrated device, if any
568+
* @return {Promise} A promise of an object containing the dehydrated device
569+
*/
570+
MatrixClient.prototype.getDehydratedDevice = async function() {
571+
try {
572+
return await this._http.authedRequest(
573+
undefined,
574+
"GET",
575+
"/dehydrated_device",
576+
undefined, undefined,
577+
{
578+
prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2",
579+
},
580+
);
581+
} catch (e) {
582+
logger.info("could not get dehydrated device", e.toString());
583+
return;
584+
}
585+
};
586+
577587
/**
578588
* Set the dehydration key. This will also periodically dehydrate devices to
579589
* the server.

src/crypto/verification/request/ToDeviceChannel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ export class ToDeviceChannel {
179179
const isAcceptingEvent = type === START_TYPE || type === READY_TYPE;
180180
// the request has picked a ready or start event, tell the other devices about it
181181
if (isAcceptingEvent && !wasStarted && isStarted && this._deviceId) {
182-
const nonChosenDevices = this._devices.filter(d => d !== this._deviceId);
182+
const nonChosenDevices = this._devices.filter(
183+
d => d !== this._deviceId && d !== this._client.getDeviceId(),
184+
);
183185
if (nonChosenDevices.length) {
184186
const message = this.completeContent({
185187
code: "m.accepted",

src/http-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ MatrixHttpApi.prototype = {
271271
xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000);
272272

273273
xhr.onreadystatechange = function() {
274+
let resp;
274275
switch (xhr.readyState) {
275276
case global.XMLHttpRequest.DONE:
276277
callbacks.clearTimeout(xhr.timeout_timer);
277-
var resp;
278278
try {
279279
if (xhr.status === 0) {
280280
throw new AbortError();

0 commit comments

Comments
 (0)