From 7b42fa5a54ed71c28e4992db4adc38779e6d909d Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 25 Nov 2021 00:37:44 +0530 Subject: [PATCH] fix: correct operation type on chat patch --- src/Types/Chat.ts | 1 + src/Utils/chat-utils.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Types/Chat.ts b/src/Types/Chat.ts index 9fec2bb..2214381 100644 --- a/src/Types/Chat.ts +++ b/src/Types/Chat.ts @@ -17,6 +17,7 @@ export type WAPatchCreate = { index: string[] type: WAPatchName apiVersion: number + operation: proto.SyncdMutation.SyncdMutationSyncdOperation } export type Chat = Omit & { diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 9fa22de..11238d1 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -109,7 +109,7 @@ const generatePatchMac = (snapshotMac: Uint8Array, valueMacs: Uint8Array[], vers export const newLTHashState = (): LTHashState => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} }) export const encodeSyncdPatch = async( - { type, index, syncAction, apiVersion }: WAPatchCreate, + { type, index, syncAction, apiVersion, operation }: WAPatchCreate, { creds: { myAppStateKeyId }, keys }: AuthenticationState ) => { const key = !!myAppStateKeyId ? await keys.getAppStateSyncKey(myAppStateKeyId) : undefined @@ -118,8 +118,6 @@ export const encodeSyncdPatch = async( } const encKeyId = Buffer.from(myAppStateKeyId, 'base64') - const operation = proto.SyncdMutation.SyncdMutationSyncdOperation.SET - const state = { ...await keys.getAppStateSyncVersion(type) } const indexBuffer = Buffer.from(JSON.stringify(index)) @@ -418,6 +416,7 @@ export const chatModificationToAppPatch = ( jid: string, lastMessages: Pick[] ) => { + const OP = proto.SyncdMutation.SyncdMutationSyncdOperation const messageRange: proto.ISyncActionMessageRange = { lastMessageTimestamp: lastMessages[lastMessages.length-1].messageTimestamp, messages: lastMessages @@ -435,7 +434,8 @@ export const chatModificationToAppPatch = ( }, index: ['mute', jid], type: 'regular_high', - apiVersion: 2 + apiVersion: 2, + operation: mod.mute ? OP.SET : OP.REMOVE } } else if('archive' in mod) { patch = { @@ -448,7 +448,8 @@ export const chatModificationToAppPatch = ( }, index: ['archive', jid], type: 'regular_low', - apiVersion: 3 + apiVersion: 3, + operation: mod.archive ? OP.SET : OP.REMOVE } } else if('markRead' in mod) { patch = { @@ -461,7 +462,8 @@ export const chatModificationToAppPatch = ( }, index: ['markChatAsRead', jid], type: 'regular_low', - apiVersion: 3 + apiVersion: 3, + operation: !mod.markRead ? OP.SET : OP.REMOVE } } else if('clear' in mod) { if(mod.clear === 'all') { @@ -478,6 +480,7 @@ export const chatModificationToAppPatch = ( index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'], type: 'regular_high', apiVersion: 3, + operation: OP.SET } } } else {