Skip to content

Commit

Permalink
Bindings for the DM peer inbox id (#1197)
Browse files Browse the repository at this point in the history
* add ffi bindings for the dm peer inbox id

* add a test for it

* fix up the test

* fix up lint
  • Loading branch information
nplasterer authored Oct 29, 2024
1 parent 3548d30 commit 257063e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,10 @@ impl FfiConversation {
inner: Arc::new(metadata),
}))
}

pub fn dm_peer_inbox_id(&self) -> Result<String, GenericError> {
self.inner.dm_inbox_id().map_err(Into::into)
}
}

#[uniffi::export]
Expand Down Expand Up @@ -3953,6 +3957,27 @@ mod tests {
assert_eq!(bo_updated_consent, FfiConsentState::Allowed);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_get_dm_peer_inbox_id() {
let alix = new_test_client().await;
let bo = new_test_client().await;

let alix_dm = alix
.conversations()
.create_dm(bo.account_address.clone())
.await
.unwrap();

let alix_dm_peer_inbox = alix_dm.dm_peer_inbox_id().unwrap();
assert_eq!(alix_dm_peer_inbox, bo.inbox_id());

bo.conversations().sync().await.unwrap();
let bo_dm = bo.conversation(alix_dm.id()).unwrap();

let bo_dm_peer_inbox = bo_dm.dm_peer_inbox_id().unwrap();
assert_eq!(bo_dm_peer_inbox, alix.inbox_id());
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_set_and_get_member_consent() {
let alix = new_test_client().await;
Expand Down
9 changes: 9 additions & 0 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,15 @@ impl<ScopedClient: ScopedGroupClient> MlsGroup<ScopedClient> {
})
}

/// Find the `inbox_id` of the group member who is the peer of this dm
pub fn dm_inbox_id(&self) -> Result<String, GroupError> {
let conn = self.context().store().conn()?;
let group = conn
.find_group(self.group_id.clone())?
.ok_or(GroupError::GroupNotFound)?;
group.dm_inbox_id.ok_or(GroupError::GroupNotFound)
}

/// Find the `consent_state` of the group
pub fn consent_state(&self) -> Result<ConsentState, GroupError> {
let conn = self.context().store().conn()?;
Expand Down

0 comments on commit 257063e

Please sign in to comment.