mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: add option for appStateMacVerification
This commit is contained in:
@@ -55,6 +55,10 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
|||||||
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
||||||
generateHighQualityLinkPreview: false,
|
generateHighQualityLinkPreview: false,
|
||||||
options: { },
|
options: { },
|
||||||
|
appStateMacVerification: {
|
||||||
|
patch: false,
|
||||||
|
snapshot: false,
|
||||||
|
},
|
||||||
getMessage: async() => undefined
|
getMessage: async() => undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ import { makeSocket } from './socket'
|
|||||||
const MAX_SYNC_ATTEMPTS = 2
|
const MAX_SYNC_ATTEMPTS = 2
|
||||||
|
|
||||||
export const makeChatsSocket = (config: SocketConfig) => {
|
export const makeChatsSocket = (config: SocketConfig) => {
|
||||||
const { logger, markOnlineOnConnect, shouldSyncHistoryMessage, fireInitQueries } = config
|
const {
|
||||||
|
logger,
|
||||||
|
markOnlineOnConnect,
|
||||||
|
shouldSyncHistoryMessage,
|
||||||
|
fireInitQueries,
|
||||||
|
appStateMacVerification,
|
||||||
|
} = config
|
||||||
const sock = makeSocket(config)
|
const sock = makeSocket(config)
|
||||||
const {
|
const {
|
||||||
ev,
|
ev,
|
||||||
@@ -360,7 +366,13 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
const { patches, hasMorePatches, snapshot } = decoded[name]
|
const { patches, hasMorePatches, snapshot } = decoded[name]
|
||||||
try {
|
try {
|
||||||
if(snapshot) {
|
if(snapshot) {
|
||||||
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name])
|
const { state: newState, mutationMap } = await decodeSyncdSnapshot(
|
||||||
|
name,
|
||||||
|
snapshot,
|
||||||
|
getAppStateSyncKey,
|
||||||
|
initialVersionMap[name],
|
||||||
|
appStateMacVerification.snapshot
|
||||||
|
)
|
||||||
states[name] = newState
|
states[name] = newState
|
||||||
Object.assign(globalMutationMap, mutationMap)
|
Object.assign(globalMutationMap, mutationMap)
|
||||||
|
|
||||||
@@ -377,7 +389,9 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
states[name],
|
states[name],
|
||||||
getAppStateSyncKey,
|
getAppStateSyncKey,
|
||||||
config.options,
|
config.options,
|
||||||
initialVersionMap[name]
|
initialVersionMap[name],
|
||||||
|
logger,
|
||||||
|
appStateMacVerification.patch
|
||||||
)
|
)
|
||||||
|
|
||||||
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ export type SocketConfig = {
|
|||||||
* */
|
* */
|
||||||
generateHighQualityLinkPreview: boolean
|
generateHighQualityLinkPreview: boolean
|
||||||
|
|
||||||
|
/** verify app state MACs */
|
||||||
|
appStateMacVerification: {
|
||||||
|
patch: boolean
|
||||||
|
snapshot: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/** options for axios */
|
/** options for axios */
|
||||||
options: AxiosRequestConfig<any>
|
options: AxiosRequestConfig<any>
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ export const decodePatches = async(
|
|||||||
mutationMap[index!] = mutation
|
mutationMap[index!] = mutation
|
||||||
}
|
}
|
||||||
: (() => { }),
|
: (() => { }),
|
||||||
validateMacs
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
newState.hash = decodeResult.hash
|
newState.hash = decodeResult.hash
|
||||||
|
|||||||
Reference in New Issue
Block a user