Skip to content

Commit 31cf1df

Browse files
committed
sdk: send out the to-device requests created by Room::share_history
1 parent 88d8c1e commit 31cf1df

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::{
2424
use eyeball::{SharedObservable, Subscriber};
2525
use eyeball_im::{Vector, VectorDiff};
2626
use futures_util::Stream;
27+
use matrix_sdk_crypto::types::events::room_key_bundle::RoomKeyBundleContent;
2728
#[cfg(feature = "e2e-encryption")]
2829
use matrix_sdk_crypto::{
2930
store::DynCryptoStore, types::requests::ToDeviceRequest, CollectStrategy, DecryptionSettings,
@@ -1594,6 +1595,22 @@ impl BaseClient {
15941595
}
15951596
}
15961597

1598+
/// Get to-device requests that will share the details of a room key history
1599+
/// bundle with a user.
1600+
#[cfg(feature = "e2e-encryption")]
1601+
pub async fn share_room_key_bundle_data(
1602+
&self,
1603+
user_id: &UserId,
1604+
bundle_data: RoomKeyBundleContent,
1605+
) -> Result<Vec<ToDeviceRequest>> {
1606+
let olm = self.olm_machine().await;
1607+
let olm = olm.as_ref().expect("Olm machine wasn't started");
1608+
1609+
Ok(olm
1610+
.share_room_key_bundle_data(&user_id, &self.room_key_recipient_strategy, bundle_data)
1611+
.await?)
1612+
}
1613+
15971614
/// Get the room with the given room id.
15981615
///
15991616
/// # Arguments

crates/matrix-sdk/src/encryption/futures.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
#![deny(unreachable_pub)]
1919

20-
use std::{future::IntoFuture, io::Read};
20+
use std::{future::IntoFuture, io::Read, iter};
2121

2222
use eyeball::SharedObservable;
2323
#[cfg(not(target_arch = "wasm32"))]
@@ -149,10 +149,11 @@ impl<'a> IntoFuture for ShareRoomHistory<'a> {
149149
let Self { room, user_id } = self;
150150
Box::pin(async move {
151151
tracing::info!("Sharing message history in {} with {}", room.room_id(), user_id);
152+
let client = &room.client;
152153

153154
// 1. Construct the key bundle
154155
let bundle = {
155-
let olm_machine = room.client.olm_machine().await;
156+
let olm_machine = client.olm_machine().await;
156157
let olm_machine = olm_machine
157158
.as_ref()
158159
.expect("This should only be called once we have an OlmMachine");
@@ -178,9 +179,17 @@ impl<'a> IntoFuture for ShareRoomHistory<'a> {
178179
"Uploaded encrypted key blob"
179180
);
180181

181-
// 3. Send to-device messages to the recipient to share the keys.
182-
// TODO
182+
// 3. Establish Olm seeions with all of the recipient's devices
183+
client.claim_one_time_keys(iter::once(user_id.as_ref())).await?;
183184

185+
// 4. Send to-device messages to the recipient to share the keys.
186+
let requests =
187+
client.base_client().share_room_key_bundle_data(&user_id, upload).await?;
188+
189+
for request in requests {
190+
let response = client.send_to_device(&request).await?;
191+
client.mark_request_as_sent(&request.txn_id, &response).await?;
192+
}
184193
Ok(())
185194
})
186195
}

0 commit comments

Comments
 (0)