Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter membership change messages in dm groups (WASM + Node) #1291

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings_node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion bindings_node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xmtp/node-bindings",
"version": "0.0.18",
"version": "0.0.19",
"repository": {
"type": "git",
"url": "git+https://[email protected]/xmtp/libxmtp.git",
Expand Down
8 changes: 4 additions & 4 deletions bindings_node/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -75,7 +75,7 @@ pub struct LogOptions {
/// an option so that it does not require being specified in js object.
pub structured: Option<bool>,
/// Filter logs by level
pub level: Option<Level>,
pub level: Option<LogLevel>,
}

fn init_logging(options: LogOptions) -> Result<()> {
Expand Down
29 changes: 15 additions & 14 deletions bindings_node/src/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -158,25 +161,23 @@ impl Conversation {
#[napi]
pub fn find_messages(&self, opts: Option<ListMessagesOptions>) -> Result<Vec<Message>> {
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<Message> = 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())
Expand Down
1 change: 1 addition & 0 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl Conversations {
Ok(())
}

#[napi]
pub async fn sync_all_conversations(&self) -> Result<usize> {
let groups = self
.inner_client
Expand Down
16 changes: 15 additions & 1 deletion bindings_node/src/message.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down Expand Up @@ -77,6 +77,20 @@ pub struct ListMessagesOptions {
pub direction: Option<SortDirection>,
}

impl From<ListMessagesOptions> 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,
Expand Down
2 changes: 1 addition & 1 deletion bindings_node/test/Conversations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions bindings_wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion bindings_wasm/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 14 additions & 1 deletion bindings_wasm/src/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -182,8 +183,20 @@ impl Conversation {
pub fn find_messages(&self, opts: Option<ListMessagesOptions>) -> Result<Vec<Message>, 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<Message> = group
.find_messages(&opts.into())
.find_messages(&opts.maybe_kind(kind))
.map_err(|e| JsError::new(&format!("{e}")))?
.into_iter()
.map(Into::into)
Expand Down