mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: ensure proper type casting for cache and message handling
This commit is contained in:
committed by
GitHub
parent
84fcd13907
commit
b0a973e24c
@@ -5,6 +5,7 @@ import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults'
|
|||||||
import {
|
import {
|
||||||
ALL_WA_PATCH_NAMES,
|
ALL_WA_PATCH_NAMES,
|
||||||
BotListInfo,
|
BotListInfo,
|
||||||
|
CacheStore,
|
||||||
ChatModification,
|
ChatModification,
|
||||||
ChatMutation,
|
ChatMutation,
|
||||||
LTHashState,
|
LTHashState,
|
||||||
@@ -79,7 +80,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!config.placeholderResendCache) {
|
if (!config.placeholderResendCache) {
|
||||||
config.placeholderResendCache = placeholderResendCache
|
config.placeholderResendCache = placeholderResendCache as CacheStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/** helper function to fetch the given app state sync key */
|
/** helper function to fetch the given app state sync key */
|
||||||
@@ -974,7 +975,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
})(),
|
})(),
|
||||||
processMessage(msg, {
|
processMessage(msg, {
|
||||||
shouldProcessHistoryMsg,
|
shouldProcessHistoryMsg,
|
||||||
placeholderResendCache,
|
placeholderResendCache: placeholderResendCache as CacheStore,
|
||||||
ev,
|
ev,
|
||||||
creds: authState.creds,
|
creds: authState.creds,
|
||||||
keyStore: authState.keys,
|
keyStore: authState.keys,
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
const msgId = msgKey.id!
|
const msgId = msgKey.id!
|
||||||
|
|
||||||
const key = `${msgId}:${msgKey?.participant}`
|
const key = `${msgId}:${msgKey?.participant}`
|
||||||
let retryCount = msgRetryCache.get<number>(key) || 0
|
let retryCount = (msgRetryCache.get<number>(key) as number) || 0
|
||||||
if (retryCount >= maxMsgRetryCount) {
|
if (retryCount >= maxMsgRetryCount) {
|
||||||
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing')
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing')
|
||||||
msgRetryCache.del(key)
|
msgRetryCache.del(key)
|
||||||
@@ -585,13 +585,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
const willSendMessageAgain = (id: string, participant: string) => {
|
const willSendMessageAgain = (id: string, participant: string) => {
|
||||||
const key = `${id}:${participant}`
|
const key = `${id}:${participant}`
|
||||||
const retryCount = msgRetryCache.get<number>(key) || 0
|
const retryCount = (msgRetryCache.get<number>(key) as number) || 0
|
||||||
return retryCount < maxMsgRetryCount
|
return retryCount < maxMsgRetryCount
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateSendMessageAgainCount = (id: string, participant: string) => {
|
const updateSendMessageAgainCount = (id: string, participant: string) => {
|
||||||
const key = `${id}:${participant}`
|
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)
|
msgRetryCache.set(key, newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,8 +961,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
// use existing call info to populate this event
|
// use existing call info to populate this event
|
||||||
if (existingCall) {
|
if (existingCall) {
|
||||||
call.isVideo = existingCall.isVideo
|
call.isVideo = (existingCall as WACallEvent).isVideo
|
||||||
call.isGroup = existingCall.isGroup
|
call.isGroup = (existingCall as WACallEvent).isGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete data once call has ended
|
// delete data once call has ended
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
const user = jidDecode(jid)?.user
|
const user = jidDecode(jid)?.user
|
||||||
jid = jidNormalizedUser(jid)
|
jid = jidNormalizedUser(jid)
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
const devices = userDevicesCache.get<JidWithDevice[]>(user!)
|
const devices = userDevicesCache.get<JidWithDevice[]>(user!) as JidWithDevice[] | undefined
|
||||||
if (devices) {
|
if (devices && Array.isArray(devices)) {
|
||||||
deviceResults.push(...devices)
|
deviceResults.push(...devices)
|
||||||
|
|
||||||
logger.trace({ user }, 'using cache for devices')
|
logger.trace({ user }, 'using cache for devices')
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ export function makeCacheableSignalKeyStore(
|
|||||||
const idsToFetch: string[] = []
|
const idsToFetch: string[] = []
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const item = cache.get<SignalDataTypeMap[typeof type]>(getUniqueId(type, id))
|
const item = cache.get<SignalDataTypeMap[typeof type]>(getUniqueId(type, id))
|
||||||
if (typeof item !== 'undefined') {
|
if (typeof item !== 'undefined' && item !== null) {
|
||||||
data[id] = item
|
data[id] = item as SignalDataTypeMap[typeof type]
|
||||||
} else {
|
} else {
|
||||||
idsToFetch.push(id)
|
idsToFetch.push(id)
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ export function makeCacheableSignalKeyStore(
|
|||||||
const fetched = await store.get(type, idsToFetch)
|
const fetched = await store.get(type, idsToFetch)
|
||||||
for (const id of idsToFetch) {
|
for (const id of idsToFetch) {
|
||||||
const item = fetched[id]
|
const item = fetched[id]
|
||||||
if (item) {
|
if (item !== null && item !== undefined) {
|
||||||
data[id] = item
|
data[id] = item
|
||||||
cache.set(getUniqueId(type, id), item)
|
cache.set(getUniqueId(type, id), item)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export async function hkdf(
|
|||||||
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
|
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
|
||||||
|
|
||||||
// Import the input key material
|
// 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
|
// Derive bits using HKDF
|
||||||
const derivedBits = await subtle.deriveBits(
|
const derivedBits = await subtle.deriveBits(
|
||||||
@@ -167,7 +167,7 @@ export async function derivePairingCodeKey(pairingCode: string, salt: Buffer): P
|
|||||||
const derivedBits = await subtle.deriveBits(
|
const derivedBits = await subtle.deriveBits(
|
||||||
{
|
{
|
||||||
name: 'PBKDF2',
|
name: 'PBKDF2',
|
||||||
salt: saltBuffer,
|
salt: saltBuffer as BufferSource,
|
||||||
iterations: 2 << 16,
|
iterations: 2 << 16,
|
||||||
hash: 'SHA-256'
|
hash: 'SHA-256'
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const downloadHistory = async (msg: proto.Message.IHistorySyncNotificatio
|
|||||||
let buffer = Buffer.concat(bufferArray)
|
let buffer = Buffer.concat(bufferArray)
|
||||||
|
|
||||||
// decompress buffer
|
// decompress buffer
|
||||||
buffer = await inflatePromise(buffer)
|
buffer = Buffer.from(await inflatePromise(buffer))
|
||||||
|
|
||||||
const syncData = proto.HistorySync.decode(buffer)
|
const syncData = proto.HistorySync.decode(buffer)
|
||||||
return syncData
|
return syncData
|
||||||
|
|||||||
Reference in New Issue
Block a user