17
17
18
18
#![ deny( unreachable_pub) ]
19
19
20
- use std:: { future:: IntoFuture , io:: Read } ;
20
+ use std:: { future:: IntoFuture , io:: Read , iter } ;
21
21
22
22
use eyeball:: SharedObservable ;
23
23
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -28,7 +28,10 @@ use ruma::{
28
28
OwnedUserId ,
29
29
} ;
30
30
31
- use crate :: { config:: RequestConfig , Client , Media , Result , Room , TransmissionProgress } ;
31
+ use crate :: {
32
+ config:: RequestConfig , crypto:: types:: events:: room_key_bundle:: RoomKeyBundleContent , Client ,
33
+ Media , Result , Room , TransmissionProgress ,
34
+ } ;
32
35
33
36
/// Future returned by [`Client::upload_encrypted_file`].
34
37
#[ allow( missing_debug_implementations) ]
@@ -149,10 +152,11 @@ impl<'a> IntoFuture for ShareRoomHistory<'a> {
149
152
let Self { room, user_id } = self ;
150
153
Box :: pin ( async move {
151
154
tracing:: info!( "Sharing message history in {} with {}" , room. room_id( ) , user_id) ;
155
+ let client = & room. client ;
152
156
153
157
// 1. Construct the key bundle
154
158
let bundle = {
155
- let olm_machine = room . client . olm_machine ( ) . await ;
159
+ let olm_machine = client. olm_machine ( ) . await ;
156
160
let olm_machine = olm_machine
157
161
. as_ref ( )
158
162
. expect ( "This should only be called once we have an OlmMachine" ) ;
@@ -178,9 +182,22 @@ impl<'a> IntoFuture for ShareRoomHistory<'a> {
178
182
"Uploaded encrypted key blob"
179
183
) ;
180
184
181
- // 3. Send to-device messages to the recipient to share the keys.
182
- // TODO
185
+ // 3. Establish Olm sessions with all of the recipient's devices.
186
+ client. claim_one_time_keys ( iter:: once ( user_id. as_ref ( ) ) ) . await ?;
187
+
188
+ // 4. Send to-device messages to the recipient to share the keys.
189
+ let requests = client
190
+ . base_client ( )
191
+ . share_room_key_bundle_data (
192
+ & user_id,
193
+ RoomKeyBundleContent { room_id : room. room_id ( ) . to_owned ( ) , file : upload } ,
194
+ )
195
+ . await ?;
183
196
197
+ for request in requests {
198
+ let response = client. send_to_device ( & request) . await ?;
199
+ client. mark_request_as_sent ( & request. txn_id , & response) . await ?;
200
+ }
184
201
Ok ( ( ) )
185
202
} )
186
203
}
0 commit comments