From d42e315bc17160fc24decc9433a70e3438e319b0 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 19 Dec 2024 12:36:30 -0800 Subject: [PATCH] add test --- xmtp_content_types/src/lib.rs | 2 +- xmtp_content_types/src/reaction.rs | 1 - xmtp_content_types/src/read_receipt.rs | 1 - xmtp_content_types/src/remote_attachment.rs | 1 - xmtp_content_types/src/reply.rs | 1 - .../src/transaction_reference.rs | 1 - .../storage/encrypted_store/group_message.rs | 78 +++++++++++++++++++ 7 files changed, 79 insertions(+), 6 deletions(-) diff --git a/xmtp_content_types/src/lib.rs b/xmtp_content_types/src/lib.rs index c0fe8fb42..727a5374f 100644 --- a/xmtp_content_types/src/lib.rs +++ b/xmtp_content_types/src/lib.rs @@ -1,9 +1,9 @@ pub mod group_updated; pub mod membership_change; pub mod reaction; -pub mod reply; pub mod read_receipt; pub mod remote_attachment; +pub mod reply; pub mod text; pub mod transaction_reference; diff --git a/xmtp_content_types/src/reaction.rs b/xmtp_content_types/src/reaction.rs index 50a89ebce..be03f5465 100644 --- a/xmtp_content_types/src/reaction.rs +++ b/xmtp_content_types/src/reaction.rs @@ -1,6 +1,5 @@ pub struct ReactionCodec {} impl ReactionCodec { - const AUTHORITY_ID: &'static str = "xmtp.org"; pub const TYPE_ID: &'static str = "reaction"; } diff --git a/xmtp_content_types/src/read_receipt.rs b/xmtp_content_types/src/read_receipt.rs index a81a2b7ad..bd72e02cf 100644 --- a/xmtp_content_types/src/read_receipt.rs +++ b/xmtp_content_types/src/read_receipt.rs @@ -1,6 +1,5 @@ pub struct ReadReceiptCodec {} impl ReadReceiptCodec { - const AUTHORITY_ID: &'static str = "xmtp.org"; pub const TYPE_ID: &'static str = "read_receipt"; } diff --git a/xmtp_content_types/src/remote_attachment.rs b/xmtp_content_types/src/remote_attachment.rs index 77680aefe..6cd7ac38d 100644 --- a/xmtp_content_types/src/remote_attachment.rs +++ b/xmtp_content_types/src/remote_attachment.rs @@ -1,6 +1,5 @@ pub struct RemoteAttachmentCodec {} impl RemoteAttachmentCodec { - const AUTHORITY_ID: &'static str = "xmtp.org"; pub const TYPE_ID: &'static str = "remote_attachment"; } diff --git a/xmtp_content_types/src/reply.rs b/xmtp_content_types/src/reply.rs index 6f8ba32f3..bdc0c5add 100644 --- a/xmtp_content_types/src/reply.rs +++ b/xmtp_content_types/src/reply.rs @@ -1,6 +1,5 @@ pub struct ReplyCodec {} impl ReplyCodec { - const AUTHORITY_ID: &'static str = "xmtp.org"; pub const TYPE_ID: &'static str = "reply"; } diff --git a/xmtp_content_types/src/transaction_reference.rs b/xmtp_content_types/src/transaction_reference.rs index c7060dc88..0f7898dcf 100644 --- a/xmtp_content_types/src/transaction_reference.rs +++ b/xmtp_content_types/src/transaction_reference.rs @@ -1,6 +1,5 @@ pub struct TransactionReferenceCodec {} impl TransactionReferenceCodec { - const AUTHORITY_ID: &'static str = "xmtp.org"; pub const TYPE_ID: &'static str = "transaction_reference"; } diff --git a/xmtp_mls/src/storage/encrypted_store/group_message.rs b/xmtp_mls/src/storage/encrypted_store/group_message.rs index 9d4178ea2..a452ecc3c 100644 --- a/xmtp_mls/src/storage/encrypted_store/group_message.rs +++ b/xmtp_mls/src/storage/encrypted_store/group_message.rs @@ -186,6 +186,7 @@ pub struct MsgQueryArgs { delivery_status: Option, limit: Option, direction: Option, + content_types: Option>, } impl MsgQueryArgs { @@ -243,6 +244,16 @@ impl MsgQueryArgs { self.limit = limit; self } + + pub fn content_types(mut self, content_types: Vec) -> Self { + self.content_types = Some(content_types); + self + } + + pub fn maybe_content_types(mut self, content_types: Option>) -> Self { + self.content_types = content_types; + self + } } impl DbConnection { @@ -273,6 +284,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()), @@ -577,4 +592,67 @@ pub(crate) mod tests { }) .await } + + #[wasm_bindgen_test(unsupported = tokio::test)] + async fn it_gets_messages_by_content_type() { + with_connection(|conn| { + let group = generate_group(None); + group.store(conn).unwrap(); + + let messages = vec![ + generate_message(None, Some(&group.id), Some(1_000), Some(ContentType::Text)), + generate_message( + None, + Some(&group.id), + Some(2_000), + Some(ContentType::GroupMembershipChange), + ), + generate_message( + None, + Some(&group.id), + Some(3_000), + Some(ContentType::GroupUpdated), + ), + ]; + assert_ok!(messages.store(conn)); + + // Query for text messages + let text_messages = conn + .get_group_messages( + &group.id, + &MsgQueryArgs::default().content_types(vec![ContentType::Text]), + ) + .unwrap(); + assert_eq!(text_messages.len(), 1); + assert_eq!(text_messages[0].content_type, ContentType::Text); + assert_eq!(text_messages[0].sent_at_ns, 1_000); + + // Query for membership change messages + let membership_messages = conn + .get_group_messages( + &group.id, + &MsgQueryArgs::default() + .content_types(vec![ContentType::GroupMembershipChange]), + ) + .unwrap(); + assert_eq!(membership_messages.len(), 1); + assert_eq!( + membership_messages[0].content_type, + ContentType::GroupMembershipChange + ); + assert_eq!(membership_messages[0].sent_at_ns, 2_000); + + // Query for group updated messages + let updated_messages = conn + .get_group_messages( + &group.id, + &MsgQueryArgs::default().content_types(vec![ContentType::GroupUpdated]), + ) + .unwrap(); + assert_eq!(updated_messages.len(), 1); + assert_eq!(updated_messages[0].content_type, ContentType::GroupUpdated); + assert_eq!(updated_messages[0].sent_at_ns, 3_000); + }) + .await + } }