fix: ensure proper type casting for cache and message handling

This commit is contained in:
Francisco Pessano
2025-08-14 16:50:03 +00:00
committed by GitHub
parent 84fcd13907
commit b0a973e24c
6 changed files with 16 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults'
import {
ALL_WA_PATCH_NAMES,
BotListInfo,
CacheStore,
ChatModification,
ChatMutation,
LTHashState,
@@ -79,7 +80,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
})
if (!config.placeholderResendCache) {
config.placeholderResendCache = placeholderResendCache
config.placeholderResendCache = placeholderResendCache as CacheStore
}
/** helper function to fetch the given app state sync key */
@@ -974,7 +975,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
})(),
processMessage(msg, {
shouldProcessHistoryMsg,
placeholderResendCache,
placeholderResendCache: placeholderResendCache as CacheStore,
ev,
creds: authState.creds,
keyStore: authState.keys,

View File

@@ -169,7 +169,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const msgId = msgKey.id!
const key = `${msgId}:${msgKey?.participant}`
let retryCount = msgRetryCache.get<number>(key) || 0
let retryCount = (msgRetryCache.get<number>(key) as number) || 0
if (retryCount >= maxMsgRetryCount) {
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing')
msgRetryCache.del(key)
@@ -585,13 +585,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const willSendMessageAgain = (id: string, participant: string) => {
const key = `${id}:${participant}`
const retryCount = msgRetryCache.get<number>(key) || 0
const retryCount = (msgRetryCache.get<number>(key) as number) || 0
return retryCount < maxMsgRetryCount
}
const updateSendMessageAgainCount = (id: string, participant: string) => {
const key = `${id}:${participant}`
const newValue = (msgRetryCache.get<number>(key) || 0) + 1
const newValue = ((msgRetryCache.get<number>(key) as number) || 0) + 1
msgRetryCache.set(key, newValue)
}
@@ -961,8 +961,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
// use existing call info to populate this event
if (existingCall) {
call.isVideo = existingCall.isVideo
call.isGroup = existingCall.isGroup
call.isVideo = (existingCall as WACallEvent).isVideo
call.isGroup = (existingCall as WACallEvent).isGroup
}
// delete data once call has ended

View File

@@ -195,8 +195,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const user = jidDecode(jid)?.user
jid = jidNormalizedUser(jid)
if (useCache) {
const devices = userDevicesCache.get<JidWithDevice[]>(user!)
if (devices) {
const devices = userDevicesCache.get<JidWithDevice[]>(user!) as JidWithDevice[] | undefined
if (devices && Array.isArray(devices)) {
deviceResults.push(...devices)
logger.trace({ user }, 'using cache for devices')

View File

@@ -43,8 +43,8 @@ export function makeCacheableSignalKeyStore(
const idsToFetch: string[] = []
for (const id of ids) {
const item = cache.get<SignalDataTypeMap[typeof type]>(getUniqueId(type, id))
if (typeof item !== 'undefined') {
data[id] = item
if (typeof item !== 'undefined' && item !== null) {
data[id] = item as SignalDataTypeMap[typeof type]
} else {
idsToFetch.push(id)
}
@@ -55,7 +55,7 @@ export function makeCacheableSignalKeyStore(
const fetched = await store.get(type, idsToFetch)
for (const id of idsToFetch) {
const item = fetched[id]
if (item) {
if (item !== null && item !== undefined) {
data[id] = item
cache.set(getUniqueId(type, id), item)
}

View File

@@ -136,7 +136,7 @@ export async function hkdf(
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
// Import the input key material
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits'])
const importedKey = await subtle.importKey('raw', inputKeyMaterial as BufferSource, { name: 'HKDF' }, false, ['deriveBits'])
// Derive bits using HKDF
const derivedBits = await subtle.deriveBits(
@@ -167,7 +167,7 @@ export async function derivePairingCodeKey(pairingCode: string, salt: Buffer): P
const derivedBits = await subtle.deriveBits(
{
name: 'PBKDF2',
salt: saltBuffer,
salt: saltBuffer as BufferSource,
iterations: 2 << 16,
hash: 'SHA-256'
},

View File

@@ -20,7 +20,7 @@ export const downloadHistory = async (msg: proto.Message.IHistorySyncNotificatio
let buffer = Buffer.concat(bufferArray)
// decompress buffer
buffer = await inflatePromise(buffer)
buffer = Buffer.from(await inflatePromise(buffer))
const syncData = proto.HistorySync.decode(buffer)
return syncData