From 719e5e1af737f412296e2a4b298d5908afb1bfa6 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 26 Nov 2024 08:40:08 -0800 Subject: [PATCH] clean up the logic --- bindings_ffi/src/mls.rs | 17 +---------------- bindings_node/src/conversations.rs | 13 +------------ bindings_wasm/src/conversations.rs | 13 +------------ xmtp_mls/src/client.rs | 13 +++++++++++++ 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 0e579fcde..1261d2ef9 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -918,23 +918,8 @@ impl FfiConversations { pub async fn sync_all_conversations(&self) -> Result { let inner = self.inner_client.as_ref(); let conn = inner.store().conn()?; - let groups = inner.find_groups(GroupQueryArgs::default().include_sync_groups())?; - log::info!( - "Groups for client inbox ID {:?}: {:?}", - self.inner_client.inbox_id(), - groups.len() - ); - - // Call sync operations in parallel - let (welcome_result, group_result) = tokio::join!( - self.inner_client.sync_welcomes(&conn), - inner.sync_all_groups(groups) - ); - - // Handle potential errors from join! - welcome_result?; - let num_groups_synced: usize = group_result?; + let num_groups_synced: usize = inner.sync_all_welcomes_and_groups(&conn).await?; // Convert usize to u32 for compatibility with Uniffi let num_groups_synced: u32 = num_groups_synced diff --git a/bindings_node/src/conversations.rs b/bindings_node/src/conversations.rs index 73c22ef37..d6a449e70 100644 --- a/bindings_node/src/conversations.rs +++ b/bindings_node/src/conversations.rs @@ -256,20 +256,9 @@ impl Conversations { .conn() .map_err(ErrorWrapper::from)?; - self - .inner_client - .sync_welcomes(&conn) - .await - .map_err(ErrorWrapper::from)?; - - let groups = self - .inner_client - .find_groups(GroupQueryArgs::default().include_sync_groups()) - .map_err(ErrorWrapper::from)?; - let num_groups_synced = self .inner_client - .sync_all_groups(groups) + .sync_all_welcomes_and_groups(&conn) .await .map_err(ErrorWrapper::from)?; diff --git a/bindings_wasm/src/conversations.rs b/bindings_wasm/src/conversations.rs index 3081b7f0d..c33cd901d 100644 --- a/bindings_wasm/src/conversations.rs +++ b/bindings_wasm/src/conversations.rs @@ -291,20 +291,9 @@ impl Conversations { .conn() .map_err(|e| JsError::new(format!("{}", e).as_str()))?; - self - .inner_client - .sync_welcomes(&conn) - .await - .map_err(|e| JsError::new(format!("{}", e).as_str()))?; - - let groups = self - .inner_client - .find_groups(GroupQueryArgs::default().include_sync_groups()) - .map_err(|e| JsError::new(format!("{}", e).as_str()))?; - let num_groups_synced = self .inner_client - .sync_all_groups(groups) + .sync_all_welcomes_and_groups(&conn) .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; diff --git a/xmtp_mls/src/client.rs b/xmtp_mls/src/client.rs index a33a24462..463d33aae 100644 --- a/xmtp_mls/src/client.rs +++ b/xmtp_mls/src/client.rs @@ -842,6 +842,19 @@ where Ok(active_group_count.load(Ordering::SeqCst)) } + /// Sync all unread welcome messages and then sync all groups. + /// Returns the total number of active groups synced. + pub async fn sync_all_welcomes_and_groups( + &self, + conn: &DbConnection, + ) -> Result { + self.sync_welcomes(conn).await?; + let groups = self.find_groups(GroupQueryArgs::default().include_sync_groups())?; + let active_groups_count = self.sync_all_groups(groups).await?; + + Ok(active_groups_count) + } + /** * Validates a credential against the given installation public key *