Skip to content

Commit

Permalink
feat: adds missing installations when group is synced (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuddman authored Feb 8, 2024
1 parent 1fe17d8 commit 43bc889
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
imports_granularity = "Crate"
reorder_imports = true
4 changes: 2 additions & 2 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ mod tests {
let _amal_2nd = ClientBuilder::new_test_client(&amal_wallet).await;

// test that adding the new installation(s), worked
let new_installations_count = group.add_missing_installations(&provider).await.unwrap();
assert_eq!(new_installations_count, 1);
let new_installations_were_added = group.add_missing_installations(provider).await;
assert!(new_installations_were_added.is_ok());
}

#[tokio::test]
Expand Down
21 changes: 9 additions & 12 deletions xmtp_mls/src/groups/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ where
{
pub async fn sync(&self) -> Result<(), GroupError> {
let conn = &mut self.client.store.conn()?;
let provider = self.client.mls_provider(&conn);

Check warning on line 66 in xmtp_mls/src/groups/sync.rs

View workflow job for this annotation

GitHub Actions / workspace

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> xmtp_mls/src/groups/sync.rs:66:49 | 66 | let provider = self.client.mls_provider(&conn); | ^^^^^ help: change this to: `conn` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
self.add_missing_installations(provider).await?;
self.update_latest_installation_list_timestamp(conn).await?;
self.sync_with_conn(conn).await
}

Expand Down Expand Up @@ -623,7 +626,6 @@ where
Ok(())
}

#[allow(dead_code)]
pub(super) async fn get_missing_members(
&self,
provider: &XmtpOpenMlsProvider<'_>,
Expand Down Expand Up @@ -689,29 +691,24 @@ where
Ok((to_add, vec![]))
}

#[allow(dead_code)]
pub(super) async fn add_missing_installations(
&self,
provider: &XmtpOpenMlsProvider<'_>,
) -> Result<usize, GroupError> {
let (missing_members, _placeholder) = self.get_missing_members(provider).await?;
provider: XmtpOpenMlsProvider<'_>,
) -> Result<(), GroupError> {
let (missing_members, _placeholder) = self.get_missing_members(&provider).await?;
if missing_members.is_empty() {
return Ok(0);
return Ok(());
}
let new_member_installations_count = missing_members.len();
self.add_members_by_installation_id(missing_members).await?;

Ok(new_member_installations_count)
Ok(())
}

#[allow(dead_code)]
pub(super) async fn update_latest_installation_list_timestamp(
&self,
conn: &DbConnection<'_>,
) -> Result<(), GroupError> {
let group_id = self.group_id.clone();
let _updated_at = conn.update_installation_list_time_checked(group_id)?;

let _updated_at = conn.update_installation_list_time_checked(self.group_id.clone())?;
Ok(())
}

Expand Down

0 comments on commit 43bc889

Please sign in to comment.