index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
authorDavid Baker <[email protected]>2020-06-15 17:38:50 +0100
committerDavid Baker <[email protected]>2020-06-15 17:38:50 +0100
commit3dece4f46bf3d2ed4a4332c3eef4dfa061688a97 (patch)
treeb801771a077f341d55c70d68f694c055bf224054
parent505915528f4b0c2e0a56809675529cd8d418508f (diff)
downloadmatrix-js-sdk-3dece4f46bf3d2ed4a4332c3eef4dfa061688a97.tar.gz
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..5d982013 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 requests = this._requestsByUserId.get(userId);
+ if (requests) {
+ return Array.from(requests.values()).filter(r => r.pending);
+ }
+ return [];
+ }
}