mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: message ack on group messages
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
|
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
|
||||||
import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils"
|
import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils"
|
||||||
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser, getBinaryNodeChild } from '../WABinary'
|
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser, getAllBinaryNodeChildren, BinaryNodeAttributes } from '../WABinary'
|
||||||
import { proto } from "../../WAProto"
|
import { proto } from "../../WAProto"
|
||||||
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
||||||
import { makeMessagesSocket } from "./messages-send"
|
import { makeMessagesSocket } from "./messages-send"
|
||||||
@@ -22,24 +22,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
sendDeliveryReceipt,
|
sendDeliveryReceipt,
|
||||||
} = sock
|
} = sock
|
||||||
|
|
||||||
const sendMessageAck = async({ attrs }: BinaryNode, includeType: boolean) => {
|
const sendMessageAck = async({ tag, attrs }: BinaryNode, extraAttrs: BinaryNodeAttributes) => {
|
||||||
const isGroup = !!attrs.participant
|
|
||||||
const meJid = authState.creds.me!.id!
|
|
||||||
const stanza: BinaryNode = {
|
const stanza: BinaryNode = {
|
||||||
tag: 'ack',
|
tag: 'ack',
|
||||||
attrs: {
|
attrs: {
|
||||||
class: 'receipt',
|
|
||||||
id: attrs.id,
|
id: attrs.id,
|
||||||
to: attrs.from,
|
to: attrs.from,
|
||||||
|
...extraAttrs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(includeType) {
|
if(!!attrs.participant) {
|
||||||
stanza.attrs.type = attrs.type
|
stanza.attrs.participant = jidNormalizedUser(attrs.participant)
|
||||||
}
|
}
|
||||||
if(isGroup) {
|
logger.debug({ recv: attrs, sent: stanza.attrs }, `sent "${tag}" ack`)
|
||||||
stanza.attrs.participant = jidNormalizedUser(meJid)
|
|
||||||
}
|
|
||||||
logger.debug({ attrs: stanza.attrs }, 'sent message ack')
|
|
||||||
await sendNode(stanza)
|
await sendNode(stanza)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +371,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
await sendNode({ tag: 'receipt', attrs: recpAttrs })
|
await sendNode({ tag: 'receipt', attrs: recpAttrs })
|
||||||
logger.debug({ msgId: dec.msgId }, 'sent message receipt')
|
logger.debug({ msgId: dec.msgId }, 'sent message receipt')
|
||||||
|
|
||||||
await sendMessageAck(stanza, false)
|
await sendMessageAck(stanza, { class: 'receipt' })
|
||||||
|
|
||||||
await sendDeliveryReceipt(dec.chatId, dec.participant, [dec.msgId])
|
await sendDeliveryReceipt(dec.chatId, dec.participant, [dec.msgId])
|
||||||
logger.debug({ msgId: dec.msgId }, 'sent delivery receipt')
|
logger.debug({ msgId: dec.msgId }, 'sent delivery receipt')
|
||||||
@@ -455,7 +450,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
update: { status }
|
update: { status }
|
||||||
})))
|
})))
|
||||||
|
|
||||||
await sendMessageAck(node, true)
|
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.on('CB:receipt', handleReceipt)
|
ws.on('CB:receipt', handleReceipt)
|
||||||
|
|||||||
Reference in New Issue
Block a user