From 019e04fb742b066a3d6742d7c2e22504e30099ee Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Fri, 1 Oct 2021 14:03:46 +0530 Subject: [PATCH] add participating groups query --- src/Socket/groups.ts | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 39468b6..ff43fd1 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -113,6 +113,40 @@ export const makeGroupsSocket = (config: SocketConfig) => { }, groupSettingUpdate: async(jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => { await groupQuery(jid, 'set', [ { tag: setting, attrs: { } } ]) + }, + groupFetchAllParticipating: async() => { + const result = await query({ + tag: 'iq', + attrs: { + to: '@g.us', + xmlns: 'w:g2', + type: 'get', + }, + content: [ + { + tag: 'participating', + attrs: { }, + content: [ + { tag: 'participants', attrs: { } }, + { tag: 'description', attrs: { } } + ] + } + ] + }) + const data: { [_: string]: GroupMetadata } = { } + const groupsChild = getBinaryNodeChild(result, 'groups') + if(groupsChild) { + const groups = getBinaryNodeChildren(groupsChild, 'group') + for(const groupNode of groups) { + const meta = extractGroupMetadata({ + tag: 'result', + attrs: { }, + content: [groupNode] + }) + data[meta.id] = meta + } + } + return data } } } @@ -128,6 +162,7 @@ const extractGroupMetadata = (result: BinaryNode) => { descId = descChild.attrs.id } const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us') + const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration const metadata: GroupMetadata = { id: groupId, subject: group.attrs.subject, @@ -144,7 +179,8 @@ const extractGroupMetadata = (result: BinaryNode) => { admin: attrs.type || null as any, } } - ) + ), + ephemeralDuration: eph ? +eph : undefined } return metadata } \ No newline at end of file