diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 36308ada1..117d8ae9e 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -242,6 +242,15 @@ impl FfiXmtpClient { }) } + pub fn group(&self, group_id: Vec) -> Result { + let convo = self.inner_client.group(group_id)?; + Ok(FfiGroup { + inner_client: self.inner_client.clone(), + group_id: convo.group_id, + created_at_ns: convo.created_at_ns, + }) + } + pub async fn can_message( &self, account_addresses: Vec, @@ -264,6 +273,13 @@ impl FfiXmtpClient { pub async fn db_reconnect(&self) -> Result<(), GenericError> { Ok(self.inner_client.reconnect_db()?) } + + pub async fn find_inbox_id(&self, address: String) -> Result, GenericError> { + let inner = self.inner_client.as_ref(); + + let result = inner.find_inbox_id_from_address(address).await?; + Ok(result) + } } #[uniffi::export(async_runtime = "tokio")] @@ -524,6 +540,17 @@ impl FfiGroup { Ok(()) } + pub async fn message(&self, message_id: Vec) -> Result { + let group = MlsGroup::new( + self.inner_client.context().clone(), + self.group_id.clone(), + self.created_at_ns, + ); + + let message = group.message(message_id)?; + Ok(message.into()) + } + pub fn find_messages( &self, opts: FfiListMessagesOptions, @@ -1575,7 +1602,7 @@ mod tests { .unwrap(); assert_eq!(bo_messages2.len(), second_msg_check); - // TODO: message_callbacks should eventually come through here, why does this + // TODO: message_callbacks should eventually come through here, why does this // not work? // tokio::time::sleep(tokio::time::Duration::from_millis(10000)).await; // assert_eq!(message_callbacks.message_count(), second_msg_check as u32); @@ -1860,7 +1887,7 @@ mod tests { alix_group.send("hello1".as_bytes().to_vec()).await.unwrap(); tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; - + assert_eq!(group_callbacks.message_count(), 1); assert_eq!(message_callbacks.message_count(), 1); diff --git a/xmtp_mls/src/client.rs b/xmtp_mls/src/client.rs index bf55542db..f58c0133c 100644 --- a/xmtp_mls/src/client.rs +++ b/xmtp_mls/src/client.rs @@ -249,6 +249,14 @@ where self.context.inbox_id() } + pub async fn find_inbox_id_from_address( + &self, + address: String, + ) -> Result, ClientError> { + let mut results = self.api_client.get_inbox_ids(vec![address.clone()]).await?; + Ok(results.remove(&address)) + } + /// Get sequence id, may not be consistent with the backend pub fn inbox_sequence_id(&self, conn: &DbConnection) -> Result { self.context.inbox_sequence_id(conn) diff --git a/xmtp_mls/src/groups/mod.rs b/xmtp_mls/src/groups/mod.rs index f826eb902..ccf8b05cd 100644 --- a/xmtp_mls/src/groups/mod.rs +++ b/xmtp_mls/src/groups/mod.rs @@ -81,7 +81,7 @@ use crate::{ group::{GroupMembershipState, Purpose, StoredGroup}, group_intent::{IntentKind, NewGroupIntent}, group_message::{DeliveryStatus, GroupMessageKind, StoredGroupMessage}, - sql_key_store, + sql_key_store, StorageError, }, utils::{id::calculate_message_id, time::now_ns}, xmtp_openmls_provider::XmtpOpenMlsProvider, @@ -487,6 +487,20 @@ impl MlsGroup { Ok(messages) } + /// Look up a message by its ID + /// Returns a [`StoredGroupMessage`] if the message exists, or an error if it does not + pub fn message(&self, message_id: Vec) -> Result { + let conn = self.context.store.conn()?; + let message = conn.get_group_message(&message_id)?; + match message { + Some(message) => Ok(message), + None => Err(GroupError::Storage(StorageError::NotFound(format!( + "message {}", + hex::encode(message_id) + )))), + } + } + /** * Add members to the group by account address *