From 913b38493c863af7f8bac056a5664291512d36c2 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 17 Feb 2022 10:32:51 +0530 Subject: [PATCH] fix: throw error if no decrypt-able message found --- src/Utils/decode-wa-message.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index 320ca5e..aa8673a 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -5,12 +5,11 @@ import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBro import { unpadRandomMax16 } from './generics' import { decryptGroupSignalProto, decryptSignalProto, processSenderKeyMessage } from './signal' +const NO_MESSAGE_FOUND_ERROR_TEXT = 'No message found' + type MessageType = 'chat' | 'peer_broadcast' | 'other_broadcast' | 'group' | 'direct_peer_status' | 'other_status' export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationState) => { - //const deviceIdentity = (stanza.content as BinaryNodeM[])?.find(m => m.tag === 'device-identity') - //const deviceIdentityBytes = deviceIdentity ? deviceIdentity.content as Buffer : undefined - let msgType: MessageType let chatId: string let author: string @@ -84,6 +83,7 @@ export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationStat return { fullMessage, decryptionTask: (async() => { + let decryptables = 0 if(Array.isArray(stanza.content)) { for(const { tag, attrs, content } of stanza.content) { if(tag !== 'enc') { @@ -93,6 +93,8 @@ export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationStat if(!(content instanceof Uint8Array)) { continue } + + decryptables += 1 let msgBuffer: Buffer @@ -126,6 +128,12 @@ export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationStat } } } + + // if nothing was found to decrypt + if(!decryptables) { + fullMessage.messageStubType = proto.WebMessageInfo.WebMessageInfoStubType.CIPHERTEXT + fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT] + } })() } } \ No newline at end of file