@@ -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,9 @@ 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 : StdRwLock < HashMap < OwnedRoomId , Vec < StoredRoomKeyBundleData > > > ,
108
107
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
- }
108
+ save_changes_lock : Arc < Mutex < ( ) > > ,
136
109
}
137
110
138
111
impl MemoryStore {
@@ -349,6 +322,16 @@ impl CryptoStore for MemoryStore {
349
322
settings. extend ( changes. room_settings ) ;
350
323
}
351
324
325
+ if !changes. received_room_key_bundles . is_empty ( ) {
326
+ let mut room_key_bundles = self . room_key_bundles . write ( ) ;
327
+ for bundle in changes. received_room_key_bundles {
328
+ room_key_bundles
329
+ . entry ( bundle. bundle_data . room_id . clone ( ) )
330
+ . or_default ( )
331
+ . push ( bundle) ;
332
+ }
333
+ }
334
+
352
335
Ok ( ( ) )
353
336
}
354
337
@@ -722,10 +705,17 @@ impl CryptoStore for MemoryStore {
722
705
723
706
async fn get_received_room_key_bundle_data (
724
707
& self ,
725
- _room_id : & RoomId ,
726
- _user_id : & UserId ,
708
+ room_id : & RoomId ,
709
+ user_id : & UserId ,
727
710
) -> Result < Option < StoredRoomKeyBundleData > > {
728
- todo ! ( )
711
+ let guard = self . room_key_bundles . read ( ) ;
712
+
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
+ } ) ;
717
+
718
+ Ok ( result)
729
719
}
730
720
731
721
async fn get_custom_value ( & self , key : & str ) -> Result < Option < Vec < u8 > > > {
0 commit comments