fix: fire init queries toggle

This commit is contained in:
Adhiraj Singh
2022-08-12 09:05:58 +05:30
parent 0b3cfb9570
commit 19484e5cfc
3 changed files with 18 additions and 7 deletions

View File

@@ -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')
)
}
})