index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
authorDavid Baker <[email protected]>2020-06-18 15:10:58 +0100
committerGitHub <[email protected]>2020-06-18 15:10:58 +0100
commite21d1f539d8783156ddf3b6cdf05816362752971 (patch)
tree2fcb9bb61e9a16980ca483d3db7bb2ed1b4df049
parent1c194e81637fb07fe6ad67cda33be0d5d4c10115 (diff)
parent1bd80247fd008c5f6e68a92df014e26a53e64552 (diff)
downloadmatrix-js-sdk-e21d1f539d8783156ddf3b6cdf05816362752971.tar.gz
Merge pull request #1405 from matrix-org/dbkr/fix_verification_race
Add method to get current in-flight to-device requests
-rw-r--r--src/client.js14
-rw-r--r--src/crypto/index.js4
-rw-r--r--src/crypto/verification/request/ToDeviceChannel.js8
3 files changed, 26 insertions, 0 deletions
diff --git a/src/client.js b/src/client.js
index fc73b41f..4ae6cfb0 100644
--- a/src/client.js
+++ b/src/client.js
@@ -970,6 +970,20 @@ MatrixClient.prototype.findVerificationRequestDMInProgress = function(roomId) {
};
/**
+ * Returns all to-device verification requests that are already in progress for the given user id
+ *
+ * @param {string} userId the ID of the user to query
+ *
+ * @returns {module:crypto/verification/request/VerificationRequest[]} the VerificationRequests that are in progress
+ */
+MatrixClient.prototype.getVerificationRequestsToDeviceInProgress = function(userId) {
+ if (this._crypto === null) {
+ throw new Error("End-to-end encryption disabled");
+ }
+ return this._crypto.getVerificationRequestsToDeviceInProgress(userId);
+};
+
+/**
* Request a key verification from another user.
*
* @param {string} userId the user to request verification with
diff --git a/src/crypto/index.js b/src/crypto/index.js
index ef9f492d..b88b5a16 100644
--- a/src/crypto/index.js
+++ b/src/crypto/index.js
@@ -2090,6 +2090,10 @@ Crypto.prototype.findVerificationRequestDMInProgress = function(roomId) {
return this._inRoomVerificationRequests.findRequestInProgress(roomId);
};
+Crypto.prototype.getVerificationRequestsToDeviceInProgress = function(userId) {
+ return this._toDeviceVerificationRequests.getRequestsInProgress(userId);
+};
+
Crypto.prototype.requestVerificationDM = function(userId, roomId) {
const existingRequest = this._inRoomVerificationRequests.
findRequestInProgress(roomId);
diff --git a/src/crypto/verification/request/ToDeviceChannel.js b/src/crypto/verification/request/ToDeviceChannel.js
index ea47fe5e..d04a7585 100644
--- a/src/crypto/verification/request/ToDeviceChannel.js
+++ b/src/crypto/verification/request/ToDeviceChannel.js
@@ -356,4 +356,12 @@ export class ToDeviceRequests {
}
}
}
+
+ getRequestsInProgress(userId) {
+ const requestsByTxnId = this._requestsByUserId.get(userId);
+ if (requestsByTxnId) {
+ return Array.from(requestsByTxnId.values()).filter(r => r.pending);
+ }
+ return [];
+ }
}