Skip to content

Commit

Permalink
fix tests and add message expiration starts timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Jan 9, 2025
1 parent c179ee4 commit ba0a4b3
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 42 deletions.
28 changes: 22 additions & 6 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ pub struct FfiConversations {

#[derive(uniffi::Enum, Clone, Debug)]
pub enum FfiGroupPermissionsOptions {
AllMembers,
Default,
AdminOnly,
CustomPolicy,
}
Expand Down Expand Up @@ -789,7 +789,7 @@ pub struct FfiPermissionPolicySet {
impl From<PreconfiguredPolicies> for FfiGroupPermissionsOptions {
fn from(policy: PreconfiguredPolicies) -> Self {
match policy {
PreconfiguredPolicies::AllMembers => FfiGroupPermissionsOptions::AllMembers,
PreconfiguredPolicies::Default => FfiGroupPermissionsOptions::Default,
PreconfiguredPolicies::AdminsOnly => FfiGroupPermissionsOptions::AdminOnly,
}
}
Expand All @@ -815,6 +815,14 @@ impl TryFrom<FfiPermissionPolicySet> for PolicySet {
MetadataField::GroupPinnedFrameUrl.to_string(),
policy_set.update_group_pinned_frame_url_policy.try_into()?,
);
// MessageExpirationFromMillis follows the same policy as MessageExpirationMillis
metadata_permissions_map.insert(
MetadataField::MessageExpirationFromMillis.to_string(),
policy_set
.update_message_expiration_ms_policy
.clone()
.try_into()?,
);
metadata_permissions_map.insert(
MetadataField::MessageExpirationMillis.to_string(),
policy_set.update_message_expiration_ms_policy.try_into()?,
Expand Down Expand Up @@ -877,8 +885,8 @@ impl FfiConversations {
let metadata_options = opts.clone().into_group_metadata_options();

let group_permissions = match opts.permissions {
Some(FfiGroupPermissionsOptions::AllMembers) => {
Some(xmtp_mls::groups::PreconfiguredPolicies::AllMembers.to_policy_set())
Some(FfiGroupPermissionsOptions::Default) => {
Some(xmtp_mls::groups::PreconfiguredPolicies::Default.to_policy_set())
}
Some(FfiGroupPermissionsOptions::AdminOnly) => {
Some(xmtp_mls::groups::PreconfiguredPolicies::AdminsOnly.to_policy_set())
Expand Down Expand Up @@ -1370,6 +1378,7 @@ pub struct FfiCreateGroupOptions {
pub group_description: Option<String>,
pub group_pinned_frame_url: Option<String>,
pub custom_permission_policy_set: Option<FfiPermissionPolicySet>,
pub message_expiration_from_ms: Option<i64>,
pub message_expiration_ms: Option<i64>,
}

Expand All @@ -1380,6 +1389,7 @@ impl FfiCreateGroupOptions {
image_url_square: self.group_image_url_square,
description: self.group_description,
pinned_frame_url: self.group_pinned_frame_url,
message_expiration_from_ms: self.message_expiration_from_ms,
message_expiration_ms: self.message_expiration_ms,
}
}
Expand Down Expand Up @@ -2689,6 +2699,7 @@ mod tests {
group_description: Some("group description".to_string()),
group_pinned_frame_url: Some("pinned frame".to_string()),
custom_permission_policy_set: None,
message_expiration_from_ms: None,
message_expiration_ms: None,
},
)
Expand Down Expand Up @@ -3935,7 +3946,7 @@ mod tests {

// Create all_members group
let all_members_options = FfiCreateGroupOptions {
permissions: Some(FfiGroupPermissionsOptions::AllMembers),
permissions: Some(FfiGroupPermissionsOptions::Default),
..Default::default()
};
let alix_group_all_members = alix
Expand Down Expand Up @@ -4085,6 +4096,7 @@ mod tests {
group_description: Some("A test group".to_string()),
group_pinned_frame_url: Some("https://example.com/frame.png".to_string()),
custom_permission_policy_set: Some(custom_permissions),
message_expiration_from_ms: None,
message_expiration_ms: None,
};

Expand Down Expand Up @@ -4213,6 +4225,7 @@ mod tests {
group_description: Some("A test group".to_string()),
group_pinned_frame_url: Some("https://example.com/frame.png".to_string()),
custom_permission_policy_set: Some(custom_permissions_invalid_1),
message_expiration_from_ms: None,
message_expiration_ms: None,
};

Expand All @@ -4227,12 +4240,13 @@ mod tests {
assert!(results_1.is_err());

let create_group_options_invalid_2 = FfiCreateGroupOptions {
permissions: Some(FfiGroupPermissionsOptions::AllMembers),
permissions: Some(FfiGroupPermissionsOptions::Default),
group_name: Some("Test Group".to_string()),
group_image_url_square: Some("https://example.com/image.png".to_string()),
group_description: Some("A test group".to_string()),
group_pinned_frame_url: Some("https://example.com/frame.png".to_string()),
custom_permission_policy_set: Some(custom_permissions_valid.clone()),
message_expiration_from_ms: None,
message_expiration_ms: None,
};

Expand All @@ -4253,6 +4267,7 @@ mod tests {
group_description: Some("A test group".to_string()),
group_pinned_frame_url: Some("https://example.com/frame.png".to_string()),
custom_permission_policy_set: Some(custom_permissions_valid.clone()),
message_expiration_from_ms: None,
message_expiration_ms: None,
};

Expand All @@ -4273,6 +4288,7 @@ mod tests {
group_description: Some("A test group".to_string()),
group_pinned_frame_url: Some("https://example.com/frame.png".to_string()),
custom_permission_policy_set: Some(custom_permissions_valid),
message_expiration_from_ms: None,
message_expiration_ms: None,
};

Expand Down
7 changes: 5 additions & 2 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub struct CreateGroupOptions {
pub group_description: Option<String>,
pub group_pinned_frame_url: Option<String>,
pub custom_permission_policy_set: Option<PermissionPolicySet>,
pub message_expiration_from_ms: Option<i64>,
pub message_expiration_ms: Option<i64>,
}

Expand All @@ -132,6 +133,7 @@ impl CreateGroupOptions {
image_url_square: self.group_image_url_square,
description: self.group_description,
pinned_frame_url: self.group_pinned_frame_url,
message_expiration_from_ms: self.message_expiration_from_ms,
message_expiration_ms: self.message_expiration_ms,
}
}
Expand Down Expand Up @@ -161,6 +163,7 @@ impl Conversations {
group_description: None,
group_pinned_frame_url: None,
custom_permission_policy_set: None,
message_expiration_from_ms: None,
message_expiration_ms: None,
});

Expand All @@ -177,8 +180,8 @@ impl Conversations {
let metadata_options = options.clone().into_group_metadata_options();

let group_permissions = match options.permissions {
Some(GroupPermissionsOptions::AllMembers) => {
Some(PreconfiguredPolicies::AllMembers.to_policy_set())
Some(GroupPermissionsOptions::Default) => {
Some(PreconfiguredPolicies::Default.to_policy_set())
}
Some(GroupPermissionsOptions::AdminOnly) => {
Some(PreconfiguredPolicies::AdminsOnly.to_policy_set())
Expand Down
4 changes: 2 additions & 2 deletions bindings_node/src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use xmtp_mls::groups::{

#[napi]
pub enum GroupPermissionsOptions {
AllMembers,
Default,
AdminOnly,
CustomPolicy,
}
Expand Down Expand Up @@ -167,7 +167,7 @@ pub struct PermissionPolicySet {
impl From<PreconfiguredPolicies> for GroupPermissionsOptions {
fn from(policy: PreconfiguredPolicies) -> Self {
match policy {
PreconfiguredPolicies::AllMembers => GroupPermissionsOptions::AllMembers,
PreconfiguredPolicies::Default => GroupPermissionsOptions::Default,
PreconfiguredPolicies::AdminsOnly => GroupPermissionsOptions::AdminOnly,
}
}
Expand Down
11 changes: 9 additions & 2 deletions bindings_wasm/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,24 @@ pub struct CreateGroupOptions {
pub group_pinned_frame_url: Option<String>,
#[wasm_bindgen(js_name = customPermissionPolicySet)]
pub custom_permission_policy_set: Option<PermissionPolicySet>,
#[wasm_bindgen(js_name = messageExpirationFromMillis)]
pub message_expiration_from_ms: Option<i64>,
#[wasm_bindgen(js_name = messageExpirationMillis)]
pub message_expiration_ms: Option<i64>,
}

#[wasm_bindgen]
impl CreateGroupOptions {
#[wasm_bindgen(constructor)]
#[allow(clippy::too_many_arguments)]
pub fn new(
permissions: Option<GroupPermissionsOptions>,
group_name: Option<String>,
group_image_url_square: Option<String>,
group_description: Option<String>,
group_pinned_frame_url: Option<String>,
custom_permission_policy_set: Option<PermissionPolicySet>,
message_expiration_from_ms: Option<i64>,
message_expiration_ms: Option<i64>,
) -> Self {
Self {
Expand All @@ -152,6 +156,7 @@ impl CreateGroupOptions {
group_description,
group_pinned_frame_url,
custom_permission_policy_set,
message_expiration_from_ms,
message_expiration_ms,
}
}
Expand All @@ -164,6 +169,7 @@ impl CreateGroupOptions {
image_url_square: self.group_image_url_square,
description: self.group_description,
pinned_frame_url: self.group_pinned_frame_url,
message_expiration_from_ms: self.message_expiration_from_ms,
message_expiration_ms: self.message_expiration_ms,
}
}
Expand Down Expand Up @@ -195,6 +201,7 @@ impl Conversations {
group_description: None,
group_pinned_frame_url: None,
custom_permission_policy_set: None,
message_expiration_from_ms: None,
message_expiration_ms: None,
});

Expand All @@ -209,8 +216,8 @@ impl Conversations {
let metadata_options = options.clone().into_group_metadata_options();

let group_permissions = match options.permissions {
Some(GroupPermissionsOptions::AllMembers) => {
Some(PreconfiguredPolicies::AllMembers.to_policy_set())
Some(GroupPermissionsOptions::Default) => {
Some(PreconfiguredPolicies::Default.to_policy_set())
}
Some(GroupPermissionsOptions::AdminOnly) => {
Some(PreconfiguredPolicies::AdminsOnly.to_policy_set())
Expand Down
4 changes: 2 additions & 2 deletions bindings_wasm/src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use xmtp_mls::groups::{
#[wasm_bindgen]
#[derive(Clone)]
pub enum GroupPermissionsOptions {
AllMembers,
Default,
AdminOnly,
CustomPolicy,
}
Expand Down Expand Up @@ -206,7 +206,7 @@ impl PermissionPolicySet {
impl From<PreconfiguredPolicies> for GroupPermissionsOptions {
fn from(policy: PreconfiguredPolicies) -> Self {
match policy {
PreconfiguredPolicies::AllMembers => GroupPermissionsOptions::AllMembers,
PreconfiguredPolicies::Default => GroupPermissionsOptions::Default,
PreconfiguredPolicies::AdminsOnly => GroupPermissionsOptions::AdminOnly,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
}
Commands::CreateGroup { permissions } => {
let group_permissions = match permissions {
Permissions::EveryoneIsAdmin => xmtp_mls::groups::PreconfiguredPolicies::AllMembers,
Permissions::EveryoneIsAdmin => xmtp_mls::groups::PreconfiguredPolicies::Default,
Permissions::GroupCreatorIsAdmin => {
xmtp_mls::groups::PreconfiguredPolicies::AdminsOnly
}
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub const DEFAULT_GROUP_NAME: &str = "";
pub const DEFAULT_GROUP_DESCRIPTION: &str = "";
pub const DEFAULT_GROUP_IMAGE_URL_SQUARE: &str = "";
pub const DEFAULT_GROUP_PINNED_FRAME_URL: &str = "";
pub const DEFAULT_MESSAGE_EXPIRATION_MS: i64 = 0;

// If a metadata field name starts with this character,
// and it does not have a policy set, it is a super admin only field
Expand Down
28 changes: 17 additions & 11 deletions xmtp_mls/src/groups/group_mutable_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use xmtp_proto::xmtp::mls::message_contents::{

use crate::configuration::{
DEFAULT_GROUP_DESCRIPTION, DEFAULT_GROUP_IMAGE_URL_SQUARE, DEFAULT_GROUP_NAME,
DEFAULT_GROUP_PINNED_FRAME_URL, DEFAULT_MESSAGE_EXPIRATION_MS, MUTABLE_METADATA_EXTENSION_ID,
DEFAULT_GROUP_PINNED_FRAME_URL, MUTABLE_METADATA_EXTENSION_ID,
};

use super::GroupMetadataOptions;
Expand Down Expand Up @@ -47,6 +47,7 @@ pub enum MetadataField {
Description,
GroupImageUrlSquare,
GroupPinnedFrameUrl,
MessageExpirationFromMillis,
MessageExpirationMillis,
}

Expand All @@ -58,6 +59,7 @@ impl MetadataField {
MetadataField::Description => "description",
MetadataField::GroupImageUrlSquare => "group_image_url_square",
MetadataField::GroupPinnedFrameUrl => "group_pinned_frame_url",
MetadataField::MessageExpirationFromMillis => "message_expiration_from_ms",
MetadataField::MessageExpirationMillis => "message_expiration_ms",
}
}
Expand Down Expand Up @@ -123,12 +125,20 @@ impl GroupMutableMetadata {
opts.pinned_frame_url
.unwrap_or_else(|| DEFAULT_GROUP_PINNED_FRAME_URL.to_string()),
);
attributes.insert(
MetadataField::MessageExpirationMillis.to_string(),
opts.message_expiration_ms
.unwrap_or(DEFAULT_MESSAGE_EXPIRATION_MS)
.to_string(),
);

if let Some(message_expiration_from_ms) = opts.message_expiration_from_ms {
attributes.insert(
MetadataField::MessageExpirationFromMillis.to_string(),
message_expiration_from_ms.to_string(),
);
}
if let Some(message_expiration_ms) = opts.message_expiration_ms {
attributes.insert(
MetadataField::MessageExpirationMillis.to_string(),
message_expiration_ms.to_string(),
);
}

let admin_list = vec![];
let super_admin_list = vec![creator_inbox_id.clone()];
Self {
Expand Down Expand Up @@ -158,10 +168,6 @@ impl GroupMutableMetadata {
MetadataField::GroupPinnedFrameUrl.to_string(),
DEFAULT_GROUP_PINNED_FRAME_URL.to_string(),
);
attributes.insert(
MetadataField::MessageExpirationMillis.to_string(),
DEFAULT_MESSAGE_EXPIRATION_MS.to_string(),
);
let admin_list = vec![];
let super_admin_list = vec![];
Self {
Expand Down
Loading

0 comments on commit ba0a4b3

Please sign in to comment.