Skip to content

Commit f11158a

Browse files
committed
sdk: send out the to-device requests created by Room::share_history
1 parent 84a030a commit f11158a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

crates/matrix-sdk/src/room/shared_room_history.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ use std::iter;
1616

1717
use ruma::OwnedUserId;
1818

19-
use crate::{Error, Result, Room};
19+
use crate::{crypto::types::events::room_key_bundle::RoomKeyBundleContent, Error, Result, Room};
2020

2121
/// Share any shareable E2EE history in the given room with the given recipient,
2222
/// as per [MSC4268].
2323
///
2424
/// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268
2525
pub async fn share_room_history(room: &Room, user_id: OwnedUserId) -> Result<()> {
2626
tracing::info!("Sharing message history in {} with {}", room.room_id(), user_id);
27+
let client = &room.client;
2728

2829
// 1. Construct the key bundle
2930
let bundle = {
30-
let olm_machine = room.client.olm_machine().await;
31+
let olm_machine = client.olm_machine().await;
3132
let olm_machine = olm_machine.as_ref().ok_or(Error::NoOlmMachine)?;
3233
olm_machine.store().build_room_key_bundle(room.room_id()).await?
3334
};
@@ -40,7 +41,7 @@ pub async fn share_room_history(room: &Room, user_id: OwnedUserId) -> Result<()>
4041
// 2. Upload to the server as an encrypted file
4142
let json = serde_json::to_vec(&bundle)?;
4243
let upload =
43-
room.client.upload_encrypted_file(&mime::APPLICATION_JSON, &mut (json.as_slice())).await?;
44+
client.upload_encrypted_file(&mime::APPLICATION_JSON, &mut (json.as_slice())).await?;
4445

4546
tracing::info!(
4647
media_url = ?upload.url,
@@ -49,8 +50,26 @@ pub async fn share_room_history(room: &Room, user_id: OwnedUserId) -> Result<()>
4950
"Uploaded encrypted key blob"
5051
);
5152

52-
// 3. Send to-device messages to the recipient to share the keys.
53-
// TODO
53+
// 3. Establish Olm sessions with all of the recipient's devices.
54+
client.claim_one_time_keys(iter::once(user_id.as_ref())).await?;
5455

56+
// 4. Send to-device messages to the recipient to share the keys.
57+
let content = RoomKeyBundleContent { room_id: room.room_id().to_owned(), file: upload };
58+
let requests = {
59+
let olm_machine = client.olm_machine().await;
60+
let olm_machine = olm_machine.as_ref().ok_or(Error::NoOlmMachine)?;
61+
olm_machine
62+
.share_room_key_bundle_data(
63+
&user_id,
64+
&client.base_client().room_key_recipient_strategy,
65+
content,
66+
)
67+
.await?
68+
};
69+
70+
for request in requests {
71+
let response = client.send_to_device(&request).await?;
72+
client.mark_request_as_sent(&request.txn_id, &response).await?;
73+
}
5574
Ok(())
5675
}

0 commit comments

Comments
 (0)