Skip to content

Commit

Permalink
Add a MsgQueryArgs struct (#1183)
Browse files Browse the repository at this point in the history
* MsgQueryArgs

* lint
  • Loading branch information
codabrink authored Oct 24, 2024
1 parent 330e2ef commit 13ec55c
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 273 deletions.
13 changes: 7 additions & 6 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use xmtp_id::{
},
InboxId,
};
use xmtp_mls::storage::group_message::MsgQueryArgs;
use xmtp_mls::storage::group_message::SortDirection;
use xmtp_mls::{
api::ApiClientWrapper,
Expand Down Expand Up @@ -1222,12 +1223,12 @@ impl FfiConversation {

let messages: Vec<FfiMessage> = group
.find_messages(
None,
opts.sent_before_ns,
opts.sent_after_ns,
delivery_status,
opts.limit,
direction,
&MsgQueryArgs::default()
.maybe_sent_before_ns(opts.sent_before_ns)
.maybe_sent_after_ns(opts.sent_after_ns)
.maybe_delivery_status(delivery_status)
.maybe_limit(opts.limit)
.maybe_direction(direction),
)?
.into_iter()
.map(|msg| msg.into())
Expand Down
22 changes: 12 additions & 10 deletions bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use napi::{
JsFunction,
};
use xmtp_cryptography::signature::ed25519_public_key_to_address;
use xmtp_mls::groups::{
group_metadata::{ConversationType, GroupMetadata},
members::PermissionLevel,
MlsGroup, UpdateAdminListType,
use xmtp_mls::{
groups::{
group_metadata::{ConversationType, GroupMetadata},
members::PermissionLevel,
MlsGroup, UpdateAdminListType,
},
storage::group_message::MsgQueryArgs,
};
use xmtp_proto::xmtp::mls::message_contents::EncodedContent;

Expand Down Expand Up @@ -167,12 +170,11 @@ impl NapiGroup {

let messages: Vec<NapiMessage> = group
.find_messages(
None,
opts.sent_before_ns,
opts.sent_after_ns,
delivery_status,
opts.limit,
None,
&MsgQueryArgs::default()
.maybe_sent_before_ns(opts.sent_before_ns)
.maybe_sent_after_ns(opts.sent_after_ns)
.maybe_delivery_status(delivery_status)
.maybe_limit(opts.limit),
)
.map_err(ErrorWrapper::from)?
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions bindings_wasm/src/groups.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;
use wasm_bindgen::JsValue;
use wasm_bindgen::{prelude::wasm_bindgen, JsError};
use xmtp_mls::storage::group_message::MsgQueryArgs;

use crate::encoded_content::WasmEncodedContent;
use crate::messages::{WasmListMessagesOptions, WasmMessage};
Expand Down Expand Up @@ -189,12 +190,11 @@ impl WasmGroup {

let messages: Vec<WasmMessage> = group
.find_messages(
None,
opts.sent_before_ns,
opts.sent_after_ns,
delivery_status,
opts.limit,
None,
&MsgQueryArgs::default()
.maybe_sent_before_ns(opts.sent_before_ns)
.maybe_sent_after_ns(opts.sent_after_ns)
.maybe_delivery_status(delivery_status)
.maybe_limit(opts.limit),
)
.map_err(|e| JsError::new(&format!("{e}")))?
.into_iter()
Expand Down
15 changes: 3 additions & 12 deletions examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use prost::Message;
use xmtp_id::associations::unverified::{UnverifiedRecoverableEcdsaSignature, UnverifiedSignature};
use xmtp_mls::client::FindGroupParams;
use xmtp_mls::groups::message_history::MessageHistoryContent;
use xmtp_mls::storage::group_message::GroupMessageKind;
use xmtp_mls::storage::group_message::{GroupMessageKind, MsgQueryArgs};

use crate::{
json_logger::make_value,
Expand Down Expand Up @@ -253,9 +253,7 @@ async fn main() {
.await
.expect("failed to get group");

let messages = group
.find_messages(None, None, None, None, None, None)
.unwrap();
let messages = group.find_messages(&MsgQueryArgs::default()).unwrap();
if cli.json {
let json_serializable_messages = messages
.iter()
Expand Down Expand Up @@ -388,14 +386,7 @@ async fn main() {
let group_id_str = hex::encode(group.group_id.clone());
group.sync().await.unwrap();
let messages = group
.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))
.unwrap();
info!("Listing history sync messages", { group_id: group_id_str, messages: messages.len()});
for message in messages {
Expand Down
25 changes: 7 additions & 18 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ pub(crate) mod tests {
identity::serialize_key_package_hash_ref,
storage::{
consent_record::{ConsentState, ConsentType, StoredConsentRecord},
group_message::MsgQueryArgs,
schema::identity_updates,
},
XmtpApi,
Expand Down Expand Up @@ -1165,14 +1166,10 @@ pub(crate) mod tests {

let bo_groups = bo.find_groups(FindGroupParams::default()).unwrap();
let bo_group1 = bo.group(alix_bo_group1.clone().group_id).unwrap();
let bo_messages1 = bo_group1
.find_messages(None, None, None, None, None, None)
.unwrap();
let bo_messages1 = bo_group1.find_messages(&MsgQueryArgs::default()).unwrap();
assert_eq!(bo_messages1.len(), 0);
let bo_group2 = bo.group(alix_bo_group2.clone().group_id).unwrap();
let bo_messages2 = bo_group2
.find_messages(None, None, None, None, None, None)
.unwrap();
let bo_messages2 = bo_group2.find_messages(&MsgQueryArgs::default()).unwrap();
assert_eq!(bo_messages2.len(), 0);
alix_bo_group1
.send_message(vec![1, 2, 3].as_slice())
Expand All @@ -1185,14 +1182,10 @@ pub(crate) mod tests {

bo.sync_all_groups(bo_groups).await.unwrap();

let bo_messages1 = bo_group1
.find_messages(None, None, None, None, None, None)
.unwrap();
let bo_messages1 = bo_group1.find_messages(&MsgQueryArgs::default()).unwrap();
assert_eq!(bo_messages1.len(), 1);
let bo_group2 = bo.group(alix_bo_group2.clone().group_id).unwrap();
let bo_messages2 = bo_group2
.find_messages(None, None, None, None, None, None)
.unwrap();
let bo_messages2 = bo_group2.find_messages(&MsgQueryArgs::default()).unwrap();
assert_eq!(bo_messages2.len(), 1);
}

Expand Down Expand Up @@ -1254,9 +1247,7 @@ pub(crate) mod tests {
// assert!(!bola_group.is_active().unwrap());

// Bola should have one readable message (them being added to the group)
let mut bola_messages = bola_group
.find_messages(None, None, None, None, None, None)
.unwrap();
let mut bola_messages = bola_group.find_messages(&MsgQueryArgs::default()).unwrap();

assert_eq!(bola_messages.len(), 1);

Expand All @@ -1276,9 +1267,7 @@ pub(crate) mod tests {
// Sync Bola's state to get the latest
bola_group.sync().await.unwrap();
// Find Bola's updated list of messages
bola_messages = bola_group
.find_messages(None, None, None, None, None, None)
.unwrap();
bola_messages = bola_group.find_messages(&MsgQueryArgs::default()).unwrap();
// Bola should have been able to decrypt the last message
assert_eq!(bola_messages.len(), 2);
assert_eq!(
Expand Down
81 changes: 15 additions & 66 deletions xmtp_mls/src/groups/message_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use xmtp_proto::{
use super::group_metadata::ConversationType;
use super::{GroupError, MlsGroup};

use crate::storage::group_message::MsgQueryArgs;
use crate::XmtpApi;
use crate::{
client::ClientError,
Expand Down Expand Up @@ -156,14 +157,8 @@ where
// sync the group
sync_group.sync().await?;

let messages = sync_group.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)?;
let messages = sync_group
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))?;

let last_message = messages.last();
if let Some(msg) = last_message {
Expand Down Expand Up @@ -215,14 +210,8 @@ where
// sync the group
Box::pin(sync_group.sync()).await?;

let messages = sync_group.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)?;
let messages = sync_group
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))?;

let last_message = match messages.last() {
Some(msg) => {
Expand Down Expand Up @@ -284,14 +273,8 @@ where
// sync the group
sync_group.sync().await?;

let messages = sync_group.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)?;
let messages = sync_group
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))?;
let last_message = messages.last();

let history_request: Option<(String, String)> = if let Some(msg) = last_message {
Expand Down Expand Up @@ -333,14 +316,8 @@ where
// sync the group
sync_group.sync().await?;

let messages = sync_group.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)?;
let messages = sync_group
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))?;

let last_message = messages.last();

Expand Down Expand Up @@ -409,14 +386,8 @@ where
pin_code: &str,
) -> Result<(), MessageHistoryError> {
let sync_group = self.get_sync_group()?;
let requests = sync_group.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)?;
let requests = sync_group
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))?;
let request = requests.into_iter().find(|msg| {
let message_history_content =
serde_json::from_slice::<MessageHistoryContent>(&msg.decrypted_message_bytes);
Expand Down Expand Up @@ -521,7 +492,7 @@ where
let mut all_messages: Vec<StoredGroupMessage> = vec![];

for StoredGroup { id, .. } in groups.into_iter() {
let messages = conn.get_group_messages(id, None, None, None, None, None, None)?;
let messages = conn.get_group_messages(&id, &MsgQueryArgs::default())?;
all_messages.extend(messages);
}

Expand Down Expand Up @@ -865,14 +836,7 @@ pub(crate) mod tests {
// make sure there's only 1 message in the sync group
let sync_group = client.get_sync_group().unwrap();
let messages = sync_group
.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))
.unwrap();
assert_eq!(messages.len(), 1);
}
Expand Down Expand Up @@ -917,14 +881,7 @@ pub(crate) mod tests {
// make sure there's 2 messages in the sync group
let sync_group = client.get_sync_group().unwrap();
let messages = sync_group
.find_messages(
Some(GroupMessageKind::Application),
None,
None,
None,
None,
None,
)
.find_messages(&MsgQueryArgs::default().kind(GroupMessageKind::Application))
.unwrap();
assert_eq!(messages.len(), 2);
}
Expand Down Expand Up @@ -1074,15 +1031,7 @@ pub(crate) mod tests {

let amal_b_conn = amal_b.store().conn().unwrap();
let amal_b_messages = amal_b_conn
.get_group_messages(
amal_b_sync_group.group_id,
None,
None,
None,
None,
None,
None,
)
.get_group_messages(&amal_b_sync_group.group_id, &MsgQueryArgs::default())
.unwrap();

assert_eq!(amal_b_messages.len(), 1);
Expand Down
Loading

0 comments on commit 13ec55c

Please sign in to comment.