From a07a63fa2858bfd86dc1df48fa366a76a09057b7 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 25 Nov 2021 15:20:47 +0530 Subject: [PATCH] perf: single process event for processSyncActions --- src/Socket/chats.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 2608efd..7ed3e5e 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -228,12 +228,13 @@ export const makeChatsSocket = (config: SocketConfig) => { if(newMutations.length) { logger.trace({ newMutations, name }, 'recv new mutations') } - processSyncActions(newMutations) totalMutations.push(...newMutations) } } + processSyncActions(totalMutations) + return totalMutations } @@ -419,9 +420,7 @@ export const makeChatsSocket = (config: SocketConfig) => { initial, authState.keys, ) - // temp: verify it was encoded correctly - const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState.keys.getAppStateSyncKey) - + const node: BinaryNode = { tag: 'iq', attrs: { @@ -458,6 +457,7 @@ export const makeChatsSocket = (config: SocketConfig) => { await authState.keys.setAppStateSyncVersion(name, state) if(config.emitOwnEvents) { + const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState.keys.getAppStateSyncKey) processSyncActions(result.newMutations) } }