diff --git a/src/base-apis.js b/src/base-apis.js index 5b2a70b81..a86d24465 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -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 * diff --git a/src/client.js b/src/client.js index 8832c0965..53fca78ac 100644 --- a/src/client.js +++ b/src/client.js @@ -500,19 +500,8 @@ MatrixClient.prototype.rehydrateDevice = async function() { return; } - let getDeviceResult; - try { - 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()); + const getDeviceResult = this.getDehydratedDevice(); + if (!getDeviceResult) { 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 * the server. diff --git a/src/crypto/verification/request/ToDeviceChannel.js b/src/crypto/verification/request/ToDeviceChannel.js index d04a75853..9f3659389 100644 --- a/src/crypto/verification/request/ToDeviceChannel.js +++ b/src/crypto/verification/request/ToDeviceChannel.js @@ -179,7 +179,9 @@ export class ToDeviceChannel { const isAcceptingEvent = type === START_TYPE || type === READY_TYPE; // the request has picked a ready or start event, tell the other devices about it 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) { const message = this.completeContent({ code: "m.accepted", diff --git a/src/http-api.js b/src/http-api.js index cc86506ad..26b3d5f5b 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -271,10 +271,10 @@ MatrixHttpApi.prototype = { xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000); xhr.onreadystatechange = function() { + let resp; switch (xhr.readyState) { case global.XMLHttpRequest.DONE: callbacks.clearTimeout(xhr.timeout_timer); - var resp; try { if (xhr.status === 0) { throw new AbortError();