diff --git a/bindings_wasm/src/conversation.rs b/bindings_wasm/src/conversation.rs index 9c7a1e090..af09d83b2 100644 --- a/bindings_wasm/src/conversation.rs +++ b/bindings_wasm/src/conversation.rs @@ -6,10 +6,13 @@ use xmtp_mls::storage::group::ConversationType; use crate::client::RustXmtpClient; use crate::encoded_content::EncodedContent; use crate::messages::{ListMessagesOptions, Message}; +use crate::permissions::{MetadataField, PermissionPolicy, PermissionUpdateType}; use crate::{consent_state::ConsentState, permissions::GroupPermissions}; use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_mls::groups::{ group_metadata::GroupMetadata as XmtpGroupMetadata, + group_mutable_metadata::MetadataField as XmtpMetadataField, + intents::PermissionUpdateType as XmtpPermissionUpdateType, members::PermissionLevel as XmtpPermissionLevel, MlsGroup, UpdateAdminListType, }; use xmtp_mls::storage::group_message::{GroupMessageKind as XmtpGroupMessageKind, MsgQueryArgs}; @@ -543,4 +546,22 @@ impl Conversation { .dm_inbox_id() .map_err(|e| JsError::new(&format!("{e}"))) } + + #[wasm_bindgen(js_name = updatePermissionPolicy)] + pub async fn update_permission_policy( + &self, + permission_update_type: PermissionUpdateType, + permission_policy_option: PermissionPolicy, + metadata_field: Option, + ) -> Result<(), JsError> { + self + .to_mls_group() + .update_permission_policy( + XmtpPermissionUpdateType::from(&permission_update_type), + permission_policy_option.try_into()?, + metadata_field.map(|field| XmtpMetadataField::from(&field)), + ) + .await + .map_err(Into::into) + } } diff --git a/bindings_wasm/src/permissions.rs b/bindings_wasm/src/permissions.rs index ff070b0d8..78ce50221 100644 --- a/bindings_wasm/src/permissions.rs +++ b/bindings_wasm/src/permissions.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use wasm_bindgen::{prelude::wasm_bindgen, JsError}; use xmtp_mls::groups::{ - group_mutable_metadata::MetadataField, + group_mutable_metadata::MetadataField as XmtpMetadataField, group_permissions::{ BasePolicies, GroupMutablePermissions, GroupMutablePermissionsError, MembershipPolicies, MetadataBasePolicies, MetadataPolicies, PermissionsBasePolicies, PermissionsPolicies, @@ -245,10 +245,14 @@ impl GroupPermissions { remove_member_policy: PermissionPolicy::from(&policy_set.remove_member_policy), add_admin_policy: PermissionPolicy::from(&policy_set.add_admin_policy), remove_admin_policy: PermissionPolicy::from(&policy_set.remove_admin_policy), - update_group_name_policy: get_policy(MetadataField::GroupName.as_str()), - update_group_description_policy: get_policy(MetadataField::Description.as_str()), - update_group_image_url_square_policy: get_policy(MetadataField::GroupImageUrlSquare.as_str()), - update_group_pinned_frame_url_policy: get_policy(MetadataField::GroupPinnedFrameUrl.as_str()), + update_group_name_policy: get_policy(XmtpMetadataField::GroupName.as_str()), + update_group_description_policy: get_policy(XmtpMetadataField::Description.as_str()), + update_group_image_url_square_policy: get_policy( + XmtpMetadataField::GroupImageUrlSquare.as_str(), + ), + update_group_pinned_frame_url_policy: get_policy( + XmtpMetadataField::GroupPinnedFrameUrl.as_str(), + ), }) } } @@ -258,19 +262,19 @@ impl TryFrom for PolicySet { fn try_from(policy_set: PermissionPolicySet) -> Result { let mut metadata_permissions_map: HashMap = HashMap::new(); metadata_permissions_map.insert( - MetadataField::GroupName.to_string(), + XmtpMetadataField::GroupName.to_string(), policy_set.update_group_name_policy.try_into()?, ); metadata_permissions_map.insert( - MetadataField::Description.to_string(), + XmtpMetadataField::Description.to_string(), policy_set.update_group_description_policy.try_into()?, ); metadata_permissions_map.insert( - MetadataField::GroupImageUrlSquare.to_string(), + XmtpMetadataField::GroupImageUrlSquare.to_string(), policy_set.update_group_image_url_square_policy.try_into()?, ); metadata_permissions_map.insert( - MetadataField::GroupPinnedFrameUrl.to_string(), + XmtpMetadataField::GroupPinnedFrameUrl.to_string(), policy_set.update_group_pinned_frame_url_policy.try_into()?, ); @@ -284,3 +288,22 @@ impl TryFrom for PolicySet { }) } } + +#[wasm_bindgen] +pub enum MetadataField { + GroupName, + Description, + ImageUrlSquare, + PinnedFrameUrl, +} + +impl From<&MetadataField> for XmtpMetadataField { + fn from(field: &MetadataField) -> Self { + match field { + MetadataField::GroupName => XmtpMetadataField::GroupName, + MetadataField::Description => XmtpMetadataField::Description, + MetadataField::ImageUrlSquare => XmtpMetadataField::GroupImageUrlSquare, + MetadataField::PinnedFrameUrl => XmtpMetadataField::GroupPinnedFrameUrl, + } + } +}