From 85574d1d795f32f75f98dfd9ef52242960c68f2b Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Mon, 8 Nov 2021 00:18:59 +0530 Subject: [PATCH] Revert "fix: remove redundant collectionSync" This reverts commit e547d85f980fba405cae0a4d75457bc63a152245. --- src/Socket/chats.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index f88b71a..c2cbf42 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -167,6 +167,40 @@ export const makeChatsSocket = (config: SocketConfig) => { }) } + const collectionSync = async(collections: { name: WAPatchName, version: number }[]) => { + const result = await query({ + tag: 'iq', + attrs: { + to: S_WHATSAPP_NET, + xmlns: 'w:sync:app:state', + type: 'set' + }, + content: [ + { + tag: 'sync', + attrs: { }, + content: collections.map( + ({ name, version }) => ({ + tag: 'collection', + attrs: { name, version: version.toString(), return_snapshot: 'true' } + }) + ) + } + ] + }) + const syncNode = getBinaryNodeChild(result, 'sync') + const collectionNodes = getBinaryNodeChildren(syncNode, 'collection') + return collectionNodes.reduce( + (dict, node) => { + const snapshotNode = getBinaryNodeChild(node, 'snapshot') + if(snapshotNode) { + dict[node.attrs.name] = snapshotNode.content as Uint8Array + } + return dict + }, { } as { [P in WAPatchName]: Uint8Array } + ) + } + /** * fetch the profile picture of a user/group * type = "preview" for a low res picture