@@ -72,7 +72,7 @@ impl BackupVersion {
7272}
7373
7474/// An in-memory only store that will forget all the E2EE key once it's dropped.
75- #[ derive( Debug ) ]
75+ #[ derive( Default , Debug ) ]
7676pub struct MemoryStore {
7777 static_account : Arc < StdRwLock < Option < StaticAccountData > > > ,
7878
@@ -103,36 +103,10 @@ 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- save_changes_lock : Arc < Mutex < ( ) > > ,
107- }
106+ room_key_bundles :
107+ StdRwLock < HashMap < OwnedRoomId , HashMap < OwnedUserId , StoredRoomKeyBundleData > > > ,
108108
109- impl Default for MemoryStore {
110- fn default ( ) -> Self {
111- MemoryStore {
112- static_account : Default :: default ( ) ,
113- account : Default :: default ( ) ,
114- sessions : Default :: default ( ) ,
115- inbound_group_sessions : Default :: default ( ) ,
116- inbound_group_sessions_backed_up_to : Default :: default ( ) ,
117- outbound_group_sessions : Default :: default ( ) ,
118- private_identity : Default :: default ( ) ,
119- tracked_users : Default :: default ( ) ,
120- olm_hashes : Default :: default ( ) ,
121- devices : DeviceStore :: new ( ) ,
122- identities : Default :: default ( ) ,
123- outgoing_key_requests : Default :: default ( ) ,
124- key_requests_by_info : Default :: default ( ) ,
125- direct_withheld_info : Default :: default ( ) ,
126- custom_values : Default :: default ( ) ,
127- leases : Default :: default ( ) ,
128- backup_keys : Default :: default ( ) ,
129- dehydrated_device_pickle_key : Default :: default ( ) ,
130- secret_inbox : Default :: default ( ) ,
131- next_batch_token : Default :: default ( ) ,
132- room_settings : Default :: default ( ) ,
133- save_changes_lock : Default :: default ( ) ,
134- }
135- }
109+ save_changes_lock : Arc < Mutex < ( ) > > ,
136110}
137111
138112impl MemoryStore {
@@ -349,6 +323,16 @@ impl CryptoStore for MemoryStore {
349323 settings. extend ( changes. room_settings ) ;
350324 }
351325
326+ if !changes. received_room_key_bundles . is_empty ( ) {
327+ let mut room_key_bundles = self . room_key_bundles . write ( ) ;
328+ for bundle in changes. received_room_key_bundles {
329+ room_key_bundles
330+ . entry ( bundle. bundle_data . room_id . clone ( ) )
331+ . or_default ( )
332+ . insert ( bundle. sender_user . clone ( ) , bundle) ;
333+ }
334+ }
335+
352336 Ok ( ( ) )
353337 }
354338
@@ -722,10 +706,14 @@ impl CryptoStore for MemoryStore {
722706
723707 async fn get_received_room_key_bundle_data (
724708 & self ,
725- _room_id : & RoomId ,
726- _user_id : & UserId ,
709+ room_id : & RoomId ,
710+ user_id : & UserId ,
727711 ) -> Result < Option < StoredRoomKeyBundleData > > {
728- todo ! ( )
712+ let guard = self . room_key_bundles . read ( ) ;
713+
714+ let result = guard. get ( room_id) . and_then ( |bundles| bundles. get ( user_id) . cloned ( ) ) ;
715+
716+ Ok ( result)
729717 }
730718
731719 async fn get_custom_value ( & self , key : & str ) -> Result < Option < Vec < u8 > > > {
0 commit comments