Skip to content

Commit 237bba5

Browse files
committed
fixup! memorystore: store received room key bundle data
1 parent b010c02 commit 237bba5

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crates/matrix-sdk-crypto/src/store/memorystore.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ pub struct MemoryStore {
103103
dehydrated_device_pickle_key: RwLock<Option<DehydratedDeviceKey>>,
104104
next_batch_token: RwLock<Option<String>>,
105105
room_settings: StdRwLock<HashMap<OwnedRoomId, RoomSettings>>,
106-
room_key_bundles: StdRwLock<HashMap<OwnedRoomId, Vec<StoredRoomKeyBundleData>>>,
106+
room_key_bundles:
107+
StdRwLock<HashMap<OwnedRoomId, HashMap<OwnedUserId, StoredRoomKeyBundleData>>>,
107108

108109
save_changes_lock: Arc<Mutex<()>>,
109110
}
@@ -328,7 +329,7 @@ impl CryptoStore for MemoryStore {
328329
room_key_bundles
329330
.entry(bundle.bundle_data.room_id.clone())
330331
.or_default()
331-
.push(bundle);
332+
.insert(bundle.sender_user.clone(), bundle);
332333
}
333334
}
334335

@@ -710,10 +711,7 @@ impl CryptoStore for MemoryStore {
710711
) -> Result<Option<StoredRoomKeyBundleData>> {
711712
let guard = self.room_key_bundles.read();
712713

713-
let result = guard.get(room_id).and_then(|bundles| {
714-
// Find the most recently-added entry from this user
715-
bundles.iter().rfind(|b| b.sender_user == user_id).cloned()
716-
});
714+
let result = guard.get(room_id).and_then(|bundles| bundles.get(user_id).cloned());
717715

718716
Ok(result)
719717
}

0 commit comments

Comments
 (0)