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",