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

Adding pinned frame metadata field #888

Merged
merged 10 commits into from
Jul 3, 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
43 changes: 43 additions & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ pub struct FfiPermissionPolicySet {
pub update_group_name_policy: FfiPermissionPolicy,
pub update_group_description_policy: FfiPermissionPolicy,
pub update_group_image_url_square_policy: FfiPermissionPolicy,
pub update_group_pinned_frame_url_policy: FfiPermissionPolicy,
}

impl From<PreconfiguredPolicies> for FfiGroupPermissionsOptions {
Expand All @@ -464,6 +465,7 @@ pub enum FfiMetadataField {
GroupName,
Description,
ImageUrlSquare,
PinnedFrameUrl,
}

impl From<&FfiMetadataField> for MetadataField {
Expand All @@ -472,6 +474,7 @@ impl From<&FfiMetadataField> for MetadataField {
FfiMetadataField::GroupName => MetadataField::GroupName,
FfiMetadataField::Description => MetadataField::Description,
FfiMetadataField::ImageUrlSquare => MetadataField::GroupImageUrlSquare,
FfiMetadataField::PinnedFrameUrl => MetadataField::GroupPinnedFrameUrl,
}
}
}
Expand Down Expand Up @@ -639,6 +642,7 @@ pub struct FfiCreateGroupOptions {
pub group_name: Option<String>,
pub group_image_url_square: Option<String>,
pub group_description: Option<String>,
pub group_pinned_frame_url: Option<String>,
}

impl FfiCreateGroupOptions {
Expand All @@ -647,6 +651,7 @@ impl FfiCreateGroupOptions {
name: self.group_name,
image_url_square: self.group_image_url_square,
description: self.group_description,
pinned_frame_url: self.group_pinned_frame_url,
}
}
}
Expand Down Expand Up @@ -897,6 +902,35 @@ impl FfiGroup {
Ok(group_description)
}

pub async fn update_group_pinned_frame_url(
&self,
pinned_frame_url: String,
) -> Result<(), GenericError> {
let group = MlsGroup::new(
self.inner_client.context().clone(),
self.group_id.clone(),
self.created_at_ns,
);

group
.update_group_pinned_frame_url(&self.inner_client, pinned_frame_url)
.await?;

Ok(())
}

pub fn group_pinned_frame_url(&self) -> Result<String, GenericError> {
let group = MlsGroup::new(
self.inner_client.context().clone(),
self.group_id.clone(),
self.created_at_ns,
);

let group_pinned_frame_url = group.group_pinned_frame_url()?;

Ok(group_pinned_frame_url)
}

pub fn admin_list(&self) -> Result<Vec<String>, GenericError> {
let group = MlsGroup::new(
self.inner_client.context().clone(),
Expand Down Expand Up @@ -1241,6 +1275,9 @@ impl FfiGroupPermissions {
update_group_image_url_square_policy: get_policy(
MetadataField::GroupImageUrlSquare.as_str(),
),
update_group_pinned_frame_url_policy: get_policy(
MetadataField::GroupPinnedFrameUrl.as_str(),
),
})
}
}
Expand Down Expand Up @@ -1570,6 +1607,7 @@ mod tests {
group_name: Some("Group Name".to_string()),
group_image_url_square: Some("url".to_string()),
group_description: Some("group description".to_string()),
group_pinned_frame_url: Some("pinned frame".to_string()),
},
)
.await
Expand All @@ -1580,6 +1618,7 @@ mod tests {
assert_eq!(group.group_name().unwrap(), "Group Name");
assert_eq!(group.group_image_url_square().unwrap(), "url");
assert_eq!(group.group_description().unwrap(), "group description");
assert_eq!(group.group_pinned_frame_url().unwrap(), "pinned frame");
}

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
Expand Down Expand Up @@ -2131,6 +2170,7 @@ mod tests {
update_group_name_policy: FfiPermissionPolicy::Admin,
update_group_description_policy: FfiPermissionPolicy::Admin,
update_group_image_url_square_policy: FfiPermissionPolicy::Admin,
update_group_pinned_frame_url_policy: FfiPermissionPolicy::Admin,
};
assert_eq!(alix_permission_policy_set, expected_permission_policy_set);

Expand Down Expand Up @@ -2159,6 +2199,7 @@ mod tests {
update_group_name_policy: FfiPermissionPolicy::Allow,
update_group_description_policy: FfiPermissionPolicy::Allow,
update_group_image_url_square_policy: FfiPermissionPolicy::Allow,
update_group_pinned_frame_url_policy: FfiPermissionPolicy::Allow,
};
assert_eq!(alix_permission_policy_set, expected_permission_policy_set);
}
Expand Down Expand Up @@ -2191,6 +2232,7 @@ mod tests {
update_group_name_policy: FfiPermissionPolicy::Admin,
update_group_description_policy: FfiPermissionPolicy::Admin,
update_group_image_url_square_policy: FfiPermissionPolicy::Admin,
update_group_pinned_frame_url_policy: FfiPermissionPolicy::Admin,
};
assert_eq!(alix_group_permissions, expected_permission_policy_set);

Expand All @@ -2217,6 +2259,7 @@ mod tests {
update_group_name_policy: FfiPermissionPolicy::Admin,
update_group_description_policy: FfiPermissionPolicy::Admin,
update_group_image_url_square_policy: FfiPermissionPolicy::Allow,
update_group_pinned_frame_url_policy: FfiPermissionPolicy::Admin,
};
assert_eq!(alix_group_permissions, new_expected_permission_policy_set);

Expand Down
3 changes: 3 additions & 0 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct NapiCreateGroupOptions {
pub group_name: Option<String>,
pub group_image_url_square: Option<String>,
pub group_description: Option<String>,
pub group_pinned_frame_url: Option<String>,
}

impl NapiCreateGroupOptions {
Expand All @@ -36,6 +37,7 @@ impl NapiCreateGroupOptions {
name: self.group_name,
image_url_square: self.group_image_url_square,
description: self.group_description,
pinned_frame_url: self.group_pinned_frame_url,
}
}
}
Expand Down Expand Up @@ -64,6 +66,7 @@ impl NapiConversations {
group_name: None,
group_image_url_square: None,
group_description: None,
group_pinned_frame_url: None,
},
};

Expand Down
31 changes: 31 additions & 0 deletions bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,37 @@ impl NapiGroup {
Ok(group_description)
}

#[napi]
pub async fn update_group_pinned_frame_url(&self, pinned_frame_url: String) -> Result<()> {
let group = MlsGroup::new(
self.inner_client.context().clone(),
self.group_id.clone(),
self.created_at_ns,
);

group
.update_group_pinned_frame_url(&self.inner_client, pinned_frame_url)
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;

Ok(())
}

#[napi]
pub fn group_pinned_frame_url(&self) -> Result<String> {
let group = MlsGroup::new(
self.inner_client.context().clone(),
self.group_id.clone(),
self.created_at_ns,
);

let group_pinned_frame_url = group
.group_pinned_frame_url()
.map_err(|e| Error::from_reason(format!("{}", e)))?;

Ok(group_pinned_frame_url)
}

#[napi(ts_args_type = "callback: (err: null | Error, result: NapiMessage) => void")]
pub fn stream(&self, callback: JsFunction) -> Result<NapiStreamCloser> {
let tsfn: ThreadsafeFunction<NapiMessage, ErrorStrategy::CalleeHandled> =
Expand Down
16 changes: 16 additions & 0 deletions bindings_node/test/Conversations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ describe('Conversations', () => {
expect(groupWithDescription.groupName()).toBe('')
expect(groupWithDescription.groupImageUrlSquare()).toBe('')
expect(groupWithDescription.groupDescription()).toBe('foo')

const groupWithPinnedFrameUrl = await client1
.conversations()
.createGroup([user2.account.address], {
groupPinnedFrameUrl: 'https://frameurl.xyz',
})
expect(groupWithPinnedFrameUrl).toBeDefined()
expect(groupWithPinnedFrameUrl.groupName()).toBe('')
expect(groupWithPinnedFrameUrl.groupImageUrlSquare()).toBe('')
expect(groupWithPinnedFrameUrl.groupDescription()).toBe('')
expect(groupWithPinnedFrameUrl.groupPinnedFrameUrl()).toBe(
'https://frameurl.xyz'
)
})

it('should update group metadata', async () => {
Expand All @@ -167,6 +180,9 @@ describe('Conversations', () => {

await group.updateGroupDescription('bar')
expect(group.groupDescription()).toBe('bar')

await group.updateGroupPinnedFrameUrl('https://frameurl.xyz')
expect(group.groupPinnedFrameUrl()).toBe('https://frameurl.xyz')
})

it('should stream new groups', async () => {
Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub const GROUP_PERMISSIONS_EXTENSION_ID: u16 = 0xff02;
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 = "";

// 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
10 changes: 9 additions & 1 deletion 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,
MUTABLE_METADATA_EXTENSION_ID,
DEFAULT_GROUP_PINNED_FRAME_URL, MUTABLE_METADATA_EXTENSION_ID,
};

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

impl MetadataField {
Expand All @@ -50,6 +51,7 @@ impl MetadataField {
MetadataField::GroupName => "group_name",
MetadataField::Description => "description",
MetadataField::GroupImageUrlSquare => "group_image_url_square",
MetadataField::GroupPinnedFrameUrl => "group_pinned_frame_url",
}
}
}
Expand Down Expand Up @@ -97,6 +99,11 @@ impl GroupMutableMetadata {
opts.image_url_square
.unwrap_or_else(|| DEFAULT_GROUP_IMAGE_URL_SQUARE.to_string()),
);
attributes.insert(
MetadataField::GroupPinnedFrameUrl.to_string(),
opts.pinned_frame_url
.unwrap_or_else(|| DEFAULT_GROUP_PINNED_FRAME_URL.to_string()),
);
let admin_list = vec![];
let super_admin_list = vec![creator_inbox_id.clone()];
Self {
Expand All @@ -112,6 +119,7 @@ impl GroupMutableMetadata {
MetadataField::GroupName,
MetadataField::Description,
MetadataField::GroupImageUrlSquare,
MetadataField::GroupPinnedFrameUrl,
]
}

Expand Down
7 changes: 7 additions & 0 deletions xmtp_mls/src/groups/intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ impl UpdateMetadataIntentData {
field_value: group_description,
}
}

pub fn new_update_group_pinned_frame_url(pinned_frame_url: String) -> Self {
Self {
field_name: MetadataField::GroupPinnedFrameUrl.to_string(),
field_value: pinned_frame_url,
}
}
}

impl From<UpdateMetadataIntentData> for Vec<u8> {
Expand Down
Loading