@@ -10,7 +10,11 @@ import { recordChannelActivity } from "openclaw/plugin-sdk/channel-activity-runt
1010import { formatLocationText } from "openclaw/plugin-sdk/channel-inbound" ;
1111import { createInboundDebouncer } from "openclaw/plugin-sdk/channel-inbound-debounce" ;
1212import { getChildLogger } from "openclaw/plugin-sdk/logging-core" ;
13- import { parseStrictFiniteNumber } from "openclaw/plugin-sdk/number-runtime" ;
13+ import {
14+ asDateTimestampMs ,
15+ parseStrictFiniteNumber ,
16+ resolveExpiresAtMsFromDurationMs ,
17+ } from "openclaw/plugin-sdk/number-runtime" ;
1418import { defaultRuntime } from "openclaw/plugin-sdk/runtime-env" ;
1519import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env" ;
1620import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime" ;
@@ -80,6 +84,13 @@ type LocalGroupMetadataCacheEntry = WhatsAppGroupMetadataCacheEntry & {
8084 mentionParticipants ?: WhatsAppOutboundMentionParticipant [ ] ;
8185} ;
8286
87+ function resolveGroupMetadataExpiresAt ( nowRaw = Date . now ( ) ) : number | undefined {
88+ const now = asDateTimestampMs ( nowRaw ) ;
89+ return now === undefined
90+ ? undefined
91+ : resolveExpiresAtMsFromDurationMs ( GROUP_META_TTL_MS , { nowMs : now } ) ;
92+ }
93+
8394function parseWhatsAppTimestampSeconds ( value : unknown ) : number | undefined {
8495 if ( value == null ) {
8596 return undefined ;
@@ -96,6 +107,10 @@ function rememberGroupMetadataCacheEntry<T extends WhatsAppGroupMetadataCacheEnt
96107 jid : string ,
97108 entry : T ,
98109) : void {
110+ if ( asDateTimestampMs ( entry . expires ) === undefined ) {
111+ cache . delete ( jid ) ;
112+ return ;
113+ }
99114 if ( cache . has ( jid ) ) {
100115 cache . delete ( jid ) ;
101116 }
@@ -118,7 +133,9 @@ function readGroupMetadataCacheEntry<T extends WhatsAppGroupMetadataCacheEntry>(
118133 if ( ! entry ) {
119134 return null ;
120135 }
121- if ( entry . expires <= Date . now ( ) ) {
136+ const now = asDateTimestampMs ( Date . now ( ) ) ;
137+ const expires = asDateTimestampMs ( entry . expires ) ;
138+ if ( now === undefined || expires === undefined || expires <= now ) {
122139 cache . delete ( jid ) ;
123140 return null ;
124141 }
@@ -472,15 +489,15 @@ export async function attachWebInboxToSocket(
472489 subject : meta . subject ,
473490 participants,
474491 mentionParticipants,
475- expires : Date . now ( ) + GROUP_META_TTL_MS ,
492+ expires : resolveGroupMetadataExpiresAt ( ) ?? 0 ,
476493 } ;
477494 } ;
478495
479496 const summarizeGroupMetaForReconnectCache = (
480497 meta : GroupMetadata ,
481498 ) : WhatsAppGroupMetadataCacheEntry => ( {
482499 subject : meta . subject ,
483- expires : Date . now ( ) + GROUP_META_TTL_MS ,
500+ expires : resolveGroupMetadataExpiresAt ( ) ?? Number . NaN ,
484501 } ) ;
485502
486503 const getGroupMeta = async ( jid : string ) => {
@@ -511,7 +528,7 @@ export async function attachWebInboxToSocket(
511528 options . verbose ,
512529 `Failed to fetch group metadata for ${ jid } : ${ String ( err ) } ` ,
513530 ) ;
514- return { expires : Date . now ( ) + GROUP_META_TTL_MS } ;
531+ return { expires : resolveGroupMetadataExpiresAt ( ) ?? 0 } ;
515532 }
516533 } ;
517534
0 commit comments