crypto: Store TrackedUsers in MemoryStore
This commit is contained in:
parent
c6da40cf55
commit
099c855049
|
@ -55,6 +55,7 @@ pub struct MemoryStore {
|
|||
sessions: SessionStore,
|
||||
inbound_group_sessions: GroupSessionStore,
|
||||
outbound_group_sessions: StdRwLock<BTreeMap<OwnedRoomId, OutboundGroupSession>>,
|
||||
tracked_users: StdRwLock<Vec<TrackedUser>>,
|
||||
olm_hashes: StdRwLock<HashMap<String, HashSet<String>>>,
|
||||
devices: DeviceStore,
|
||||
identities: StdRwLock<HashMap<OwnedUserId, ReadOnlyUserIdentities>>,
|
||||
|
@ -76,6 +77,7 @@ impl Default for MemoryStore {
|
|||
sessions: SessionStore::new(),
|
||||
inbound_group_sessions: GroupSessionStore::new(),
|
||||
outbound_group_sessions: Default::default(),
|
||||
tracked_users: Default::default(),
|
||||
olm_hashes: Default::default(),
|
||||
devices: DeviceStore::new(),
|
||||
identities: Default::default(),
|
||||
|
@ -315,10 +317,13 @@ impl CryptoStore for MemoryStore {
|
|||
}
|
||||
|
||||
async fn load_tracked_users(&self) -> Result<Vec<TrackedUser>> {
|
||||
Ok(Vec::new())
|
||||
Ok(self.tracked_users.read().unwrap().clone())
|
||||
}
|
||||
|
||||
async fn save_tracked_users(&self, _: &[(&UserId, bool)]) -> Result<()> {
|
||||
async fn save_tracked_users(&self, tracked_users: &[(&UserId, bool)]) -> Result<()> {
|
||||
self.tracked_users.write().unwrap().extend(tracked_users.iter().map(|(user_id, dirty)| {
|
||||
TrackedUser { user_id: user_id.to_owned().into(), dirty: *dirty }
|
||||
}));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -472,7 +477,7 @@ impl CryptoStore for MemoryStore {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::room_id;
|
||||
use ruma::{room_id, user_id};
|
||||
use vodozemac::{Curve25519PublicKey, Ed25519PublicKey};
|
||||
|
||||
use crate::{
|
||||
|
@ -526,7 +531,7 @@ mod tests {
|
|||
|
||||
#[async_test]
|
||||
async fn test_outbound_group_session_store() {
|
||||
// Given an outbound sessions
|
||||
// Given an outbound session
|
||||
let (account, _) = get_account_and_session_test_helper();
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let (outbound, _) = account.create_group_session_pair_with_defaults(room_id).await;
|
||||
|
@ -543,6 +548,26 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_tracked_users_store() {
|
||||
// Given some tracked users
|
||||
let tracked_users =
|
||||
&[(user_id!("@dirty_user:s"), true), (user_id!("@clean_user:t"), false)];
|
||||
|
||||
// When we save them to the store
|
||||
let store = MemoryStore::new();
|
||||
store.save_tracked_users(tracked_users).await.unwrap();
|
||||
|
||||
// Then we can get them out again
|
||||
let loaded_tracked_users =
|
||||
store.load_tracked_users().await.expect("failed to load tracked users");
|
||||
assert_eq!(loaded_tracked_users[0].user_id, user_id!("@dirty_user:s"));
|
||||
assert!(loaded_tracked_users[0].dirty);
|
||||
assert_eq!(loaded_tracked_users[1].user_id, user_id!("@clean_user:t"));
|
||||
assert!(!loaded_tracked_users[1].dirty);
|
||||
assert_eq!(loaded_tracked_users.len(), 2);
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_device_store() {
|
||||
let device = get_device();
|
||||
|
|
|
@ -526,7 +526,7 @@ pub struct Changes {
|
|||
}
|
||||
|
||||
/// A user for which we are tracking the list of devices.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct TrackedUser {
|
||||
/// The user ID of the user.
|
||||
pub user_id: OwnedUserId,
|
||||
|
|
Loading…
Reference in New Issue