Skip to content

Commit

Permalink
Add group description getter/setter (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine authored Jul 2, 2024
1 parent e4cfade commit 1696101
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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<NapiStreamCloser> {
let tsfn: ThreadsafeFunction<NapiMessage, ErrorStrategy::CalleeHandled> =
Expand Down
29 changes: 29 additions & 0 deletions bindings_node/test/Conversations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 1696101

Please sign in to comment.