Skip to content

Commit

Permalink
clean up the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 26, 2024
1 parent 0efd0cf commit 719e5e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
17 changes: 1 addition & 16 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,23 +918,8 @@ impl FfiConversations {
pub async fn sync_all_conversations(&self) -> Result<u32, GenericError> {
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
Expand Down
13 changes: 1 addition & 12 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
13 changes: 1 addition & 12 deletions bindings_wasm/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;

Expand Down
13 changes: 13 additions & 0 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, ClientError> {
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
*
Expand Down

0 comments on commit 719e5e1

Please sign in to comment.