diff --git a/bindings_node/CHANGELOG.md b/bindings_node/CHANGELOG.md index 3d8f6c5a9..ec6028421 100644 --- a/bindings_node/CHANGELOG.md +++ b/bindings_node/CHANGELOG.md @@ -1,5 +1,11 @@ # @xmtp/node-bindings +## 0.0.19 + +- Renamed `Level` to `LogLevel` +- Filtered out group membership messages from DM groups +- Fixed `syncAllConversations` export + ## 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_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<()> { 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/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 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_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) 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", 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)