mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: debounced app state resync
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
||||||
import { BaileysEventMap, MessageUserReceipt, SocketConfig, WAMessageStubType } from '../Types'
|
import { BaileysEventMap, MessageUserReceipt, SocketConfig, WAMessageStubType } from '../Types'
|
||||||
import { decodeMessageStanza, delay, encodeBigEndian, generateSignalPubKey, getStatusFromReceiptType, normalizeMessageContent, xmppPreKey, xmppSignedPreKey } from '../Utils'
|
import { debouncedTimeout, decodeMessageStanza, delay, encodeBigEndian, generateSignalPubKey, getStatusFromReceiptType, normalizeMessageContent, xmppPreKey, xmppSignedPreKey } from '../Utils'
|
||||||
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex'
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex'
|
||||||
import processMessage from '../Utils/process-message'
|
import processMessage from '../Utils/process-message'
|
||||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getAllBinaryNodeChildren, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getAllBinaryNodeChildren, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary'
|
||||||
@@ -36,6 +36,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
||||||
const retryMutex = makeMutex()
|
const retryMutex = makeMutex()
|
||||||
|
|
||||||
|
const appStateSyncTimeout = debouncedTimeout(
|
||||||
|
6_000,
|
||||||
|
() => ws.readyState === ws.OPEN && resyncMainAppState()
|
||||||
|
)
|
||||||
|
|
||||||
const msgRetryMap = config.msgRetryCounterMap || { }
|
const msgRetryMap = config.msgRetryCounterMap || { }
|
||||||
|
|
||||||
const historyCache = new Set<string>()
|
const historyCache = new Set<string>()
|
||||||
@@ -153,8 +158,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
{ historyCache, meId, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal }
|
{ historyCache, meId, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal }
|
||||||
)
|
)
|
||||||
|
|
||||||
if(newEvents['chats.set']?.isLatest) {
|
if(isAnyHistoryMsg) {
|
||||||
resyncMainAppState()
|
logger.debug('restarting app sync timeout')
|
||||||
|
// restart the app state sync timeout
|
||||||
|
appStateSyncTimeout.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
return newEvents
|
return newEvents
|
||||||
|
|||||||
Reference in New Issue
Block a user