Skip to content

Commit

Permalink
add content type filtering to bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 19, 2024
1 parent 507b885 commit e084d61
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ pub struct FfiListMessagesOptions {
pub limit: Option<i64>,
pub delivery_status: Option<FfiDeliveryStatus>,
pub direction: Option<FfiDirection>,
pub content_types: Option<Vec<String>>,
}

#[derive(uniffi::Record, Clone, Default)]
Expand Down
20 changes: 20 additions & 0 deletions xmtp_content_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
Expand All @@ -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",
}
}
}
Expand All @@ -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()),
}
}
Expand Down
5 changes: 5 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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 @@ -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()),
Expand Down

0 comments on commit e084d61

Please sign in to comment.