feat(sdk): Expose the list of tracked users publicly

This commit is contained in:
Damir Jelić 2021-09-09 10:20:50 +02:00
parent 1bcc74738e
commit c6100404e5
5 changed files with 35 additions and 2 deletions

View file

@ -14,7 +14,10 @@
// limitations under the License. // limitations under the License.
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use std::io::{Cursor, Write}; use std::{
collections::HashSet,
io::{Cursor, Write},
};
#[cfg(all(feature = "encryption", not(target_arch = "wasm32")))] #[cfg(all(feature = "encryption", not(target_arch = "wasm32")))]
use std::path::PathBuf; use std::path::PathBuf;
use std::{ use std::{
@ -716,6 +719,16 @@ impl Client {
self.base_client.olm_machine().await.map(|o| o.identity_keys().ed25519().to_owned()) self.base_client.olm_machine().await.map(|o| o.identity_keys().ed25519().to_owned())
} }
/// Get all the tracked users we know about
///
/// Tracked users are users for which we keep the device list of E2EE
/// capable devices up to date.
#[cfg(feature = "encryption")]
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
pub async fn tracked_users(&self) -> HashSet<UserId> {
self.base_client.olm_machine().await.map(|o| o.tracked_users()).unwrap_or_default()
}
/// Fetches the display name of the owner of the client. /// Fetches the display name of the owner of the client.
/// ///
/// # Example /// # Example

View file

@ -14,7 +14,11 @@
#[cfg(feature = "sled_cryptostore")] #[cfg(feature = "sled_cryptostore")]
use std::path::Path; use std::path::Path;
use std::{collections::BTreeMap, mem, sync::Arc}; use std::{
collections::{BTreeMap, HashSet},
mem,
sync::Arc,
};
use dashmap::DashMap; use dashmap::DashMap;
use matrix_sdk_common::{ use matrix_sdk_common::{
@ -293,6 +297,11 @@ impl OlmMachine {
self.store.device_display_name().await self.store.device_display_name().await
} }
/// Get all the tracked users we know about
pub fn tracked_users(&self) -> HashSet<UserId> {
self.store.tracked_users()
}
/// Get the outgoing requests that need to be sent out. /// Get the outgoing requests that need to be sent out.
/// ///
/// This returns a list of `OutGoingRequest`, those requests need to be sent /// This returns a list of `OutGoingRequest`, those requests need to be sent

View file

@ -183,6 +183,10 @@ impl CryptoStore for MemoryStore {
self.users_for_key_query.iter().map(|u| u.clone()).collect() self.users_for_key_query.iter().map(|u| u.clone()).collect()
} }
fn tracked_users(&self) -> HashSet<UserId> {
self.tracked_users.iter().map(|u| u.to_owned()).collect()
}
async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result<bool> { async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result<bool> {
// TODO to prevent a race between the sync and a key query in flight we // TODO to prevent a race between the sync and a key query in flight we
// need to have an additional state to mention that the user changed. // need to have an additional state to mention that the user changed.

View file

@ -584,6 +584,9 @@ pub trait CryptoStore: AsyncTraitDeps {
/// the tracked users. /// the tracked users.
fn users_for_key_query(&self) -> HashSet<UserId>; fn users_for_key_query(&self) -> HashSet<UserId>;
/// Get all tracked users we know about.
fn tracked_users(&self) -> HashSet<UserId>;
/// Add an user for tracking. /// Add an user for tracking.
/// ///
/// Returns true if the user wasn't already tracked, false otherwise. /// Returns true if the user wasn't already tracked, false otherwise.

View file

@ -673,6 +673,10 @@ impl CryptoStore for SledStore {
!self.users_for_key_query_cache.is_empty() !self.users_for_key_query_cache.is_empty()
} }
fn tracked_users(&self) -> HashSet<UserId> {
self.tracked_users_cache.to_owned().iter().map(|u| u.clone()).collect()
}
fn users_for_key_query(&self) -> HashSet<UserId> { fn users_for_key_query(&self) -> HashSet<UserId> {
#[allow(clippy::map_clone)] #[allow(clippy::map_clone)]
self.users_for_key_query_cache.iter().map(|u| u.clone()).collect() self.users_for_key_query_cache.iter().map(|u| u.clone()).collect()