mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Android not receiving message status update fix
This commit is contained in:
@@ -236,29 +236,31 @@ export class WAConnection extends Base {
|
|||||||
this.logger.debug ({ unhandled: true }, 'received message update for non-present message from ' + jid)
|
this.logger.debug ({ unhandled: true }, 'received message update for non-present message from ' + jid)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.on('CB:action,add:relay,received', json => {
|
// message status updates
|
||||||
|
const onMessageStatusUpdate = json => {
|
||||||
json = json[2][0][1]
|
json = json[2][0][1]
|
||||||
const chat = this.chats.get( whatsappID(json.jid) )
|
const MAP = {
|
||||||
const msg = chat?.messages.get(GET_MESSAGE_ID({ id: json.index, fromMe: json.owner === 'true' }))
|
read: WA_MESSAGE_STATUS_TYPE.READ,
|
||||||
if (msg) {
|
message: WA_MESSAGE_STATUS_TYPE.DELIVERY_ACK,
|
||||||
const MAP = {
|
error: WA_MESSAGE_STATUS_TYPE.ERROR
|
||||||
read: WA_MESSAGE_STATUS_TYPE.READ,
|
|
||||||
message: WA_MESSAGE_STATUS_TYPE.DELIVERY_ACK,
|
|
||||||
error: WA_MESSAGE_STATUS_TYPE.ERROR
|
|
||||||
}
|
|
||||||
const status = MAP[json.type]
|
|
||||||
if (typeof status !== 'undefined') {
|
|
||||||
if (status > msg.status || status === WA_MESSAGE_STATUS_TYPE.ERROR) {
|
|
||||||
msg.status = status
|
|
||||||
this.emit('chat-update', { jid: chat.jid, messages: newMessagesDB([ msg ]) })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.logger.warn({ update: json }, 'received unknown message status update')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.logger.debug ({ unhandled: true, update: json }, 'received message status update for non-present message')
|
|
||||||
}
|
}
|
||||||
})
|
this.onMessageStatusUpdate(
|
||||||
|
whatsappID(json.jid),
|
||||||
|
{ id: json.index, fromMe: json.owner === 'true' },
|
||||||
|
MAP[json.type]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
this.on('CB:action,add:relay,received', onMessageStatusUpdate)
|
||||||
|
this.on('CB:action,,received', onMessageStatusUpdate)
|
||||||
|
|
||||||
|
this.on('CB:Msg,cmd:ack', json => (
|
||||||
|
this.onMessageStatusUpdate(
|
||||||
|
whatsappID(json[1].to),
|
||||||
|
{ id: json[1].id, fromMe: true },
|
||||||
|
+json[1].ack + 1
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
// If a user's contact has changed
|
// If a user's contact has changed
|
||||||
this.on ('CB:action,,user', json => {
|
this.on ('CB:action,,user', json => {
|
||||||
const node = json[2][0]
|
const node = json[2][0]
|
||||||
@@ -430,6 +432,22 @@ export class WAConnection extends Base {
|
|||||||
return chat
|
return chat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected onMessageStatusUpdate(jid: string, key: { id: string, fromMe: boolean }, status: WA_MESSAGE_STATUS_TYPE) {
|
||||||
|
const chat = this.chats.get( whatsappID(jid) )
|
||||||
|
const msg = chat?.messages.get(GET_MESSAGE_ID(key))
|
||||||
|
if (msg) {
|
||||||
|
if (typeof status !== 'undefined') {
|
||||||
|
if (status > msg.status || status === WA_MESSAGE_STATUS_TYPE.ERROR) {
|
||||||
|
msg.status = status
|
||||||
|
this.emit('chat-update', { jid: chat.jid, messages: newMessagesDB([ msg ]) })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.logger.warn({ update: status }, 'received unknown message status update')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.logger.debug ({ unhandled: true, update: status, key }, 'received message status update for non-present message')
|
||||||
|
}
|
||||||
|
}
|
||||||
protected contactAddOrGet (jid: string) {
|
protected contactAddOrGet (jid: string) {
|
||||||
jid = whatsappID(jid)
|
jid = whatsappID(jid)
|
||||||
if (!this.contacts[jid]) this.contacts[jid] = { jid }
|
if (!this.contacts[jid]) this.contacts[jid] = { jid }
|
||||||
|
|||||||
Reference in New Issue
Block a user