correct message updates

This commit is contained in:
Adhiraj
2020-08-19 17:43:30 +05:30
parent a6c8fee814
commit 47021c34bf
4 changed files with 23 additions and 13 deletions

View File

@@ -32,9 +32,9 @@ async function example() {
/* Note: one can take this auth_info.json file and login again from any computer without having to scan the QR code,
and get full access to one's WhatsApp. Despite the convenience, be careful with this file */
conn.on ('user-presence-update', json => console.log(json.id + ' presence is ' + json.type))
conn.on ('message-update', message => {
//const participant = json.participant ? ' (' + json.participant + ')' : '' // participant exists when the message is from a group
//console.log(`${json.to}${participant} acknlowledged message(s) ${json.ids} as ${json.type}`)
conn.on ('message-update', json => {
const participant = json.participant ? ' (' + json.participant + ')' : '' // participant exists when the message is from a group
console.log(`${json.to}${participant} acknlowledged message(s) ${json.ids} as ${json.type}`)
})
// set to false to NOT relay your own sent messages
conn.on('message-new', async (m) => {

View File

@@ -116,7 +116,6 @@ describe ('Reconnects', () => {
// let it fail reconnect a few times
if (closes > 4) {
console.log ('here')
conn.removeAllListeners ('closed')
conn.removeAllListeners ('connecting')
resolve ()

View File

@@ -1,6 +1,6 @@
import WS from 'ws'
import * as Utils from './Utils'
import { WAMessage, WAChat, WAContact, MessageLogLevel, WANode, KEEP_ALIVE_INTERVAL_MS } from './Constants'
import { WAMessage, WAChat, WAContact, MessageLogLevel, WANode, KEEP_ALIVE_INTERVAL_MS, BaileysError } from './Constants'
import {WAConnection as Base} from './1.Validation'
import Decoder from '../Binary/Decoder'
@@ -266,6 +266,10 @@ export class WAConnection extends Base {
this.cancelReconnect = null
break
} catch (error) {
// don't continue reconnecting if error is 400
if (error instanceof BaileysError && error.status >= 400) {
break
}
this.log (`error in reconnecting: ${error}, reconnecting...`, MessageLogLevel.info)
}
}

View File

@@ -127,7 +127,8 @@ export class WAConnection extends Base {
const chat = this.chats.get( whatsappID(update.to) )
if (!chat) return
this.emit ('message-update', update)
this.chatUpdatedMessage (update.ids, update.type, chat)
}
this.registerCallback('Msg', func)
@@ -183,11 +184,19 @@ export class WAConnection extends Base {
case WAMessageProto.ProtocolMessage.PROTOCOL_MESSAGE_TYPE.REVOKE:
const found = chat.messages.find(m => m.key.id === protocolMessage.key.id)
if (found && found.message) {
//this.log ('deleting message: ' + protocolMessage.key.id + ' in chat: ' + protocolMessage.key.remoteJid)
this.log ('deleting message: ' + protocolMessage.key.id + ' in chat: ' + protocolMessage.key.remoteJid, MessageLogLevel.info)
found.messageStubType = WA_MESSAGE_STUB_TYPE.REVOKE
found.message = null
this.emit ('message-update', found)
const update: MessageStatusUpdate = {
from: this.user.id,
to: message.key.remoteJid,
ids: [message.key.id],
timestamp: new Date(),
type: -1
}
this.emit ('message-update', update)
}
break
default:
@@ -249,8 +258,6 @@ export class WAConnection extends Base {
if (messageIDs.includes(msg.key.id)) {
if (isGroupID(chat.jid)) msg.status = WA_MESSAGE_STATUS_TYPE.SERVER_ACK
else msg.status = status
this.emit ('message-update', msg)
}
}
}
@@ -294,8 +301,8 @@ export class WAConnection extends Base {
on (event: 'chat-update', listener: (chat: Partial<WAChat> & { jid: string }) => void): this
/** when a new message is relayed */
on (event: 'message-new', listener: (message: WAMessage) => void): this
/** when a message is updated (deleted, delivered, read) */
on (event: 'message-update', listener: (message: WAMessage) => void): this
/** when a message is updated (deleted, delivered, read, sent etc.) */
on (event: 'message-update', listener: (message: MessageStatusUpdate) => void): this
/** when participants are added to a group */
on (event: 'group-participants-add', listener: (update: {jid: string, participants: string[], actor?: string}) => void): this
/** when participants are removed or leave from a group */