diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 3404de771..1261d2ef9 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -917,19 +917,15 @@ impl FfiConversations { pub async fn sync_all_conversations(&self) -> Result { let inner = self.inner_client.as_ref(); - let groups = inner.find_groups(GroupQueryArgs::default().include_sync_groups())?; + let conn = inner.store().conn()?; - log::info!( - "groups for client inbox id {:?}: {:?}", - self.inner_client.inbox_id(), - groups.len() - ); + let num_groups_synced: usize = inner.sync_all_welcomes_and_groups(&conn).await?; - let num_groups_synced: usize = inner.sync_all_groups(groups).await?; - // Uniffi does not work with usize, so we need to convert to u32 + // Convert usize to u32 for compatibility with Uniffi let num_groups_synced: u32 = num_groups_synced .try_into() .map_err(|_| GenericError::FailedToConvertToU32)?; + Ok(num_groups_synced) } @@ -2569,7 +2565,7 @@ mod tests { .unwrap(); } - bo.conversations().sync().await.unwrap(); + bo.conversations().sync_all_conversations().await.unwrap(); let alix_groups = alix .conversations() .list(FfiListConversationsOptions::default()) diff --git a/bindings_node/src/conversations.rs b/bindings_node/src/conversations.rs index 24b618a40..d6a449e70 100644 --- a/bindings_node/src/conversations.rs +++ b/bindings_node/src/conversations.rs @@ -250,15 +250,18 @@ impl Conversations { #[napi] pub async fn sync_all_conversations(&self) -> Result { - let groups = self + let conn = self .inner_client - .find_groups(GroupQueryArgs::default()) + .store() + .conn() .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)?; + Ok(num_groups_synced) } diff --git a/bindings_wasm/src/conversations.rs b/bindings_wasm/src/conversations.rs index 07931f5b4..c33cd901d 100644 --- a/bindings_wasm/src/conversations.rs +++ b/bindings_wasm/src/conversations.rs @@ -285,11 +285,18 @@ impl Conversations { #[wasm_bindgen(js_name = syncAllConversations)] pub async fn sync_all_conversations(&self) -> Result { - let groups = self + let conn = self + .inner_client + .store() + .conn() + .map_err(|e| JsError::new(format!("{}", e).as_str()))?; + + let num_groups_synced = self .inner_client - .find_groups(GroupQueryArgs::default()) + .sync_all_welcomes_and_groups(&conn) + .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; - let num_groups_synced = self.inner_client.sync_all_groups(groups).await?; + Ok(num_groups_synced) } diff --git a/xmtp_mls/src/client.rs b/xmtp_mls/src/client.rs index a33a24462..d680e3018 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 *