mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
potential fix for QR scan. the server may expect these messages to be sent on reconnect after scan (#959)
* potential fix for QR scan. the server may expect these messages to be sent on reconnect after scan. * refactor: extract dictionary reduce code into utility * refactor: convert the props + abt send req to somewhat useful query Co-authored-by: Adhiraj Singh <adhirajsingh1001@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, LTHashState, ChatModification, Contact } from "../Types";
|
||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary";
|
||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET, reduceBinaryNodeToDictionary } from "../WABinary";
|
||||
import { proto } from '../../WAProto'
|
||||
import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch, decodeSyncdSnapshot, newLTHashState } from "../Utils";
|
||||
import { makeMessagesSocket } from "./messages-send";
|
||||
@@ -465,6 +465,56 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
)
|
||||
}
|
||||
/** sending abt props may fix QR scan fail if server expects */
|
||||
const fetchAbt = async() => {
|
||||
const abtNode = await query({
|
||||
tag: 'iq',
|
||||
attrs: {
|
||||
to: S_WHATSAPP_NET,
|
||||
xmlns: 'abt',
|
||||
type: 'get',
|
||||
id: generateMessageTag(),
|
||||
},
|
||||
content: [
|
||||
{ tag: 'props', attrs: { protocol: '1' } }
|
||||
]
|
||||
})
|
||||
|
||||
const propsNode = getBinaryNodeChild(abtNode, 'props')
|
||||
|
||||
let props: { [_: string]: string } = { }
|
||||
if(propsNode) {
|
||||
props = reduceBinaryNodeToDictionary(propsNode, 'prop')
|
||||
}
|
||||
logger.debug('fetched abt')
|
||||
|
||||
return props
|
||||
}
|
||||
/** sending non-abt props may fix QR scan fail if server expects */
|
||||
const fetchProps = async() => {
|
||||
const resultNode = await query({
|
||||
tag: 'iq',
|
||||
attrs: {
|
||||
to: S_WHATSAPP_NET,
|
||||
xmlns: 'w',
|
||||
type: 'get',
|
||||
id: generateMessageTag(),
|
||||
},
|
||||
content: [
|
||||
{ tag: 'props', attrs: { } }
|
||||
]
|
||||
})
|
||||
|
||||
const propsNode = getBinaryNodeChild(resultNode, 'props')
|
||||
|
||||
let props: { [_: string]: string } = { }
|
||||
if(propsNode) {
|
||||
props = reduceBinaryNodeToDictionary(propsNode, 'prop')
|
||||
}
|
||||
logger.debug('fetched props')
|
||||
|
||||
return props
|
||||
}
|
||||
/**
|
||||
* modify a chat -- mark unread, read etc.
|
||||
* lastMessages must be sorted in reverse chronologically
|
||||
@@ -514,6 +564,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
sendPresenceUpdate('available')
|
||||
fetchBlocklist()
|
||||
fetchPrivacySettings()
|
||||
fetchAbt()
|
||||
fetchProps()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
import got from "got"
|
||||
import { Boom } from "@hapi/boom"
|
||||
import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions, WAMessageKey } from "../Types"
|
||||
import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions } from "../Types"
|
||||
import { encodeWAMessage, generateMessageID, generateWAMessage, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, jidToSignalProtocolAddress, parseAndInjectE2ESession } from "../Utils"
|
||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, BinaryNodeAttributes, JidWithDevice } from '../WABinary'
|
||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, BinaryNodeAttributes, JidWithDevice, reduceBinaryNodeToDictionary } from '../WABinary'
|
||||
import { proto } from "../../WAProto"
|
||||
import { WA_DEFAULT_EPHEMERAL, DEFAULT_ORIGIN, MEDIA_PATH_MAP } from "../Defaults"
|
||||
import { makeGroupsSocket } from "./groups"
|
||||
@@ -41,13 +41,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
{ tag: 'privacy', attrs: { } }
|
||||
]
|
||||
})
|
||||
const nodes = getBinaryNodeChildren(result, 'category')
|
||||
privacySettings = nodes.reduce(
|
||||
(dict, { attrs }) => {
|
||||
dict[attrs.name] = attrs.value
|
||||
return dict
|
||||
}, { } as { [_: string]: string }
|
||||
)
|
||||
privacySettings = reduceBinaryNodeToDictionary(result, 'category')
|
||||
}
|
||||
return privacySettings
|
||||
}
|
||||
|
||||
@@ -308,5 +308,16 @@ export const assertNodeErrorFree = (node: BinaryNode) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const reduceBinaryNodeToDictionary = (node: BinaryNode, tag: string) => {
|
||||
const nodes = getBinaryNodeChildren(node, tag)
|
||||
const dict = nodes.reduce(
|
||||
(dict, { attrs }) => {
|
||||
dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value
|
||||
return dict
|
||||
}, { } as { [_: string]: string }
|
||||
)
|
||||
return dict
|
||||
}
|
||||
|
||||
export * from './jid-utils'
|
||||
export { Binary } from '../../WABinary/Binary'
|
||||
Reference in New Issue
Block a user