Skip to content

Commit

Permalink
Sync all conversations syncs all (#1340)
Browse files Browse the repository at this point in the history
* Revert "Live Consent Sync (#1234)"

This reverts commit 0b0bcde.

* make sync all sync all

* do the web side

* clean up the logic

* cargo fmt
  • Loading branch information
nplasterer authored Nov 26, 2024
1 parent 1413c38 commit 14df3bc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
14 changes: 5 additions & 9 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,19 +917,15 @@ 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().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)
}

Expand Down Expand Up @@ -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())
Expand Down
9 changes: 6 additions & 3 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,18 @@ impl Conversations {

#[napi]
pub async fn sync_all_conversations(&self) -> Result<usize> {
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)
}

Expand Down
13 changes: 10 additions & 3 deletions bindings_wasm/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,18 @@ impl Conversations {

#[wasm_bindgen(js_name = syncAllConversations)]
pub async fn sync_all_conversations(&self) -> Result<usize, JsError> {
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)
}

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 14df3bc

Please sign in to comment.