Skip to content

Commit

Permalink
Reduce duplication of maybe_update_installations
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Oct 2, 2024
1 parent 71478f1 commit bb75ed4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
7 changes: 6 additions & 1 deletion xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use xmtp_proto::xmtp::mls::api::v1::{

use crate::{
api::ApiClientWrapper,
configuration::SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
groups::{
group_permissions::PolicySet, validated_commit::CommitValidationError, GroupError,
GroupMetadataOptions, IntentError, MlsGroup,
Expand Down Expand Up @@ -756,7 +757,11 @@ where
);
if mls_group.is_active() {
group
.maybe_update_installations(provider_ref, None, self)
.maybe_update_installations(
provider_ref,
SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
self,
)
.await?;

group.sync_with_conn(provider_ref, self).await?;
Expand Down
15 changes: 8 additions & 7 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,6 @@ impl MlsGroup {
{
let conn = self.context.store.conn()?;
let provider = XmtpOpenMlsProvider::from(conn);
let update_interval_ns = Some(SEND_MESSAGE_UPDATE_INSTALLATIONS_INTERVAL_NS);
self.maybe_update_installations(&provider, update_interval_ns, client)
.await?;
self.sync_until_last_intent_resolved(&provider, client)
.await?;

Expand All @@ -506,6 +503,7 @@ impl MlsGroup {
}

/// Update group installations
#[cfg(test)]
pub async fn update_installations<ApiClient>(
&self,
client: &Client<ApiClient>,
Expand All @@ -515,7 +513,7 @@ impl MlsGroup {
{
let conn = self.context.store.conn()?;
let provider = XmtpOpenMlsProvider::from(conn);
self.maybe_update_installations(&provider, Some(0), client)
self.maybe_update_installations(&provider, 0 /*interval_ns*/, client)
.await?;
Ok(())
}
Expand Down Expand Up @@ -1042,9 +1040,12 @@ impl MlsGroup {
}

let provider: XmtpOpenMlsProvider = conn.into();
let update_interval_ns = Some(SEND_MESSAGE_UPDATE_INSTALLATIONS_INTERVAL_NS);
self.maybe_update_installations(&provider, update_interval_ns, client)
.await?;
self.maybe_update_installations(
&provider,
SEND_MESSAGE_UPDATE_INSTALLATIONS_INTERVAL_NS,
client,
)
.await?;

Ok(PreIntentComplete {})
}
Expand Down
16 changes: 7 additions & 9 deletions xmtp_mls/src/groups/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ impl MlsGroup {
client.inbox_id(),
self.load_mls_group(&mls_provider)?.epoch()
);
self.maybe_update_installations(&mls_provider, None, client)
.await?;
self.maybe_update_installations(
&mls_provider,
SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
client,
)
.await?;

self.sync_with_conn(&mls_provider, client).await
}
Expand Down Expand Up @@ -979,18 +983,12 @@ impl MlsGroup {
pub async fn maybe_update_installations<ApiClient>(
&self,
provider: &XmtpOpenMlsProvider,
update_interval_ns: Option<i64>,
interval_ns: i64,
client: &Client<ApiClient>,
) -> Result<(), GroupError>
where
ApiClient: XmtpApi,
{
// determine how long of an interval in time to use before updating list
let interval_ns = match update_interval_ns {
Some(val) => val,
None => SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
};

let now_ns = crate::utils::time::now_ns();
let last_ns = provider
.conn_ref()
Expand Down

0 comments on commit bb75ed4

Please sign in to comment.