feat: implement account sync

This commit is contained in:
Adhiraj Singh
2021-11-08 00:18:29 +05:30
parent 56c17ce0d1
commit d796b286a6

View File

@@ -146,7 +146,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
})
}
const updateAccountSyncTimestamp = async() => {
const updateAccountSyncTimestamp = async(fromTimestamp: number | string) => {
logger.info({ fromTimestamp }, 'requesting account sync')
await sendNode({
tag: 'iq',
attrs: {
@@ -158,7 +159,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
content: [
{
tag: 'clean',
attrs: { }
attrs: {
type: 'account_sync',
timestamp: fromTimestamp.toString(),
}
}
]
})
@@ -408,6 +412,19 @@ export const makeChatsSocket = (config: SocketConfig) => {
ws.on('CB:presence', handlePresenceUpdate)
ws.on('CB:chatstate', handlePresenceUpdate)
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)
break
default:
logger.info({ node }, `received unknown sync`)
break
}
})
ws.on('CB:notification,type:server_sync', (node: BinaryNode) => {
const update = getBinaryNodeChild(node, 'collection')
if(update) {