fix: address PR review comments for tctoken lifecycle
- Wire onNewJidStored callback in messages-send.ts so proactively fetched tokens are registered in the pruning index - Batch keystore reads in pruneExpiredTcTokens (1 query instead of N) - Persist lastTcTokenPruneTs in keystore so 24h throttle survives restarts - Replace parseInt() with Number() for safer timestamp parsing - Normalize JIDs via jidNormalizedUser() before LID lookup in resolveTcTokenJid to prevent device-suffix mismatches Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ const TC_TOKEN_NUM_BUCKETS = 4
|
||||
*/
|
||||
export function isTcTokenExpired(timestamp: number | string | null | undefined): boolean {
|
||||
if(timestamp === null || timestamp === undefined) return true
|
||||
const ts = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp
|
||||
const ts = typeof timestamp === 'string' ? Number(timestamp) : timestamp
|
||||
if(isNaN(ts)) return true
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION)
|
||||
@@ -57,9 +57,10 @@ export async function resolveTcTokenJid(
|
||||
jid: string,
|
||||
getLIDForPN: (pn: string) => Promise<string | null>
|
||||
): Promise<string> {
|
||||
if(isLidUser(jid)) return jid
|
||||
const lid = await getLIDForPN(jid)
|
||||
return lid ?? jid
|
||||
const normalized = jidNormalizedUser(jid)
|
||||
if(isLidUser(normalized)) return normalized
|
||||
const lid = await getLIDForPN(normalized)
|
||||
return lid ?? normalized
|
||||
}
|
||||
|
||||
type TcTokenParams = {
|
||||
|
||||
Reference in New Issue
Block a user