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:
Renato Alcara
2026-02-15 21:35:45 -03:00
parent 08793904e2
commit 39de1f0582
3 changed files with 56 additions and 14 deletions
+25 -1
View File
@@ -1519,7 +1519,31 @@ export const makeMessagesSocket = (config: SocketConfig) => {
result: fetchResult,
fallbackJid: destinationJid,
keys: authState.keys,
getLIDForPN: signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping)
getLIDForPN: signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping),
onNewJidStored: (storedJid) => {
// Fire-and-forget: persist JID into tctoken index for pruning
(async () => {
try {
const TC_IDX = '__index'
const idxData = await authState.keys.get('tctoken', [TC_IDX])
const idxEntry = idxData[TC_IDX]
const existing: string[] = idxEntry?.token
? JSON.parse(Buffer.from(idxEntry.token).toString('utf8'))
: []
if(!existing.includes(storedJid)) {
existing.push(storedJid)
await authState.keys.set({
tctoken: {
[TC_IDX]: {
token: Buffer.from(JSON.stringify(existing), 'utf8'),
timestamp: unixTimestampSeconds().toString()
}
}
})
}
} catch { /* non-critical — index rebuilt on next pruning cycle */ }
})()
}
})
// Re-read from key store — the notification handler or inline