From 43bc8896e58017af0a3c8f73ee227c7181949df9 Mon Sep 17 00:00:00 2001 From: tuddman Date: Thu, 8 Feb 2024 14:01:41 +0100 Subject: [PATCH] feat: adds missing installations when group is synced (#492) --- rustfmt.toml | 2 +- xmtp_mls/src/groups/mod.rs | 4 ++-- xmtp_mls/src/groups/sync.rs | 21 +++++++++------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index c3c8c3753..44148a2d3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -imports_granularity = "Crate" +reorder_imports = true diff --git a/xmtp_mls/src/groups/mod.rs b/xmtp_mls/src/groups/mod.rs index c5eb4b442..db8ca3f28 100644 --- a/xmtp_mls/src/groups/mod.rs +++ b/xmtp_mls/src/groups/mod.rs @@ -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] diff --git a/xmtp_mls/src/groups/sync.rs b/xmtp_mls/src/groups/sync.rs index a58587fa0..8f486e0ba 100644 --- a/xmtp_mls/src/groups/sync.rs +++ b/xmtp_mls/src/groups/sync.rs @@ -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); + self.add_missing_installations(provider).await?; + self.update_latest_installation_list_timestamp(conn).await?; self.sync_with_conn(conn).await } @@ -623,7 +626,6 @@ where Ok(()) } - #[allow(dead_code)] pub(super) async fn get_missing_members( &self, provider: &XmtpOpenMlsProvider<'_>, @@ -689,29 +691,24 @@ where Ok((to_add, vec![])) } - #[allow(dead_code)] pub(super) async fn add_missing_installations( &self, - provider: &XmtpOpenMlsProvider<'_>, - ) -> Result { - 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(()) }