Skip to content

Commit c501048

Browse files
authored
Add disappearing message methods to Conversation (WASM) (#1650)
* Update README * Add check:macos script * Remove auto filtering of messages in DM groups * Update JS names of MessageDisappearingSettings fields * Add message filtering methods to groups * Update version and changelog
1 parent 5aad910 commit c501048

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

bindings_wasm/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @xmtp/wasm-bindings
22

3+
## 0.0.16
4+
5+
- Added `isMessageDisappearingEnabled` method to `Conversation`
6+
- Added `messageDisappearingSettings` method to `Conversation`
7+
- Added `removeMessageDisappearingSettings` method to `Conversation`
8+
- Added `messageDisappearingSettings` method to `Conversation`
9+
- Updated JS names for `MessageDisappearingSettings` fields
10+
- Removed automatic filtering of DM group messages
11+
312
## 0.0.15
413

514
- Added `consent_states`, `include_sync_groups`, and `include_duplicate_dms` to `ListConversationsOptions`

bindings_wasm/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
- `yarn`: Installs all dependencies (required before building)
99
- `yarn build`: Build a release version of the WASM bindings for the current platform
1010
- `yarn lint`: Run cargo clippy and fmt checks
11+
- `yarn check:macos`: Run cargo check for macOS (requires Homebrew and `llvm` to be installed)
12+
13+
# Publishing
14+
15+
To release a new version of the bindings, update the version in `package.json` with the appropriate semver value and add an entry to the CHANGELOG.md file. Once merged, manually trigger the `Release WASM Bindings` workflow to build and publish the bindings.

bindings_wasm/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xmtp/wasm-bindings",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"type": "module",
55
"license": "MIT",
66
"description": "WASM bindings for the libXMTP rust library",
@@ -27,6 +27,7 @@
2727
"build": "yarn clean && yarn build:web && yarn build:copy && yarn clean:release",
2828
"build:web": "cargo xtask build BindingsWasm --out-dir ./dist --plain -- --release",
2929
"build:copy": "node scripts/copyFiles.js",
30+
"check:macos": "CC_wasm32_unknown_unknown=/opt/homebrew/opt/llvm/bin/clang cargo check --target wasm32-unknown-unknown",
3031
"clean:release": "rm -f ./dist/package.json",
3132
"clean": "rm -rf ./dist",
3233
"lint": "yarn lint:clippy && yarn lint:fmt",

bindings_wasm/src/conversation.rs

+52-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use wasm_bindgen::{prelude::wasm_bindgen, JsError};
44
use xmtp_mls::storage::group::ConversationType;
55

66
use crate::client::RustXmtpClient;
7+
use crate::conversations::MessageDisappearingSettings;
78
use crate::encoded_content::EncodedContent;
89
use crate::messages::{ListMessagesOptions, Message};
910
use crate::permissions::{MetadataField, PermissionPolicy, PermissionUpdateType};
@@ -15,7 +16,7 @@ use xmtp_mls::groups::{
1516
intents::PermissionUpdateType as XmtpPermissionUpdateType,
1617
members::PermissionLevel as XmtpPermissionLevel, MlsGroup, UpdateAdminListType,
1718
};
18-
use xmtp_mls::storage::group_message::{GroupMessageKind as XmtpGroupMessageKind, MsgQueryArgs};
19+
use xmtp_mls::storage::group_message::MsgQueryArgs;
1920
use xmtp_proto::xmtp::mls::message_contents::EncodedContent as XmtpEncodedContent;
2021

2122
use prost::Message as ProstMessage;
@@ -199,7 +200,7 @@ impl Conversation {
199200
.map_err(|e| JsError::new(&format!("{e}")))?;
200201
let kind = match conversation_type {
201202
ConversationType::Group => None,
202-
ConversationType::Dm => Some(XmtpGroupMessageKind::Application),
203+
ConversationType::Dm => None,
203204
ConversationType::Sync => None,
204205
};
205206

@@ -558,6 +559,55 @@ impl Conversation {
558559
.await
559560
.map_err(Into::into)
560561
}
562+
563+
#[wasm_bindgen(js_name = updateMessageDisappearingSettings)]
564+
pub async fn update_message_disappearing_settings(
565+
&self,
566+
settings: MessageDisappearingSettings,
567+
) -> Result<(), JsError> {
568+
self
569+
.to_mls_group()
570+
.update_conversation_message_disappearing_settings(settings.into())
571+
.await
572+
.map_err(|e| JsError::new(&format!("{e}")))?;
573+
574+
Ok(())
575+
}
576+
577+
#[wasm_bindgen(js_name = removeMessageDisappearingSettings)]
578+
pub async fn remove_message_disappearing_settings(&self) -> Result<(), JsError> {
579+
self
580+
.to_mls_group()
581+
.remove_conversation_message_disappearing_settings()
582+
.await
583+
.map_err(|e| JsError::new(&format!("{e}")))?;
584+
585+
Ok(())
586+
}
587+
588+
#[wasm_bindgen(js_name = messageDisappearingSettings)]
589+
pub fn message_disappearing_settings(
590+
&self,
591+
) -> Result<Option<MessageDisappearingSettings>, JsError> {
592+
let settings = self
593+
.inner_client
594+
.group_disappearing_settings(self.group_id.clone())
595+
.map_err(|e| JsError::new(&format!("{e}")))?;
596+
597+
match settings {
598+
Some(s) => Ok(Some(s.into())),
599+
None => Ok(None),
600+
}
601+
}
602+
603+
#[wasm_bindgen(js_name = isMessageDisappearingEnabled)]
604+
pub fn is_message_disappearing_enabled(&self) -> Result<bool, JsError> {
605+
self.message_disappearing_settings().map(|settings| {
606+
settings
607+
.as_ref()
608+
.is_some_and(|s| s.from_ns > 0 && s.in_ns > 0)
609+
})
610+
}
561611
}
562612

563613
#[cfg(test)]

bindings_wasm/src/conversations.rs

+11
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ impl ListConversationsOptions {
143143
#[wasm_bindgen(getter_with_clone)]
144144
#[derive(Clone)]
145145
pub struct MessageDisappearingSettings {
146+
#[wasm_bindgen(js_name = fromNs)]
146147
pub from_ns: i64,
148+
#[wasm_bindgen(js_name = inNs)]
147149
pub in_ns: i64,
148150
}
149151

@@ -156,6 +158,15 @@ impl From<MessageDisappearingSettings> for XmtpMessageDisappearingSettings {
156158
}
157159
}
158160

161+
impl From<XmtpMessageDisappearingSettings> for MessageDisappearingSettings {
162+
fn from(value: XmtpMessageDisappearingSettings) -> Self {
163+
Self {
164+
from_ns: value.from_ns,
165+
in_ns: value.in_ns,
166+
}
167+
}
168+
}
169+
159170
#[wasm_bindgen]
160171
impl MessageDisappearingSettings {
161172
#[wasm_bindgen(constructor)]

0 commit comments

Comments
 (0)