chore: make use of "msgRetryCounterMap" more explicit

This commit is contained in:
Adhiraj Singh
2022-05-01 11:44:51 +05:30
parent 4a8c6ed66d
commit 221b95050f
2 changed files with 12 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { Boom } from '@hapi/boom'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, useSingleFileAuthState } from '../src'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, MessageRetryMap, useSingleFileAuthState } from '../src'
import MAIN_LOGGER from '../src/Utils/logger'
const logger = MAIN_LOGGER.child({ })
@@ -8,6 +8,10 @@ logger.level = 'trace'
const useStore = !process.argv.includes('--no-store')
const doReplies = !process.argv.includes('--no-reply')
// external map to store retry counts of messages when decryption/encryption fails
// keep this out of the socket itself, so as to prevent a message decryption/encryption loop across socket restarts
const msgRetryCounterMap: MessageRetryMap = { }
// the store maintains the data of the WA connection in memory
// can be written out to a file & read from it
const store = useStore ? makeInMemoryStore({ logger }) : undefined
@@ -30,6 +34,7 @@ const startSock = async() => {
logger,
printQRInTerminal: true,
auth: state,
msgRetryCounterMap,
// implement to handle retries
getMessage: async key => {
return {

View File

@@ -14,11 +14,15 @@ import { proto } from '../../WAProto'
import { AuthenticationState } from './Auth'
import { CommonSocketConfig } from './Socket'
export type MessageRetryMap = { [msgId: string]: number }
export type SocketConfig = CommonSocketConfig<AuthenticationState> & {
/** provide a cache to store a user's device list */
userDevicesCache?: NodeCache
/** map to store the retry counts for failed messages */
msgRetryCounterMap?: { [msgId: string]: number }
/**
* map to store the retry counts for failed messages;
* used to determine whether to retry a message or not */
msgRetryCounterMap?: MessageRetryMap
/** width for link preview images */
linkPreviewImageThumbnailWidth: number
/**