From c5538e73945490a076bb04fd4b1c0d55017ea0e8 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Thu, 14 Nov 2024 21:49:31 -0600 Subject: [PATCH 1/5] Filter membership change messages in dm groups --- bindings_node/src/conversation.rs | 29 +++++++++++++++-------------- bindings_node/src/message.rs | 16 +++++++++++++++- bindings_wasm/src/conversation.rs | 15 ++++++++++++++- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/bindings_node/src/conversation.rs b/bindings_node/src/conversation.rs index 9caf28b69..aeeffa6b1 100644 --- a/bindings_node/src/conversation.rs +++ b/bindings_node/src/conversation.rs @@ -11,7 +11,10 @@ use xmtp_mls::{ group_metadata::GroupMetadata as XmtpGroupMetadata, members::PermissionLevel as XmtpPermissionLevel, MlsGroup, UpdateAdminListType, }, - storage::{group::ConversationType, group_message::MsgQueryArgs}, + storage::{ + group::ConversationType, + group_message::{GroupMessageKind as XmtpGroupMessageKind, MsgQueryArgs}, + }, }; use xmtp_proto::xmtp::mls::message_contents::EncodedContent as XmtpEncodedContent; @@ -158,25 +161,23 @@ impl Conversation { #[napi] pub fn find_messages(&self, opts: Option) -> Result> { let opts = opts.unwrap_or_default(); - let group = MlsGroup::new( self.inner_client.clone(), self.group_id.clone(), self.created_at_ns, ); - - let delivery_status = opts.delivery_status.map(|status| status.into()); - let direction = opts.direction.map(|dir| dir.into()); - + let provider = group.mls_provider().map_err(ErrorWrapper::from)?; + let conversation_type = group + .conversation_type(&provider) + .map_err(ErrorWrapper::from)?; + let kind = match conversation_type { + ConversationType::Group => None, + ConversationType::Dm => Some(XmtpGroupMessageKind::Application), + ConversationType::Sync => None, + }; + let opts: MsgQueryArgs = opts.into(); let messages: Vec = group - .find_messages( - &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), - ) + .find_messages(&opts.maybe_kind(kind)) .map_err(ErrorWrapper::from)? .into_iter() .map(|msg| msg.into()) diff --git a/bindings_node/src/message.rs b/bindings_node/src/message.rs index ad54390f6..fbe3975b5 100644 --- a/bindings_node/src/message.rs +++ b/bindings_node/src/message.rs @@ -1,7 +1,7 @@ use napi::bindgen_prelude::Uint8Array; use prost::Message as ProstMessage; use xmtp_mls::storage::group_message::{ - DeliveryStatus as XmtpDeliveryStatus, GroupMessageKind as XmtpGroupMessageKind, + DeliveryStatus as XmtpDeliveryStatus, GroupMessageKind as XmtpGroupMessageKind, MsgQueryArgs, SortDirection as XmtpSortDirection, StoredGroupMessage, }; @@ -77,6 +77,20 @@ pub struct ListMessagesOptions { pub direction: Option, } +impl From for MsgQueryArgs { + fn from(opts: ListMessagesOptions) -> MsgQueryArgs { + let delivery_status = opts.delivery_status.map(Into::into); + let direction = opts.direction.map(Into::into); + + 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) + } +} + #[napi(object)] pub struct Message { pub id: String, diff --git a/bindings_wasm/src/conversation.rs b/bindings_wasm/src/conversation.rs index 0c892e4d1..9c7a1e090 100644 --- a/bindings_wasm/src/conversation.rs +++ b/bindings_wasm/src/conversation.rs @@ -12,6 +12,7 @@ use xmtp_mls::groups::{ group_metadata::GroupMetadata as XmtpGroupMetadata, members::PermissionLevel as XmtpPermissionLevel, MlsGroup, UpdateAdminListType, }; +use xmtp_mls::storage::group_message::{GroupMessageKind as XmtpGroupMessageKind, MsgQueryArgs}; use xmtp_proto::xmtp::mls::message_contents::EncodedContent as XmtpEncodedContent; use prost::Message as ProstMessage; @@ -182,8 +183,20 @@ impl Conversation { pub fn find_messages(&self, opts: Option) -> Result, JsError> { let opts = opts.unwrap_or_default(); let group = self.to_mls_group(); + let provider = group + .mls_provider() + .map_err(|e| JsError::new(&format!("{e}")))?; + let conversation_type = group + .conversation_type(&provider) + .map_err(|e| JsError::new(&format!("{e}")))?; + let kind = match conversation_type { + ConversationType::Group => None, + ConversationType::Dm => Some(XmtpGroupMessageKind::Application), + ConversationType::Sync => None, + }; + let opts: MsgQueryArgs = opts.into(); let messages: Vec = group - .find_messages(&opts.into()) + .find_messages(&opts.maybe_kind(kind)) .map_err(|e| JsError::new(&format!("{e}")))? .into_iter() .map(Into::into) From 9d0410a8575d3c6de66e45013e688a533278b560 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Thu, 14 Nov 2024 21:51:03 -0600 Subject: [PATCH 2/5] Level => LogLevel --- bindings_node/src/client.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings_node/src/client.rs b/bindings_node/src/client.rs index 6ae6a8e25..2011ab782 100644 --- a/bindings_node/src/client.rs +++ b/bindings_node/src/client.rs @@ -43,7 +43,7 @@ impl Client { #[napi(string_enum)] #[derive(Debug)] #[allow(non_camel_case_types)] -pub enum Level { +pub enum LogLevel { off, error, warn, @@ -52,9 +52,9 @@ pub enum Level { trace, } -impl std::fmt::Display for Level { +impl std::fmt::Display for LogLevel { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use Level::*; + use LogLevel::*; let s = match self { off => "off", error => "error", @@ -75,7 +75,7 @@ pub struct LogOptions { /// an option so that it does not require being specified in js object. pub structured: Option, /// Filter logs by level - pub level: Option, + pub level: Option, } fn init_logging(options: LogOptions) -> Result<()> { From 9565c046496cc860a239cd26f6f2dd3f81f02b8a Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 15 Nov 2024 00:37:28 -0600 Subject: [PATCH 3/5] Prepare releases --- bindings_node/CHANGELOG.md | 5 +++++ bindings_node/package.json | 2 +- bindings_wasm/CHANGELOG.md | 4 ++++ bindings_wasm/package.json | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bindings_node/CHANGELOG.md b/bindings_node/CHANGELOG.md index 3d8f6c5a9..0d15f85d6 100644 --- a/bindings_node/CHANGELOG.md +++ b/bindings_node/CHANGELOG.md @@ -1,5 +1,10 @@ # @xmtp/node-bindings +## 0.0.19 + +- Renamed `Level` to `LogLevel` +- Filtered out group membership messages from DM groups + ## 0.0.18 - Added `syncAllConversations` to `Conversations` diff --git a/bindings_node/package.json b/bindings_node/package.json index c383c6230..fd7ad00d8 100644 --- a/bindings_node/package.json +++ b/bindings_node/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/node-bindings", - "version": "0.0.18", + "version": "0.0.19", "repository": { "type": "git", "url": "git+https://git@github.com/xmtp/libxmtp.git", diff --git a/bindings_wasm/CHANGELOG.md b/bindings_wasm/CHANGELOG.md index 2d75bbae0..ae7da1394 100644 --- a/bindings_wasm/CHANGELOG.md +++ b/bindings_wasm/CHANGELOG.md @@ -1,5 +1,9 @@ # @xmtp/wasm-bindings +## 0.0.5 + +- Filtered out group membership messages from DM groups + ## 0.0.4 - Added smart contract wallet signature support diff --git a/bindings_wasm/package.json b/bindings_wasm/package.json index 405b2992f..e799e8cf2 100644 --- a/bindings_wasm/package.json +++ b/bindings_wasm/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/wasm-bindings", - "version": "0.0.4", + "version": "0.0.5", "type": "module", "license": "MIT", "description": "WASM bindings for the libXMTP rust library", From e934c2e12ef34d94cdb11e6c5f62a58c2a62d588 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 19 Nov 2024 09:37:21 -0600 Subject: [PATCH 4/5] Add sync_all_conversations to NAPI exports --- bindings_node/CHANGELOG.md | 1 + bindings_node/src/conversations.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/bindings_node/CHANGELOG.md b/bindings_node/CHANGELOG.md index 0d15f85d6..ec6028421 100644 --- a/bindings_node/CHANGELOG.md +++ b/bindings_node/CHANGELOG.md @@ -4,6 +4,7 @@ - Renamed `Level` to `LogLevel` - Filtered out group membership messages from DM groups +- Fixed `syncAllConversations` export ## 0.0.18 diff --git a/bindings_node/src/conversations.rs b/bindings_node/src/conversations.rs index 2babb9007..24b618a40 100644 --- a/bindings_node/src/conversations.rs +++ b/bindings_node/src/conversations.rs @@ -248,6 +248,7 @@ impl Conversations { Ok(()) } + #[napi] pub async fn sync_all_conversations(&self) -> Result { let groups = self .inner_client From 55d4d4d957cd6c4fdcd9e822f7032882c6415dd0 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 19 Nov 2024 09:52:54 -0600 Subject: [PATCH 5/5] Fix test --- bindings_node/test/Conversations.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings_node/test/Conversations.test.ts b/bindings_node/test/Conversations.test.ts index 3b4b40a04..951aa61df 100644 --- a/bindings_node/test/Conversations.test.ts +++ b/bindings_node/test/Conversations.test.ts @@ -105,7 +105,7 @@ describe('Conversations', () => { updateGroupPinnedFrameUrlPolicy: 0, }) expect(group.addedByInboxId()).toBe(client1.inboxId()) - expect(group.findMessages().length).toBe(1) + expect(group.findMessages().length).toBe(0) const members = await group.listMembers() expect(members.length).toBe(2) const memberInboxIds = members.map((member) => member.inboxId)