From e084d6171d69389d2b468e145b5219df7b9e00d7 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 18 Dec 2024 16:53:56 -0800 Subject: [PATCH] add content type filtering to bindings --- bindings_ffi/src/mls.rs | 1 + xmtp_content_types/src/lib.rs | 20 +++++++++++++++++++ .../storage/encrypted_store/group_message.rs | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 4ac46b3c1..3eb4a7d98 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -1258,6 +1258,7 @@ pub struct FfiListMessagesOptions { pub limit: Option, pub delivery_status: Option, pub direction: Option, + pub content_types: Option>, } #[derive(uniffi::Record, Clone, Default)] diff --git a/xmtp_content_types/src/lib.rs b/xmtp_content_types/src/lib.rs index c3453908a..b0c1b609e 100644 --- a/xmtp_content_types/src/lib.rs +++ b/xmtp_content_types/src/lib.rs @@ -25,6 +25,11 @@ pub enum ContentType { Text = 1, GroupMembershipChange = 2, GroupUpdated = 3, + Reaction = 4, + Reply = 5, + ReadReceipt = 6, + RemoteAttachment = 7, + TransactionReference = 8, } impl ContentType { @@ -33,6 +38,11 @@ impl ContentType { text::TextCodec::TYPE_ID => Self::Text, membership_change::GroupMembershipChangeCodec::TYPE_ID => Self::GroupMembershipChange, group_updated::GroupUpdatedCodec::TYPE_ID => Self::GroupUpdated, + "reaction" => Self::Reaction, + "reply" => Self::Reply, + "read_receipt" => Self::ReadReceipt, + "remote_attachment" => Self::RemoteAttachment, + "transaction_reference" => Self::TransactionReference, _ => Self::Unknown, } } @@ -43,6 +53,11 @@ impl ContentType { Self::Text => text::TextCodec::TYPE_ID, Self::GroupMembershipChange => membership_change::GroupMembershipChangeCodec::TYPE_ID, Self::GroupUpdated => group_updated::GroupUpdatedCodec::TYPE_ID, + Self::Reaction => "reaction", + Self::Reply => "reply", + Self::ReadReceipt => "read_receipt", + Self::RemoteAttachment => "remote_attachment", + Self::TransactionReference => "transaction_reference", } } } @@ -67,6 +82,11 @@ where 1 => Ok(ContentType::Text), 2 => Ok(ContentType::GroupMembershipChange), 3 => Ok(ContentType::GroupUpdated), + 4 => Ok(ContentType::Reaction), + 5 => Ok(ContentType::Reply), + 6 => Ok(ContentType::ReadReceipt), + 7 => Ok(ContentType::RemoteAttachment), + 8 => Ok(ContentType::TransactionReference), x => Err(format!("Unrecognized variant {}", x).into()), } } diff --git a/xmtp_mls/src/storage/encrypted_store/group_message.rs b/xmtp_mls/src/storage/encrypted_store/group_message.rs index 75ee41213..ec509d93c 100644 --- a/xmtp_mls/src/storage/encrypted_store/group_message.rs +++ b/xmtp_mls/src/storage/encrypted_store/group_message.rs @@ -131,6 +131,7 @@ pub struct MsgQueryArgs { delivery_status: Option, limit: Option, direction: Option, + content_types: Option>, } impl MsgQueryArgs { @@ -218,6 +219,10 @@ impl DbConnection { query = query.filter(dsl::delivery_status.eq(status)); } + if let Some(content_types) = &args.content_types { + query = query.filter(dsl::content_type.eq_any(content_types)); + } + query = match args.direction.as_ref().unwrap_or(&SortDirection::Ascending) { SortDirection::Ascending => query.order(dsl::sent_at_ns.asc()), SortDirection::Descending => query.order(dsl::sent_at_ns.desc()),