From 44fdabfbc9f7d74de6a3e111cb1269d5f39cc510 Mon Sep 17 00:00:00 2001 From: Dakota Brink <779390+codabrink@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:15:45 -0500 Subject: [PATCH] make include sync groups work unconditionally (#1391) --- xmtp_mls/src/storage/encrypted_store/group.rs | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 2cecc9b4f..63906099e 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -215,6 +215,8 @@ impl DbConnection { } = args.as_ref(); let mut query = groups_dsl::groups + // Filter out sync groups from the main query + .filter(groups_dsl::conversation_type.ne(ConversationType::Sync)) .order(groups_dsl::created_at_ns.asc()) .into_boxed(); @@ -238,13 +240,7 @@ 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 { + let mut groups = if let Some(consent_state) = consent_state { if *consent_state == ConsentState::Unknown { let query = query .left_join( @@ -278,6 +274,15 @@ impl DbConnection { self.raw_query(|conn| query.load::(conn))? }; + // Were sync groups explicitly asked for? Was the include_sync_groups flag set to true? + // Then query for those separately + if matches!(conversation_type, Some(ConversationType::Sync)) || *include_sync_groups { + let query = + groups_dsl::groups.filter(groups_dsl::conversation_type.eq(ConversationType::Sync)); + let mut sync_groups = self.raw_query(|conn| query.load(conn))?; + groups.append(&mut sync_groups); + } + Ok(groups) } @@ -781,7 +786,19 @@ pub(crate) mod tests { let found = conn.latest_sync_group().unwrap(); assert!(found.is_some()); - assert_eq!(found.unwrap().conversation_type, ConversationType::Sync) + assert_eq!(found.unwrap().conversation_type, ConversationType::Sync); + + // Load the sync group with a consent filter + let allowed_groups = conn + .find_groups(&GroupQueryArgs { + consent_state: Some(ConsentState::Allowed), + include_sync_groups: true, + ..Default::default() + }) + .unwrap(); + + assert_eq!(allowed_groups.len(), 1); + assert_eq!(allowed_groups[0].id, sync_group.id); }) .await }