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 { attrs, content } = node
const isLid = attrs.from.includes('lid') const isLid = attrs.from.includes('lid')
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id) 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 const remoteJid = node.attrs.from
if(shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') { if(shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification') 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) => { const handleMessage = async(node: BinaryNode) => {
if(offline) {
await sendMessageAck(node)
return
}
if(shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') { if(shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
logger.debug({ key: node.attrs.key }, 'ignored message') logger.debug({ key: node.attrs.key }, 'ignored message')
await sendMessageAck(node) await sendMessageAck(node)
@@ -1004,7 +999,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
const makeOfflineNodeProcessor = () => { 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], ['message', handleMessage],
['call', handleCall], ['call', handleCall],
['receipt', handleReceipt], ['receipt', handleReceipt],
@@ -1036,7 +1031,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
continue continue
} }
await nodeProcessor(node, true) await nodeProcessor(node)
} }
isProcessing = false isProcessing = false
@@ -1050,7 +1045,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const offlineNodeProcessor = makeOfflineNodeProcessor() 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 const isOffline = !!node.attrs.offline
if(isOffline) { if(isOffline) {

View File

@@ -171,7 +171,7 @@ const encodeBinaryNodeInner = (
for(const char of str) { for(const char of str) {
const isInNibbleRange = char >= '0' && char <= '9' const isInNibbleRange = char >= '0' && char <= '9'
if(!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) { if(!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
return false return false
} }
} }
@@ -189,6 +189,8 @@ const encodeBinaryNodeInner = (
pushByte(tokenIndex.index) pushByte(tokenIndex.index)
} else if(isNibble(str)) { } else if(isNibble(str)) {
writePackedBytes(str, 'nibble') writePackedBytes(str, 'nibble')
} else if(isHex(str)) {
writePackedBytes(str, 'hex')
} else if(str) { } else if(str) {
const decodedJid = jidDecode(str) const decodedJid = jidDecode(str)
if(decodedJid) { if(decodedJid) {