From f9ffb0f4c8f9b002f152b3faef916cb674630bf8 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sun, 3 Apr 2022 00:14:34 +0530 Subject: [PATCH] refactor: send history sync later --- src/Socket/messages-recv.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 734faa2..7f14c75 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -140,13 +140,25 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { }) } - const processMessageLocal = async(message: proto.IWebMessageInfo) => { + const processMessageLocal = async(msg: proto.IWebMessageInfo) => { const meId = authState.creds.me!.id // process message and emit events const newEvents = await processMessage( - message, + msg, { historyCache, meId, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal } ) + + // send ack for history message + const normalizedContent = !!msg.message ? normalizeMessageContent(msg.message) : undefined + const isAnyHistoryMsg = !!normalizedContent?.protocolMessage?.historySyncNotification + if(isAnyHistoryMsg) { + await sendReceipt(msg.key.remoteJid!, undefined, [msg.key.id], 'hist_sync') + // we only want to sync app state once we've all the history + // restart the app state sync timeout + logger.debug('restarting app sync timeout') + appStateSyncTimeout.start() + } + return newEvents } @@ -456,17 +468,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { // no type in the receipt => message delivered await sendReceipt(msg.key.remoteJid!, msg.key.participant, [msg.key.id!], undefined) - // send ack for history message - const normalizedContent = !!msg.message ? normalizeMessageContent(msg.message) : undefined - const isAnyHistoryMsg = !!normalizedContent?.protocolMessage?.historySyncNotification - if(isAnyHistoryMsg) { - await sendReceipt(msg.key.remoteJid!, undefined, [msg.key.id], 'hist_sync') - // we only want to sync app state once we've all the history - // restart the app state sync timeout - logger.debug('restarting app sync timeout') - appStateSyncTimeout.start() - } - if(category === 'peer') { await sendReceipt(msg.key.remoteJid!, undefined, [msg.key.id], 'peer_msg') }