mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: prevent duplicate receipts on multiple messages recv in stanza
This commit is contained in:
@@ -345,10 +345,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
// recv a message
|
// recv a message
|
||||||
ws.on('CB:message', async(stanza: BinaryNode) => {
|
ws.on('CB:message', async(stanza: BinaryNode) => {
|
||||||
const dec = await decodeMessageStanza(stanza, authState)
|
const dec = await decodeMessageStanza(stanza, authState)
|
||||||
if(dec.successes.length) {
|
|
||||||
ev.emit('auth-state.update', authState)
|
|
||||||
}
|
|
||||||
|
|
||||||
const fullMessages: proto.IWebMessageInfo[] = []
|
const fullMessages: proto.IWebMessageInfo[] = []
|
||||||
|
|
||||||
const { attrs } = stanza
|
const { attrs } = stanza
|
||||||
@@ -364,8 +360,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
id: dec.msgId,
|
id: dec.msgId,
|
||||||
participant: dec.participant
|
participant: dec.participant
|
||||||
}
|
}
|
||||||
|
// if there were some successful decryptions
|
||||||
for(const msg of dec.successes) {
|
if(dec.successes.length) {
|
||||||
|
ev.emit('auth-state.update', authState)
|
||||||
// send message receipt
|
// send message receipt
|
||||||
let recpAttrs: { [_: string]: any }
|
let recpAttrs: { [_: string]: any }
|
||||||
if(isMe) {
|
if(isMe) {
|
||||||
@@ -399,16 +396,18 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const msg of dec.successes) {
|
||||||
const message = msg.deviceSentMessage?.message || msg
|
const message = msg.deviceSentMessage?.message || msg
|
||||||
fullMessages.push({
|
fullMessages.push({
|
||||||
key,
|
key,
|
||||||
message,
|
message,
|
||||||
status: isMe ? proto.WebMessageInfo.WebMessageInfoStatus.SERVER_ACK : null,
|
status: isMe ? proto.WebMessageInfo.WebMessageInfoStatus.SERVER_ACK : null,
|
||||||
messageTimestamp: dec.timestamp,
|
messageTimestamp: dec.timestamp,
|
||||||
pushName: dec.pushname,
|
pushName: dec.pushname,
|
||||||
participant: dec.participant
|
participant: dec.participant
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const { error } of dec.failures) {
|
for(const { error } of dec.failures) {
|
||||||
@@ -425,15 +424,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fullMessages.length) {
|
ev.emit(
|
||||||
ev.emit(
|
'messages.upsert',
|
||||||
'messages.upsert',
|
{
|
||||||
{
|
messages: fullMessages.map(m => proto.WebMessageInfo.fromObject(m)),
|
||||||
messages: fullMessages.map(m => proto.WebMessageInfo.fromObject(m)),
|
type: stanza.attrs.offline ? 'append' : 'notify'
|
||||||
type: stanza.attrs.offline ? 'append' : 'notify'
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.on('CB:ack,class:message', async(node: BinaryNode) => {
|
ws.on('CB:ack,class:message', async(node: BinaryNode) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user