Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 19, 2024
1 parent 0f32da1 commit d42e315
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xmtp_content_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 0 additions & 1 deletion xmtp_content_types/src/reaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub struct ReactionCodec {}

impl ReactionCodec {
const AUTHORITY_ID: &'static str = "xmtp.org";
pub const TYPE_ID: &'static str = "reaction";
}
1 change: 0 additions & 1 deletion xmtp_content_types/src/read_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub struct ReadReceiptCodec {}

impl ReadReceiptCodec {
const AUTHORITY_ID: &'static str = "xmtp.org";
pub const TYPE_ID: &'static str = "read_receipt";
}
1 change: 0 additions & 1 deletion xmtp_content_types/src/remote_attachment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub struct RemoteAttachmentCodec {}

impl RemoteAttachmentCodec {
const AUTHORITY_ID: &'static str = "xmtp.org";
pub const TYPE_ID: &'static str = "remote_attachment";
}
1 change: 0 additions & 1 deletion xmtp_content_types/src/reply.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub struct ReplyCodec {}

impl ReplyCodec {
const AUTHORITY_ID: &'static str = "xmtp.org";
pub const TYPE_ID: &'static str = "reply";
}
1 change: 0 additions & 1 deletion xmtp_content_types/src/transaction_reference.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub struct TransactionReferenceCodec {}

impl TransactionReferenceCodec {
const AUTHORITY_ID: &'static str = "xmtp.org";
pub const TYPE_ID: &'static str = "transaction_reference";
}
78 changes: 78 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub struct MsgQueryArgs {
delivery_status: Option<DeliveryStatus>,
limit: Option<i64>,
direction: Option<SortDirection>,
content_types: Option<Vec<ContentType>>,
}

impl MsgQueryArgs {
Expand Down Expand Up @@ -243,6 +244,16 @@ impl MsgQueryArgs {
self.limit = limit;
self
}

pub fn content_types(mut self, content_types: Vec<ContentType>) -> Self {
self.content_types = Some(content_types);
self
}

pub fn maybe_content_types(mut self, content_types: Option<Vec<ContentType>>) -> Self {
self.content_types = content_types;
self
}
}

impl DbConnection {
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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
}
}

0 comments on commit d42e315

Please sign in to comment.