From 43a74524c58c97db46a840428b70637377bd504c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 18 Jan 2021 12:44:19 +0100 Subject: [PATCH] crypto: Add a pending requests method for the outbound group session --- matrix_sdk_crypto/src/olm/group_sessions/outbound.rs | 9 +++++++++ matrix_sdk_crypto/src/session_manager/group_sessions.rs | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index 6b3c9d86..e467c703 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -374,6 +374,15 @@ impl OutboundGroupSession { .or_insert_with(DashSet::new) .insert(device_id.to_owned()); } + + /// Get the list of requests that need to be sent out for this session to be + /// marked as shared. + pub(crate) fn pending_requests(&self) -> Vec> { + self.to_share_with_set + .iter() + .map(|i| i.value().clone()) + .collect() + } } #[cfg(not(tarpaulin_include))] diff --git a/matrix_sdk_crypto/src/session_manager/group_sessions.rs b/matrix_sdk_crypto/src/session_manager/group_sessions.rs index b8f27aa7..422b1973 100644 --- a/matrix_sdk_crypto/src/session_manager/group_sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/group_sessions.rs @@ -244,7 +244,6 @@ impl GroupSessionManager { .collect::>() ); - let mut requests = Vec::new(); let key_content = outbound.as_json().await; for device_map_chunk in devices.chunks(Self::MAX_TO_DEVICE_MESSAGES) { @@ -283,12 +282,13 @@ impl GroupSessionManager { messages, }); - outbound.add_request(id, request.clone()); + outbound.add_request(id, request); self.outbound_sessions_being_shared .insert(id, outbound.clone()); - requests.push(request); } + let requests = outbound.pending_requests(); + if requests.is_empty() { debug!( "Session {} for room {} doesn't need to be shared with anyone, marking as shared",