Android not receiving message status update fix

This commit is contained in:
Adhiraj Singh
2021-02-04 22:38:30 +05:30
parent a13aabd394
commit d803c219b6

View File

@@ -236,29 +236,31 @@ export class WAConnection extends Base {
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]
const chat = this.chats.get( whatsappID(json.jid) )
const msg = chat?.messages.get(GET_MESSAGE_ID({ id: json.index, fromMe: json.owner === 'true' }))
if (msg) {
const MAP = {
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')
const MAP = {
read: WA_MESSAGE_STATUS_TYPE.READ,
message: WA_MESSAGE_STATUS_TYPE.DELIVERY_ACK,
error: WA_MESSAGE_STATUS_TYPE.ERROR
}
})
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
this.on ('CB:action,,user', json => {
const node = json[2][0]
@@ -430,6 +432,22 @@ export class WAConnection extends Base {
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) {
jid = whatsappID(jid)
if (!this.contacts[jid]) this.contacts[jid] = { jid }