mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: throw error if no decrypt-able message found
This commit is contained in:
@@ -5,12 +5,11 @@ import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBro
|
|||||||
import { unpadRandomMax16 } from './generics'
|
import { unpadRandomMax16 } from './generics'
|
||||||
import { decryptGroupSignalProto, decryptSignalProto, processSenderKeyMessage } from './signal'
|
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'
|
type MessageType = 'chat' | 'peer_broadcast' | 'other_broadcast' | 'group' | 'direct_peer_status' | 'other_status'
|
||||||
|
|
||||||
export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationState) => {
|
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 msgType: MessageType
|
||||||
let chatId: string
|
let chatId: string
|
||||||
let author: string
|
let author: string
|
||||||
@@ -84,6 +83,7 @@ export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationStat
|
|||||||
return {
|
return {
|
||||||
fullMessage,
|
fullMessage,
|
||||||
decryptionTask: (async() => {
|
decryptionTask: (async() => {
|
||||||
|
let decryptables = 0
|
||||||
if(Array.isArray(stanza.content)) {
|
if(Array.isArray(stanza.content)) {
|
||||||
for(const { tag, attrs, content } of stanza.content) {
|
for(const { tag, attrs, content } of stanza.content) {
|
||||||
if(tag !== 'enc') {
|
if(tag !== 'enc') {
|
||||||
@@ -93,6 +93,8 @@ export const decodeMessageStanza = (stanza: BinaryNode, auth: AuthenticationStat
|
|||||||
if(!(content instanceof Uint8Array)) {
|
if(!(content instanceof Uint8Array)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decryptables += 1
|
||||||
|
|
||||||
let msgBuffer: Buffer
|
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]
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user