Async + Multi Cache (#1741)
* fix: handle invalid signatureKeyPublic types in sender-key-state
- added extra check to ensure signatureKeyPublic is either a base64 string or a Buffer
- fallback to empty buffer when unexpected object type is received
- prevents ERR_INVALID_ARG_TYPE error in Buffer.from
* adjusted based on @jlucaso1 recommmendation
* fix: handle chain key objects for skmsg group message decryption
previously, some sender chain keys were stored or retrieved as plain objects
(e.g. { '0': 85, '1': 100, ... }) instead of Buffers. this caused
"ERR_INVALID_ARG_TYPE" during initial decryption of skmsg group messages.
this fixes any chain key object is converted to a proper Buffer
before being passed to SenderChainKey.
* fix: add more robust checks and fallbacks
* feat: async cache
feat: async caching
* fix: linting issues
* fix: mget logic
---------
Co-authored-by: αѕтяσχ11 <devastro0010@gmail.com>
This commit is contained in:
@@ -76,7 +76,7 @@ export function makeCacheableSignalKeyStore(
|
||||
let keys = 0
|
||||
for (const type in data) {
|
||||
for (const id in data[type as keyof SignalDataTypeMap]) {
|
||||
cache.set(getUniqueId(type, id), data[type as keyof SignalDataTypeMap]![id]!)
|
||||
await cache.set(getUniqueId(type, id), data[type as keyof SignalDataTypeMap]![id]!)
|
||||
keys += 1
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export function makeCacheableSignalKeyStore(
|
||||
})
|
||||
},
|
||||
async clear() {
|
||||
cache.flushAll()
|
||||
await cache.flushAll()
|
||||
await store.clear?.()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export const prepareWAMessageMedia = async (
|
||||
}
|
||||
|
||||
if (cacheableKey) {
|
||||
const mediaBuff = options.mediaCache!.get<Buffer>(cacheableKey)
|
||||
const mediaBuff = await options.mediaCache!.get<Buffer>(cacheableKey)
|
||||
if (mediaBuff) {
|
||||
logger?.debug({ cacheableKey }, 'got media cache hit')
|
||||
|
||||
@@ -202,7 +202,7 @@ export const prepareWAMessageMedia = async (
|
||||
|
||||
if (cacheableKey) {
|
||||
logger?.debug({ cacheableKey }, 'set cache')
|
||||
options.mediaCache!.set(cacheableKey, WAProto.Message.encode(obj).finish())
|
||||
await options.mediaCache!.set(cacheableKey, WAProto.Message.encode(obj).finish())
|
||||
}
|
||||
|
||||
return obj
|
||||
@@ -305,7 +305,7 @@ export const prepareWAMessageMedia = async (
|
||||
|
||||
if (cacheableKey) {
|
||||
logger?.debug({ cacheableKey }, 'set cache')
|
||||
options.mediaCache!.set(cacheableKey, WAProto.Message.encode(obj).finish())
|
||||
await options.mediaCache!.set(cacheableKey, WAProto.Message.encode(obj).finish())
|
||||
}
|
||||
|
||||
return obj
|
||||
|
||||
@@ -264,7 +264,7 @@ const processMessage = async (
|
||||
case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
||||
const response = protocolMsg.peerDataOperationRequestResponseMessage!
|
||||
if (response) {
|
||||
placeholderResendCache?.del(response.stanzaId!)
|
||||
await placeholderResendCache?.del(response.stanzaId!)
|
||||
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
||||
const { peerDataOperationResult } = response
|
||||
for (const result of peerDataOperationResult!) {
|
||||
|
||||
Reference in New Issue
Block a user