Commit 0ee5a5a345ee
tarball2 files changed+19-3
@@ -520,7 +520,7 @@ impl<'a> IntoFuture for SendStateEvent<'a> {
520520
521521
/// Ensures the room is ready for encrypted events to be sent.522522
#[cfg(feature = "e2e-encryption")]523
-async fn ensure_room_encryption_ready(room: &Room) -> Result<()> {523
+pub(super) async fn ensure_room_encryption_ready(room: &Room) -> Result<()> {524524
if !room.are_members_synced() {525525
room.sync_members().await?;526526
}@@ -2383,14 +2383,30 @@ impl Room {
23832383
self.enable_encryption_inner(true).await23842384
}23852385
2386
+ /// Get this room ready for sending an encrypted event, ahead of the send.2387
+ ///2388
+ /// Syncs the members if needed, queries the keys of untracked or dirty2389
+ /// members, claims one-time keys and shares the room key. That's the work2390
+ /// sending an encrypted event would otherwise do before the event goes2391
+ /// out, so calling this when the user starts typing takes it off the send.2392
+ ///2393
+ /// Does nothing if the room isn't encrypted or no room key needs to be2394
+ /// shared. A send racing it waits for the share rather than doing it twice.2395
+ #[cfg(feature = "e2e-encryption")]2396
+ #[instrument(skip_all, fields(room_id = ?self.room_id()))]2397
+ pub async fn prepare_encryption(&self) -> Result<()> {2398
+ if self.latest_encryption_state().await?.is_encrypted() {2399
+ futures::ensure_room_encryption_ready(self).await?;2400
+ }2401
+ Ok(())2402
+ }2403
+23862404
/// Share a room key with users in the given room.23872405
///23882406
/// This will create Olm sessions with all the users/device pairs in the23892407
/// room if necessary and share a room key that can be shared with them.23902408
///23912409
/// Does nothing if no room key needs to be shared.2392
- // TODO: expose this publicly so people can pre-share a group session if2393
- // e.g. a user starts to type a message for a room.23942410
#[cfg(feature = "e2e-encryption")]23952411
#[instrument(skip_all, fields(room_id = ?self.room_id()))]23962412
async fn preshare_room_key(&self) -> Result<()> {