From f5fcaa36f3c4898dcc0f7f8c6e1f66e7005576ab Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 25 Nov 2021 13:52:18 +0530 Subject: [PATCH] feat: (hopefully) correctly implement account timestamp sync --- src/Socket/chats.ts | 11 ++++++++--- src/Types/Auth.ts | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 684c631..2608efd 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -472,18 +472,23 @@ export const makeChatsSocket = (config: SocketConfig) => { ws.on('CB:presence', handlePresenceUpdate) ws.on('CB:chatstate', handlePresenceUpdate) - /*ws.on('CB:ib,,dirty', async(node: BinaryNode) => { + ws.on('CB:ib,,dirty', async(node: BinaryNode) => { const { attrs } = getBinaryNodeChild(node, 'dirty') const type = attrs.type switch(type) { case 'account_sync': - await updateAccountSyncTimestamp(attrs.timestamp) + let { lastAccountSyncTimestamp } = authState.creds + if(lastAccountSyncTimestamp) { + await updateAccountSyncTimestamp(lastAccountSyncTimestamp) + } + lastAccountSyncTimestamp = +attrs.timestamp + ev.emit('creds.update', { lastAccountSyncTimestamp }) break default: logger.info({ node }, `received unknown sync`) break } - })*/ + }) ws.on('CB:notification,type:server_sync', (node: BinaryNode) => { const update = getBinaryNodeChild(node, 'collection') diff --git a/src/Types/Auth.ts b/src/Types/Auth.ts index 80fd367..7a3e749 100644 --- a/src/Types/Auth.ts +++ b/src/Types/Auth.ts @@ -39,6 +39,8 @@ export type AuthenticationCreds = SignalCreds & { firstUnuploadedPreKeyId: number serverHasPreKeys: boolean nextPreKeyId: number + + lastAccountSyncTimestamp?: number } type Awaitable = T | Promise