mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: implement account sync
This commit is contained in:
@@ -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({
|
await sendNode({
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -158,7 +159,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
tag: 'clean',
|
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:presence', handlePresenceUpdate)
|
||||||
ws.on('CB:chatstate', 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) => {
|
ws.on('CB:notification,type:server_sync', (node: BinaryNode) => {
|
||||||
const update = getBinaryNodeChild(node, 'collection')
|
const update = getBinaryNodeChild(node, 'collection')
|
||||||
if(update) {
|
if(update) {
|
||||||
|
|||||||
Reference in New Issue
Block a user