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

@@ -43,6 +43,7 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig = {
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = { export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
...BASE_CONNECTION_CONFIG, ...BASE_CONNECTION_CONFIG,
fireInitQueries: true,
auth: undefined as any, auth: undefined as any,
downloadHistory: true, downloadHistory: true,
markOnlineOnConnect: true, markOnlineOnConnect: true,

View File

@@ -12,7 +12,7 @@ const MAX_SYNC_ATTEMPTS = 5
const APP_STATE_SYNC_TIMEOUT_MS = 10_000 const APP_STATE_SYNC_TIMEOUT_MS = 10_000
export const makeChatsSocket = (config: SocketConfig) => { export const makeChatsSocket = (config: SocketConfig) => {
const { logger, markOnlineOnConnect, downloadHistory } = config const { logger, markOnlineOnConnect, downloadHistory, fireInitQueries } = config
const sock = makeSocket(config) const sock = makeSocket(config)
const { const {
ev, ev,
@@ -207,8 +207,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
type: 'get' 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') => { 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 * queries need to be fired on connection open
* help ensure parity with WA Web * help ensure parity with WA Web
* */ * */
const fireInitQueries = async() => { const executeInitQueries = async() => {
await Promise.all([ await Promise.all([
fetchAbt(), fetchAbt(),
fetchProps(), fetchProps(),
fetchBlocklist(), fetchBlocklist(),
fetchPrivacySettings(), fetchPrivacySettings(),
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
]) ])
} }
@@ -771,9 +772,16 @@ export const makeChatsSocket = (config: SocketConfig) => {
ev.on('connection.update', ({ connection }) => { ev.on('connection.update', ({ connection }) => {
if(connection === 'open') { if(connection === 'open') {
fireInitQueries() if(fireInitQueries) {
executeInitQueries()
.catch(
error => onUnexpectedError(error, 'init queries')
)
}
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
.catch( .catch(
error => onUnexpectedError(error, 'connection open requests') error => onUnexpectedError(error, 'presence update requests')
) )
} }
}) })

View File

@@ -36,6 +36,8 @@ export type SocketConfig = CommonSocketConfig & {
linkPreviewImageThumbnailWidth: number linkPreviewImageThumbnailWidth: number
/** Should Baileys ask the phone for full history, will be received async */ /** Should Baileys ask the phone for full history, will be received async */
syncFullHistory: boolean syncFullHistory: boolean
/** Should baileys fire init queries automatically, default true */
fireInitQueries: boolean
/** /**
* fetch a message from your store * fetch a message from your store
* implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried * implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried