From 169610128c62478540e014034fece2611bb497e3 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 2 Jul 2024 10:11:11 -0500 Subject: [PATCH] Add group description getter/setter (#885) --- bindings_node/src/groups.rs | 31 ++++++++++++++++++++++++ bindings_node/test/Conversations.test.ts | 29 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/bindings_node/src/groups.rs b/bindings_node/src/groups.rs index 7b4646f4a..8f9236561 100644 --- a/bindings_node/src/groups.rs +++ b/bindings_node/src/groups.rs @@ -500,6 +500,37 @@ impl NapiGroup { Ok(group_image_url_square) } + #[napi] + pub async fn update_group_description(&self, group_description: String) -> Result<()> { + let group = MlsGroup::new( + self.inner_client.context().clone(), + self.group_id.clone(), + self.created_at_ns, + ); + + group + .update_group_description(&self.inner_client, group_description) + .await + .map_err(|e| Error::from_reason(format!("{}", e)))?; + + Ok(()) + } + + #[napi] + pub fn group_description(&self) -> Result { + let group = MlsGroup::new( + self.inner_client.context().clone(), + self.group_id.clone(), + self.created_at_ns, + ); + + let group_description = group + .group_description() + .map_err(|e| Error::from_reason(format!("{}", e)))?; + + Ok(group_description) + } + #[napi(ts_args_type = "callback: (err: null | Error, result: NapiMessage) => void")] pub fn stream(&self, callback: JsFunction) -> Result { let tsfn: ThreadsafeFunction = diff --git a/bindings_node/test/Conversations.test.ts b/bindings_node/test/Conversations.test.ts index 97ec08b89..186591c25 100644 --- a/bindings_node/test/Conversations.test.ts +++ b/bindings_node/test/Conversations.test.ts @@ -138,6 +138,35 @@ describe('Conversations', () => { expect(groupWithPermissions.groupPermissions().policyType()).toBe( GroupPermissions.GroupCreatorIsAdmin ) + + const groupWithDescription = await client1 + .conversations() + .createGroup([user2.account.address], { + groupDescription: 'foo', + }) + expect(groupWithDescription).toBeDefined() + expect(groupWithDescription.groupName()).toBe('') + expect(groupWithDescription.groupImageUrlSquare()).toBe('') + expect(groupWithDescription.groupDescription()).toBe('foo') + }) + + it('should update group metadata', async () => { + const user1 = createUser() + const user2 = createUser() + const client1 = await createRegisteredClient(user1) + await createRegisteredClient(user2) + const group = await client1 + .conversations() + .createGroup([user2.account.address]) + + await group.updateGroupName('foo') + expect(group.groupName()).toBe('foo') + + await group.updateGroupImageUrlSquare('https://foo/bar.png') + expect(group.groupImageUrlSquare()).toBe('https://foo/bar.png') + + await group.updateGroupDescription('bar') + expect(group.groupDescription()).toBe('bar') }) it('should stream new groups', async () => {