mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: fire init queries toggle
This commit is contained in:
@@ -12,7 +12,7 @@ const MAX_SYNC_ATTEMPTS = 5
|
||||
const APP_STATE_SYNC_TIMEOUT_MS = 10_000
|
||||
|
||||
export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const { logger, markOnlineOnConnect, downloadHistory } = config
|
||||
const { logger, markOnlineOnConnect, downloadHistory, fireInitQueries } = config
|
||||
const sock = makeSocket(config)
|
||||
const {
|
||||
ev,
|
||||
@@ -207,8 +207,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
type: 'get'
|
||||
}
|
||||
})
|
||||
const child = result.content?.[0] as BinaryNode
|
||||
return (child.content as BinaryNode[])?.map(i => i.attrs.jid)
|
||||
|
||||
const listNode = getBinaryNodeChild(result, 'list')
|
||||
return getBinaryNodeChildren(listNode, 'item')
|
||||
.map(n => n.attrs.jid)
|
||||
}
|
||||
|
||||
const updateBlockStatus = async(jid: string, action: 'block' | 'unblock') => {
|
||||
@@ -689,13 +691,12 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
* queries need to be fired on connection open
|
||||
* help ensure parity with WA Web
|
||||
* */
|
||||
const fireInitQueries = async() => {
|
||||
const executeInitQueries = async() => {
|
||||
await Promise.all([
|
||||
fetchAbt(),
|
||||
fetchProps(),
|
||||
fetchBlocklist(),
|
||||
fetchPrivacySettings(),
|
||||
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
||||
])
|
||||
}
|
||||
|
||||
@@ -771,9 +772,16 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
ev.on('connection.update', ({ connection }) => {
|
||||
if(connection === 'open') {
|
||||
fireInitQueries()
|
||||
if(fireInitQueries) {
|
||||
executeInitQueries()
|
||||
.catch(
|
||||
error => onUnexpectedError(error, 'init queries')
|
||||
)
|
||||
}
|
||||
|
||||
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
||||
.catch(
|
||||
error => onUnexpectedError(error, 'connection open requests')
|
||||
error => onUnexpectedError(error, 'presence update requests')
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user