From 34703bc0d66c02919b8d509e8064a29e410da128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 17 Jun 2021 10:03:47 +0200 Subject: [PATCH] crypto: Add a method to get all verification requests of a certain user --- matrix_sdk_crypto/src/machine.rs | 5 +++++ matrix_sdk_crypto/src/verification/machine.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 5b1cfa00..a22e7929 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -731,6 +731,11 @@ impl OlmMachine { self.verification_machine.get_request(user_id, flow_id) } + /// Get all the verification requests of a given user. + pub fn get_verification_requests(&self, user_id: &UserId) -> Vec { + self.verification_machine.get_requests(user_id) + } + async fn update_one_time_key_count(&self, key_count: &BTreeMap) { self.account.update_uploaded_key_count(key_count).await; } diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index 5478a16e..9a1162fe 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -99,6 +99,13 @@ impl VerificationMachine { self.requests.get(user_id).and_then(|v| v.get(flow_id.as_ref()).map(|s| s.clone())) } + pub fn get_requests(&self, user_id: &UserId) -> Vec { + self.requests + .get(user_id) + .map(|v| v.iter().map(|i| i.value().clone()).collect()) + .unwrap_or_default() + } + fn insert_request(&self, request: VerificationRequest) { self.requests .entry(request.other_user().to_owned())