mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Chats not being received bug fix
This commit is contained in:
@@ -480,7 +480,7 @@ Baileys is written, keeping in mind, that you may require other custom functiona
|
|||||||
|
|
||||||
First, enable the logging of unhandled messages from WhatsApp by setting
|
First, enable the logging of unhandled messages from WhatsApp by setting
|
||||||
``` ts
|
``` ts
|
||||||
conn.logger.level = 'unhandled'
|
conn.logger.level = 'debug'
|
||||||
```
|
```
|
||||||
This will enable you to see all sorts of messages WhatsApp sends in the console. Some examples:
|
This will enable you to see all sorts of messages WhatsApp sends in the console. Some examples:
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class WAConnection extends EventEmitter {
|
|||||||
waitForChats: true,
|
waitForChats: true,
|
||||||
maxRetries: 10,
|
maxRetries: 10,
|
||||||
connectCooldownMs: 4000,
|
connectCooldownMs: 4000,
|
||||||
phoneResponseTime: 10_000,
|
phoneResponseTime: 15_000,
|
||||||
alwaysUseTakeover: true
|
alwaysUseTakeover: true
|
||||||
}
|
}
|
||||||
/** When to auto-reconnect */
|
/** When to auto-reconnect */
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ export class WAConnection extends Base {
|
|||||||
let waitForChats: Promise<{[k: string]: Partial<WAChat>}>
|
let waitForChats: Promise<{[k: string]: Partial<WAChat>}>
|
||||||
// add wait for chats promise if required
|
// add wait for chats promise if required
|
||||||
if (typeof options?.waitForChats === 'undefined' ? true : options?.waitForChats) {
|
if (typeof options?.waitForChats === 'undefined' ? true : options?.waitForChats) {
|
||||||
const {waitForChats: wPromise, cancelChats} = this.receiveChatsAndContacts(this.connectOptions.waitOnlyForLastMessage)
|
const {wait, cancelChats} = this.receiveChatsAndContacts(this.connectOptions.waitOnlyForLastMessage)
|
||||||
waitForChats = wPromise
|
waitForChats = wait
|
||||||
rejections.push (cancelChats)
|
rejections.push (cancelChats)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -143,16 +143,16 @@ export class WAConnection extends Base {
|
|||||||
const chats = new KeyedDB(this.chatOrderingKey, c => c.jid)
|
const chats = new KeyedDB(this.chatOrderingKey, c => c.jid)
|
||||||
const contacts = {}
|
const contacts = {}
|
||||||
|
|
||||||
|
let receivedChats = false
|
||||||
let receivedContacts = false
|
let receivedContacts = false
|
||||||
let receivedMessages = false
|
let receivedMessages = false
|
||||||
|
|
||||||
let resolveTask: () => void
|
let resolveTask: () => void
|
||||||
let rejectTask: (e: Error) => void
|
let rejectTask: (e: Error) => void
|
||||||
const checkForResolution = () => receivedContacts && receivedMessages && resolveTask ()
|
const checkForResolution = () => receivedContacts && receivedChats && receivedMessages && resolveTask ()
|
||||||
// wait for messages to load
|
// wait for messages to load
|
||||||
const messagesUpdate = json => {
|
const messagesUpdate = json => {
|
||||||
this.startDebouncedTimeout () // restart debounced timeout
|
this.startDebouncedTimeout () // restart debounced timeout
|
||||||
receivedMessages = true
|
|
||||||
|
|
||||||
const isLast = json[1].last || waitOnlyForLast
|
const isLast = json[1].last || waitOnlyForLast
|
||||||
const messages = json[2] as WANode[]
|
const messages = json[2] as WANode[]
|
||||||
@@ -171,6 +171,7 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (isLast) receivedMessages = true
|
||||||
// if received contacts before messages
|
// if received contacts before messages
|
||||||
if (isLast && receivedContacts) checkForResolution ()
|
if (isLast && receivedContacts) checkForResolution ()
|
||||||
}
|
}
|
||||||
@@ -195,10 +196,10 @@ export class WAConnection extends Base {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.logger.info (`received ${json[2].length} chats`)
|
this.logger.info (`received ${json[2].length} chats`)
|
||||||
if (json[2].length === 0) {
|
receivedChats = true
|
||||||
receivedMessages = true
|
|
||||||
checkForResolution ()
|
if (json[2].length === 0) receivedMessages = true
|
||||||
}
|
checkForResolution ()
|
||||||
}
|
}
|
||||||
const contactsUpdate = json => {
|
const contactsUpdate = json => {
|
||||||
if (json[1].duplicate || !json[2]) return
|
if (json[1].duplicate || !json[2]) return
|
||||||
@@ -233,7 +234,7 @@ export class WAConnection extends Base {
|
|||||||
this.off(DEF_CALLBACK_PREFIX + 'response,type:contacts', contactsUpdate)
|
this.off(DEF_CALLBACK_PREFIX + 'response,type:contacts', contactsUpdate)
|
||||||
}
|
}
|
||||||
// wait for the chats & contacts to load
|
// wait for the chats & contacts to load
|
||||||
const waitForChats = async () => {
|
const wait = (async () => {
|
||||||
try {
|
try {
|
||||||
registerCallbacks ()
|
registerCallbacks ()
|
||||||
|
|
||||||
@@ -266,8 +267,8 @@ export class WAConnection extends Base {
|
|||||||
} finally {
|
} finally {
|
||||||
deregisterCallbacks ()
|
deregisterCallbacks ()
|
||||||
}
|
}
|
||||||
}
|
})()
|
||||||
return { waitForChats: waitForChats (), cancelChats: () => rejectTask (CancelledError()) }
|
return { wait, cancelChats: () => rejectTask (CancelledError()) }
|
||||||
}
|
}
|
||||||
private onMessageRecieved(message: string | Buffer) {
|
private onMessageRecieved(message: string | Buffer) {
|
||||||
if (message[0] === '!') {
|
if (message[0] === '!') {
|
||||||
|
|||||||
Reference in New Issue
Block a user