messages-recv,encode: Implement proper fixes

This commit is contained in:
Rajeh Taher
2025-01-31 23:59:04 +02:00
parent fcbae0e3f2
commit b1fcab0216
2 changed files with 9 additions and 12 deletions

View File

@@ -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<MessageType, (node: BinaryNode, offline: boolean) => Promise<void>> = new Map([
const nodeProcessorMap: Map<MessageType, (node: BinaryNode) => Promise<void>> = 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<void>) => {
const processNode = (type: MessageType, node: BinaryNode, identifier: string, exec: (node: BinaryNode) => Promise<void>) => {
const isOffline = !!node.attrs.offline
if(isOffline) {

View File

@@ -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) {