Skip to content

Commit

Permalink
add get addresses by inbox id (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx authored Oct 10, 2024
1 parent cebf673 commit 387d033
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,24 @@ impl FfiXmtpClient {
Ok(state.into())
}

/**
* Get the inbox state for each `inbox_id`.
*
* If `refresh_from_network` is true, the client will go to the network first to refresh the state.
* Otherwise, the state will be read from the local database.
*/
pub async fn addresses_from_inbox_id(
&self,
refresh_from_network: bool,
inbox_ids: Vec<String>,
) -> Result<Vec<FfiInboxState>, GenericError> {
let state = self
.inner_client
.inbox_addresses(refresh_from_network, inbox_ids)
.await?;
Ok(state.into_iter().map(Into::into).collect())
}

pub async fn get_latest_inbox_state(
&self,
inbox_id: String,
Expand Down
14 changes: 14 additions & 0 deletions bindings_node/src/mls_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ impl NapiClient {
Ok(state.into())
}

#[napi]
pub async fn addresses_from_inbox_id(
&self,
refresh_from_network: bool,
inbox_ids: Vec<String>,
) -> Result<Vec<NapiInboxState>> {
let state = self
.inner_client
.inbox_addresses(refresh_from_network, inbox_ids)
.await
.map_err(ErrorWrapper::from)?;
Ok(state.into_iter().map(Into::into).collect())
}

#[napi]
pub async fn get_latest_inbox_state(&self, inbox_id: String) -> Result<NapiInboxState> {
let conn = self
Expand Down
24 changes: 24 additions & 0 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,30 @@ where
Ok(state)
}

/// Get the [`AssociationState`] for each `inbox_id`
pub async fn inbox_addresses<InboxId: AsRef<str>>(
&self,
refresh_from_network: bool,
inbox_ids: Vec<InboxId>,
) -> Result<Vec<AssociationState>, ClientError> {
let conn = self.store().conn()?;
if refresh_from_network {
load_identity_updates(
&self.api_client,
&conn,
inbox_ids.iter().map(|s| String::from(s.as_ref())).collect(),
)
.await?;
}
let state = self
.batch_get_association_state(
&conn,
&inbox_ids.into_iter().map(|i| (i, None)).collect::<Vec<_>>(),
)
.await?;
Ok(state)
}

/// Set a consent record in the local database.
/// If the consent record is an address set the consent state for both the address and `inbox_id`
pub async fn set_consent_states(
Expand Down

0 comments on commit 387d033

Please sign in to comment.