@@ -10,7 +10,11 @@ import { recordChannelActivity } from "openclaw/plugin-sdk/channel-activity-runt
|
10 | 10 | import { formatLocationText } from "openclaw/plugin-sdk/channel-inbound"; |
11 | 11 | import { createInboundDebouncer } from "openclaw/plugin-sdk/channel-inbound-debounce"; |
12 | 12 | import { 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"; |
14 | 18 | import { defaultRuntime } from "openclaw/plugin-sdk/runtime-env"; |
15 | 19 | import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env"; |
16 | 20 | import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime"; |
@@ -80,6 +84,13 @@ type LocalGroupMetadataCacheEntry = WhatsAppGroupMetadataCacheEntry & {
|
80 | 84 | mentionParticipants?: WhatsAppOutboundMentionParticipant[]; |
81 | 85 | }; |
82 | 86 | |
| 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 | + |
83 | 94 | function parseWhatsAppTimestampSeconds(value: unknown): number | undefined { |
84 | 95 | if (value == null) { |
85 | 96 | return undefined; |
@@ -96,6 +107,10 @@ function rememberGroupMetadataCacheEntry<T extends WhatsAppGroupMetadataCacheEnt
|
96 | 107 | jid: string, |
97 | 108 | entry: T, |
98 | 109 | ): void { |
| 110 | +if (asDateTimestampMs(entry.expires) === undefined) { |
| 111 | +cache.delete(jid); |
| 112 | +return; |
| 113 | +} |
99 | 114 | if (cache.has(jid)) { |
100 | 115 | cache.delete(jid); |
101 | 116 | } |
@@ -118,7 +133,9 @@ function readGroupMetadataCacheEntry<T extends WhatsAppGroupMetadataCacheEntry>(
|
118 | 133 | if (!entry) { |
119 | 134 | return null; |
120 | 135 | } |
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) { |
122 | 139 | cache.delete(jid); |
123 | 140 | return null; |
124 | 141 | } |
@@ -472,15 +489,15 @@ export async function attachWebInboxToSocket(
|
472 | 489 | subject: meta.subject, |
473 | 490 | participants, |
474 | 491 | mentionParticipants, |
475 | | -expires: Date.now() + GROUP_META_TTL_MS, |
| 492 | +expires: resolveGroupMetadataExpiresAt() ?? 0, |
476 | 493 | }; |
477 | 494 | }; |
478 | 495 | |
479 | 496 | const summarizeGroupMetaForReconnectCache = ( |
480 | 497 | meta: GroupMetadata, |
481 | 498 | ): WhatsAppGroupMetadataCacheEntry => ({ |
482 | 499 | subject: meta.subject, |
483 | | -expires: Date.now() + GROUP_META_TTL_MS, |
| 500 | +expires: resolveGroupMetadataExpiresAt() ?? Number.NaN, |
484 | 501 | }); |
485 | 502 | |
486 | 503 | const getGroupMeta = async (jid: string) => { |
@@ -511,7 +528,7 @@ export async function attachWebInboxToSocket(
|
511 | 528 | options.verbose, |
512 | 529 | `Failed to fetch group metadata for ${jid}: ${String(err)}`, |
513 | 530 | ); |
514 | | -return { expires: Date.now() + GROUP_META_TTL_MS }; |
| 531 | +return { expires: resolveGroupMetadataExpiresAt() ?? 0 }; |
515 | 532 | } |
516 | 533 | }; |
517 | 534 | |
|