From b1fcab021646fd212de4e9a50e5d65f0a1fbe024 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Fri, 31 Jan 2025 23:59:04 +0200 Subject: [PATCH] messages-recv,encode: Implement proper fixes --- src/Socket/messages-recv.ts | 17 ++++++----------- src/WABinary/encode.ts | 4 +++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 014b5bb..85160d0 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -601,7 +601,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } } - const handleReceipt = async(node: BinaryNode, offline: boolean) => { + const handleReceipt = async(node: BinaryNode) => { const { attrs, content } = node const isLid = attrs.from.includes('lid') const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id) @@ -693,7 +693,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } } - const handleNotification = async(node: BinaryNode, offline: boolean) => { + const handleNotification = async(node: BinaryNode) => { const remoteJid = node.attrs.from if(shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') { logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification') @@ -729,12 +729,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } } - const handleMessage = async(node: BinaryNode, offline: boolean) => { - if(offline) { - await sendMessageAck(node) - return - } - + const handleMessage = async(node: BinaryNode) => { if(shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') { logger.debug({ key: node.attrs.key }, 'ignored message') await sendMessageAck(node) @@ -1004,7 +999,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } const makeOfflineNodeProcessor = () => { - const nodeProcessorMap: Map Promise> = new Map([ + const nodeProcessorMap: Map Promise> = new Map([ ['message', handleMessage], ['call', handleCall], ['receipt', handleReceipt], @@ -1036,7 +1031,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { continue } - await nodeProcessor(node, true) + await nodeProcessor(node) } isProcessing = false @@ -1050,7 +1045,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const offlineNodeProcessor = makeOfflineNodeProcessor() - const processNode = (type: MessageType, node: BinaryNode, identifier: string, exec: (node: BinaryNode, offline: boolean) => Promise) => { + const processNode = (type: MessageType, node: BinaryNode, identifier: string, exec: (node: BinaryNode) => Promise) => { const isOffline = !!node.attrs.offline if(isOffline) { diff --git a/src/WABinary/encode.ts b/src/WABinary/encode.ts index 6591a81..f1168a6 100644 --- a/src/WABinary/encode.ts +++ b/src/WABinary/encode.ts @@ -171,7 +171,7 @@ const encodeBinaryNodeInner = ( for(const char of str) { const isInNibbleRange = char >= '0' && char <= '9' - if(!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) { + if(!isInNibbleRange && !(char >= 'A' && char <= 'F')) { return false } } @@ -189,6 +189,8 @@ const encodeBinaryNodeInner = ( pushByte(tokenIndex.index) } else if(isNibble(str)) { writePackedBytes(str, 'nibble') + } else if(isHex(str)) { + writePackedBytes(str, 'hex') } else if(str) { const decodedJid = jidDecode(str) if(decodedJid) {