@@ -72,7 +72,7 @@ impl BackupVersion {
72
72
}
73
73
74
74
/// An in-memory only store that will forget all the E2EE key once it's dropped.
75
- #[ derive( Debug ) ]
75
+ #[ derive( Default , Debug ) ]
76
76
pub struct MemoryStore {
77
77
static_account : Arc < StdRwLock < Option < StaticAccountData > > > ,
78
78
@@ -103,36 +103,10 @@ pub struct MemoryStore {
103
103
dehydrated_device_pickle_key : RwLock < Option < DehydratedDeviceKey > > ,
104
104
next_batch_token : RwLock < Option < String > > ,
105
105
room_settings : StdRwLock < HashMap < OwnedRoomId , RoomSettings > > ,
106
- save_changes_lock : Arc < Mutex < ( ) > > ,
107
- }
106
+ room_key_bundles :
107
+ StdRwLock < HashMap < OwnedRoomId , HashMap < OwnedUserId , StoredRoomKeyBundleData > > > ,
108
108
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 < ( ) > > ,
136
110
}
137
111
138
112
impl MemoryStore {
@@ -349,6 +323,16 @@ impl CryptoStore for MemoryStore {
349
323
settings. extend ( changes. room_settings ) ;
350
324
}
351
325
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
+
352
336
Ok ( ( ) )
353
337
}
354
338
@@ -722,10 +706,14 @@ impl CryptoStore for MemoryStore {
722
706
723
707
async fn get_received_room_key_bundle_data (
724
708
& self ,
725
- _room_id : & RoomId ,
726
- _user_id : & UserId ,
709
+ room_id : & RoomId ,
710
+ user_id : & UserId ,
727
711
) -> 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)
729
717
}
730
718
731
719
async fn get_custom_value ( & self , key : & str ) -> Result < Option < Vec < u8 > > > {
0 commit comments