diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index ff43fd1..caec21f 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -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 diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index ae2e22b..bfb195d 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -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() diff --git a/src/Types/index.ts b/src/Types/index.ts index 6816d21..a860819 100644 --- a/src/Types/index.ts +++ b/src/Types/index.ts @@ -120,6 +120,7 @@ export type BaileysEventMap = { 'message-info.update': MessageInfoUpdate[] + 'groups.upsert': GroupMetadata[] 'groups.update': Partial[] /** apply an action to participants in a group */ 'group-participants.update': { id: string, participants: string[], action: ParticipantAction }