feat: catch groups create notification

This commit is contained in:
Adhiraj Singh
2021-11-10 19:46:25 +05:30
parent 3e54741042
commit 469f3451d2
3 changed files with 23 additions and 6 deletions

View File

@@ -152,7 +152,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
}
const extractGroupMetadata = (result: BinaryNode) => {
export const extractGroupMetadata = (result: BinaryNode) => {
const group = getBinaryNodeChild(result, 'group')
const descChild = getBinaryNodeChild(group, 'description')
let desc: string | undefined

View File

@@ -1,10 +1,11 @@
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils"
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser } from '../WABinary'
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser, getBinaryNodeChild } from '../WABinary'
import { proto } from "../../WAProto"
import { KEY_BUNDLE_TYPE } from "../Defaults"
import { makeMessagesSocket } from "./messages-send"
import { extractGroupMetadata } from "./groups"
const isReadReceipt = (type: string) => type === 'read' || type === 'read-self'
@@ -216,7 +217,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
emitGroupUpdate({ restrict })
break
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
case WAMessageStubType.GROUP_CREATE:
chatUpdate.name = message.messageStubParameters[0]
emitGroupUpdate({ subject: chatUpdate.name })
break
@@ -270,6 +270,18 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
if(node.attrs.type === 'w:gp2') {
switch(child?.tag) {
case 'create':
const metadata = extractGroupMetadata(child)
result.messageStubType = WAMessageStubType.GROUP_CREATE
result.messageStubParameters = [metadata.subject]
ev.emit('chats.upsert', [{
id: metadata.id,
name: metadata.subject,
conversationTimestamp: metadata.creation,
}])
ev.emit('groups.upsert', [metadata])
break
case 'ephemeral':
case 'not_ephemeral':
result.message = {
@@ -450,7 +462,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
ws.on('CB:notification', async(node: BinaryNode) => {
const sendAck = async() => {
await sendNode({
const stanza: BinaryNode = {
tag: 'ack',
attrs: {
class: 'notification',
@@ -458,9 +470,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
type: node.attrs.type,
to: node.attrs.from
}
})
}
if(node.attrs.participant) {
stanza.attrs.participant = node.attrs.participant
}
await sendNode(stanza)
logger.debug({ msgId: node.attrs.id }, 'ack notification')
logger.debug({ attrs: stanza.attrs }, 'ack notification')
}
await sendAck()

View File

@@ -120,6 +120,7 @@ export type BaileysEventMap = {
'message-info.update': MessageInfoUpdate[]
'groups.upsert': GroupMetadata[]
'groups.update': Partial<GroupMetadata>[]
/** apply an action to participants in a group */
'group-participants.update': { id: string, participants: string[], action: ParticipantAction }