diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 2a4ffd031..83d0b7a05 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -1416,6 +1416,10 @@ impl FfiConversation { inner: Arc::new(metadata), })) } + + pub fn dm_peer_inbox_id(&self) -> Result { + self.inner.dm_inbox_id().map_err(Into::into) + } } #[uniffi::export] @@ -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; diff --git a/xmtp_mls/src/groups/mod.rs b/xmtp_mls/src/groups/mod.rs index 8d82fc96e..fba87afb2 100644 --- a/xmtp_mls/src/groups/mod.rs +++ b/xmtp_mls/src/groups/mod.rs @@ -1002,6 +1002,15 @@ impl MlsGroup { }) } + /// Find the `inbox_id` of the group member who is the peer of this dm + pub fn dm_inbox_id(&self) -> Result { + 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 { let conn = self.context().store().conn()?;