Add groupRevokeInvite, groupAcceptInvite and fix groupLeave (#860)

* Update groups.ts

* Fix: error TS2448: Block-scoped variable 'result' used before its declaration.
This commit is contained in:
BochilGaming
2021-11-15 14:14:43 +07:00
committed by GitHub
parent 9ed4c28b8e
commit 823701a9c7

View File

@@ -52,7 +52,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
)
return extractGroupMetadata(result)
},
groupLeave: async(jid: string) => {
groupLeave: async(id: string) => {
await groupQuery(
'@g.us',
'set',
@@ -61,7 +61,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
tag: 'leave',
attrs: { },
content: [
{ tag: 'group', attrs: { jid } }
{ tag: 'group', attrs: { id } }
]
}
]
@@ -124,6 +124,16 @@ export const makeGroupsSocket = (config: SocketConfig) => {
const inviteNode = getBinaryNodeChild(result, 'invite')
return inviteNode.attrs.code
},
groupRevokeInvite: async (jid: string) => {
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
const inviteNode = getBinaryNodeChild(result, 'invite')
return inviteNode.attrs.code
},
groupAcceptInvite: async (code: string) => {
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
const result = getBinaryNodeChild(results, 'group')
return result.attrs.jid
},
groupToggleEphemeral: async(jid: string, ephemeralExpiration: number) => {
const content: BinaryNode = ephemeralExpiration ?
{ tag: 'ephemeral', attrs: { ephemeral: ephemeralExpiration.toString() } } :
@@ -202,4 +212,4 @@ export const extractGroupMetadata = (result: BinaryNode) => {
ephemeralDuration: eph ? +eph : undefined
}
return metadata
}
}