diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 9928742..c70b5f3 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -1,7 +1,7 @@ import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, LTHashState, ChatModification, Contact } from "../Types"; import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary"; import { proto } from '../../WAProto' -import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch, decodeSyncdSnapshot } from "../Utils"; +import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch, decodeSyncdSnapshot, newLTHashState } from "../Utils"; import { makeMessagesSocket } from "./messages-send"; import makeMutex from "../Utils/make-mutex"; @@ -176,7 +176,7 @@ export const makeChatsSocket = (config: SocketConfig) => { const states = { } as { [T in WAPatchName]: LTHashState } for(const name of collections) { let state: LTHashState = fromScratch ? undefined : await authState.keys.getAppStateSyncVersion(name) - if(!state) state = { version: 0, hash: Buffer.alloc(128), mutations: [] } + if(!state) state = newLTHashState() states[name] = state diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index a55bd4e..0ed6d81 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -95,6 +95,8 @@ const generatePatchMac = (snapshotMac: Uint8Array, valueMacs: Uint8Array[], vers return hmacSign(total, key) } +export const newLTHashState = (): LTHashState => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} }) + export const encodeSyncdPatch = async( { type, index, syncAction, apiVersion }: WAPatchCreate, { creds: { myAppStateKeyId }, keys }: AuthenticationState