crypto: Add a method to get all group sessions from the store.

master
Damir Jelić 2020-09-10 14:59:20 +02:00
parent 7bd0e4975b
commit 464e181f66
4 changed files with 24 additions and 0 deletions

View File

@ -106,6 +106,19 @@ impl GroupSessionStore {
.is_none()
}
/// Get all the group sessions the store knows about.
pub fn get_all(&self) -> Vec<InboundGroupSession> {
self.entries
.iter()
.flat_map(|d| {
d.value()
.values()
.flat_map(|t| t.values().cloned().collect::<Vec<InboundGroupSession>>())
.collect::<Vec<InboundGroupSession>>()
})
.collect()
}
/// Get a inbound group session from our store.
///
/// # Arguments

View File

@ -99,6 +99,10 @@ impl CryptoStore for MemoryStore {
.get(room_id, sender_key, session_id))
}
async fn get_inbound_group_sessions(&self) -> Result<Vec<InboundGroupSession>> {
Ok(self.inbound_group_sessions.get_all())
}
fn users_for_key_query(&self) -> HashSet<UserId> {
#[allow(clippy::map_clone)]
self.users_for_key_query.iter().map(|u| u.clone()).collect()

View File

@ -179,6 +179,9 @@ pub trait CryptoStore: Debug {
session_id: &str,
) -> Result<Option<InboundGroupSession>>;
/// Get all the inbound group sessions we have stored.
async fn get_inbound_group_sessions(&self) -> Result<Vec<InboundGroupSession>>;
/// Is the given user already tracked.
fn is_user_tracked(&self, user_id: &UserId) -> bool;

View File

@ -1289,6 +1289,10 @@ impl CryptoStore for SqliteStore {
.get(room_id, sender_key, session_id))
}
async fn get_inbound_group_sessions(&self) -> Result<Vec<InboundGroupSession>> {
Ok(self.inbound_group_sessions.get_all())
}
fn is_user_tracked(&self, user_id: &UserId) -> bool {
self.tracked_users.contains(user_id)
}