Skip to content

Commit

Permalink
invert the approach
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Nov 13, 2024
1 parent 4441039 commit 2b18f0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ impl FfiConversations {

pub async fn sync_all_conversations(&self) -> Result<u32, GenericError> {
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 {:?}: {:?}",
Expand Down
11 changes: 2 additions & 9 deletions xmtp_mls/src/groups/device_sync/message_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@ where
&self,
conn: &DbConnection,
) -> Result<Vec<Syncable>, 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)
}
Expand Down
13 changes: 13 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct GroupQueryArgs {
pub limit: Option<i64>,
pub conversation_type: Option<ConversationType>,
pub consent_state: Option<ConsentState>,
pub include_sync_groups: bool,
}

impl AsRef<GroupQueryArgs> for GroupQueryArgs {
Expand Down Expand Up @@ -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 {
Expand All @@ -205,6 +211,7 @@ impl DbConnection {
limit,
conversation_type,
consent_state,
include_sync_groups,
} = args.as_ref();

let mut query = groups_dsl::groups
Expand All @@ -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
Expand Down

0 comments on commit 2b18f0e

Please sign in to comment.