From 2b18f0e213dac69080c6d72d9753866fff177b36 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Wed, 13 Nov 2024 15:06:41 -0500 Subject: [PATCH] invert the approach --- bindings_ffi/src/mls.rs | 2 +- xmtp_mls/src/groups/device_sync/message_sync.rs | 11 ++--------- xmtp_mls/src/storage/encrypted_store/group.rs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index a30f29333..338d4feee 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -858,7 +858,7 @@ impl FfiConversations { pub async fn sync_all_conversations(&self) -> Result { let inner = self.inner_client.as_ref(); - let groups = inner.find_groups(GroupQueryArgs::default())?; + let groups = inner.find_groups(GroupQueryArgs::default().include_sync_groups())?; log::info!( "groups for client inbox id {:?}: {:?}", diff --git a/xmtp_mls/src/groups/device_sync/message_sync.rs b/xmtp_mls/src/groups/device_sync/message_sync.rs index 5f08b5df9..8cd0bddba 100644 --- a/xmtp_mls/src/groups/device_sync/message_sync.rs +++ b/xmtp_mls/src/groups/device_sync/message_sync.rs @@ -14,18 +14,11 @@ where &self, conn: &DbConnection, ) -> Result, DeviceSyncError> { - let mut groups: Vec<_> = conn - .find_groups(GroupQueryArgs::default().conversation_type(ConversationType::Group))? + let groups = conn + .find_groups(GroupQueryArgs::default())? .into_iter() .map(Syncable::Group) .collect(); - let mut dms: Vec<_> = conn - .find_groups(GroupQueryArgs::default().conversation_type(ConversationType::Dm))? - .into_iter() - .map(Syncable::Group) - .collect(); - - groups.append(&mut dms); Ok(groups) } diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 91d6d18a8..f5241f53e 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -124,6 +124,7 @@ pub struct GroupQueryArgs { pub limit: Option, pub conversation_type: Option, pub consent_state: Option, + pub include_sync_groups: bool, } impl AsRef for GroupQueryArgs { @@ -188,6 +189,11 @@ impl GroupQueryArgs { self.consent_state = consent_state; self } + + pub fn include_sync_groups(mut self) -> Self { + self.include_sync_groups = true; + self + } } impl DbConnection { @@ -205,6 +211,7 @@ impl DbConnection { limit, conversation_type, consent_state, + include_sync_groups, } = args.as_ref(); let mut query = groups_dsl::groups @@ -231,6 +238,12 @@ impl DbConnection { query = query.filter(groups_dsl::conversation_type.eq(conversation_type)); } + // Were sync groups explicitly asked for? Was the include_sync_groups flag set to true? + // Otherwise filter sync groups out by default. + if !matches!(conversation_type, Some(ConversationType::Sync)) && !include_sync_groups { + query = query.filter(groups_dsl::conversation_type.ne(ConversationType::Sync)); + } + let groups = if let Some(consent_state) = consent_state { if *consent_state == ConsentState::Unknown { let query = query