mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: better ack
This commit is contained in:
@@ -47,20 +47,30 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
const historyCache = new Set<string>()
|
const historyCache = new Set<string>()
|
||||||
|
|
||||||
const sendMessageAck = async({ tag, attrs }: BinaryNode, extraAttrs: BinaryNodeAttributes) => {
|
const sendMessageAck = async({ tag, attrs }: BinaryNode, extraAttrs: BinaryNodeAttributes = { }) => {
|
||||||
const stanza: BinaryNode = {
|
const stanza: BinaryNode = {
|
||||||
tag: 'ack',
|
tag: 'ack',
|
||||||
attrs: {
|
attrs: {
|
||||||
id: attrs.id,
|
id: attrs.id,
|
||||||
to: attrs.from,
|
to: attrs.from,
|
||||||
|
class: tag,
|
||||||
...extraAttrs,
|
...extraAttrs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!!attrs.participant) {
|
if(!!attrs.participant) {
|
||||||
stanza.attrs.participant = attrs.participant
|
stanza.attrs.participant = attrs.participant
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug({ recv: attrs, sent: stanza.attrs }, `sent "${tag}" ack`)
|
if(!!attrs.recipient) {
|
||||||
|
stanza.attrs.recipient = attrs.recipient
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tag !== 'message' && attrs.type && !extraAttrs.type) {
|
||||||
|
stanza.attrs.type = attrs.type
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack')
|
||||||
await sendNode(stanza)
|
await sendNode(stanza)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +409,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(shouldAck) {
|
if(shouldAck) {
|
||||||
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
|
await sendMessageAck(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -407,7 +417,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
const handleNotification = async(node: BinaryNode) => {
|
const handleNotification = async(node: BinaryNode) => {
|
||||||
const remoteJid = node.attrs.from
|
const remoteJid = node.attrs.from
|
||||||
await sendMessageAck(node, { class: 'notification', type: node.attrs.type })
|
await sendMessageAck(node)
|
||||||
await processingMutex.mutex(
|
await processingMutex.mutex(
|
||||||
remoteJid,
|
remoteJid,
|
||||||
async() => {
|
async() => {
|
||||||
@@ -468,6 +478,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
processingMutex.mutex(
|
processingMutex.mutex(
|
||||||
msg.key.remoteJid!,
|
msg.key.remoteJid!,
|
||||||
async() => {
|
async() => {
|
||||||
|
await sendMessageAck(stanza)
|
||||||
await decryptionTask
|
await decryptionTask
|
||||||
// message failed to decrypt
|
// message failed to decrypt
|
||||||
if(msg.messageStubType === proto.WebMessageInfo.WebMessageInfoStubType.CIPHERTEXT) {
|
if(msg.messageStubType === proto.WebMessageInfo.WebMessageInfoStubType.CIPHERTEXT) {
|
||||||
@@ -547,7 +558,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
ev.emit('call', [call])
|
ev.emit('call', [call])
|
||||||
|
|
||||||
await sendMessageAck(node, { class: 'call', type: infoChild.tag })
|
await sendMessageAck(node, { type: infoChild.tag })
|
||||||
.catch(
|
.catch(
|
||||||
error => onUnexpectedError(error, 'ack call')
|
error => onUnexpectedError(error, 'ack call')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user