fix: ack receipts

This commit is contained in:
Adhiraj Singh
2021-11-08 22:58:03 +05:30
parent 4edfc7531b
commit 5120f1d1e4

View File

@@ -21,7 +21,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
sendDeliveryReceipt, sendDeliveryReceipt,
} = sock } = sock
const sendMessageAck = async({ attrs }: BinaryNode) => { const sendMessageAck = async({ attrs }: BinaryNode, includeType: boolean) => {
const isGroup = !!attrs.participant const isGroup = !!attrs.participant
const { user: meUser } = jidDecode(authState.creds.me!.id!) const { user: meUser } = jidDecode(authState.creds.me!.id!)
const stanza: BinaryNode = { const stanza: BinaryNode = {
@@ -32,9 +32,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
to: isGroup ? attrs.from : authState.creds.me!.id, to: isGroup ? attrs.from : authState.creds.me!.id,
} }
} }
if(includeType) {
stanza.attrs.type = attrs.type
}
if(isGroup) { if(isGroup) {
stanza.attrs.participant = jidEncode(meUser, 's.whatsapp.net') stanza.attrs.participant = jidEncode(meUser, 's.whatsapp.net')
} }
logger.debug({ attrs: stanza.attrs }, 'sent message ack')
await sendNode(stanza) await sendNode(stanza)
} }
@@ -360,8 +364,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) await sendMessageAck(stanza, false)
logger.debug({ msgId: dec.msgId, sender }, 'sent message ack')
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')
@@ -440,7 +443,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
update: { status } update: { status }
}))) })))
await sendMessageAck(node) await sendMessageAck(node, true)
} }
ws.on('CB:receipt', handleReceipt) ws.on('CB:receipt', handleReceipt)