[core] Add msgRetryCounterCache

This commit is contained in:
devlikepro committed 2024-06-20 14:21:00 +07:00
1 parent 822eba7982
commit d72401fc39
1 file changed
+9
@@ -33,6 +33,7 @@ import * as Buffer from 'buffer';
import { Agent } from 'https';
import * as lodash from 'lodash';
import { toNumber } from 'lodash';
import * as NodeCache from 'node-cache';
import type { Logger } from 'pino';
import {
@@ -132,6 +133,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
private startTimeoutId: null | ReturnType<typeof setTimeout> = null;
private autoRestartTimeoutId: null | ReturnType<typeof setTimeout> = null;
public logger: Logger;
private msgRetryCounterCache: NodeCache;
get listenConnectionEventsFromTheStart() {
return true;
@@ -150,6 +152,12 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
this.logger = logger.child({
session: this.name,
});
// external map to store retry counts of messages when decryption/encryption fails
// keep this out of the socket itself, to prevent a message decryption/encryption loop across socket restarts
this.msgRetryCounterCache = new NodeCache({
stdTTL: 60 * 60, // 1 hour
useClones: false,
});
}
start() {
@@ -178,6 +186,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
keepAliveIntervalMs: 30_000,
getMessage: (key) => this.getMessage(key),
syncFullHistory: fullSyncEnabled,
msgRetryCounterCache: this.msgRetryCounterCache,
};
}