From ae80566c0e4f905e874e0973f5891ceaee1773ed Mon Sep 17 00:00:00 2001 From: Ilya Borodin <48887908+ilyaborodin@users.noreply.github.com> Date: Mon, 15 Nov 2021 05:39:10 +0300 Subject: [PATCH] Group update description (#859) * Added groupUpdateDescription * Updated README Co-authored-by: Ilya Borodin --- README.md | 4 ++++ src/Socket/groups.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index ac59e10..9a8270d 100644 --- a/README.md +++ b/README.md @@ -542,6 +542,10 @@ Of course, replace ``` xyz ``` with an actual ID. ``` ts await conn.groupUpdateSubject("abcd-xyz@g.us", "New Subject!") ``` +- To change the group's description + ``` ts + await conn.groupUpdateDescription("abcd-xyz@g.us", "New Description!") + ``` - To change group settings ``` ts // only allow admins to send messages diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index caec21f..508760e 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -100,6 +100,25 @@ export const makeGroupsSocket = (config: SocketConfig) => { const participantsAffected = getBinaryNodeChildren(node!, 'participant') return participantsAffected.map(p => p.attrs.jid) }, + groupUpdateDescription: async(jid: string, description?: string) => { + const metadata = await groupMetadata(jid); + const prev = metadata.descId ?? null; + + await groupQuery( + jid, + 'set', + [ + { + tag: 'description', + attrs: { + ...( description ? { id: generateMessageID() } : { delete: 'true' } ), + ...(prev ? { prev } : {}) + }, + content: description ? [{tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8')}] : null + } + ] + ) + }, groupInviteCode: async(jid: string) => { const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]) const inviteNode = getBinaryNodeChild(result, 'invite')