mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: push failed decryption messages as "CIPHERTEXT"
This commit is contained in:
@@ -342,14 +342,28 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
// recv a message
|
// recv a message
|
||||||
ws.on('CB:message', async(stanza: BinaryNode) => {
|
ws.on('CB:message', async(stanza: BinaryNode) => {
|
||||||
const dec = await decodeMessageStanza(stanza, authState)
|
const dec = await decodeMessageStanza(stanza, authState)
|
||||||
const fullMessages: proto.IWebMessageInfo[] = []
|
if(dec.successes.length) {
|
||||||
for(const msg of dec.successes) {
|
ev.emit('auth-state.update', authState)
|
||||||
const { attrs } = stanza
|
}
|
||||||
const isGroup = !!stanza.attrs.participant
|
|
||||||
const sender = (attrs.participant || attrs.from)?.toString()
|
|
||||||
const isMe = areJidsSameUser(sender, authState.creds.me!.id)
|
|
||||||
|
|
||||||
// send delivery receipt
|
const fullMessages: proto.IWebMessageInfo[] = []
|
||||||
|
|
||||||
|
const { attrs } = stanza
|
||||||
|
const isGroup = !!stanza.attrs.participant
|
||||||
|
const sender = (attrs.participant || attrs.from)?.toString()
|
||||||
|
const isMe = areJidsSameUser(sender, authState.creds.me!.id)
|
||||||
|
|
||||||
|
const remoteJid = jidNormalizedUser(dec.chatId)
|
||||||
|
|
||||||
|
const key: WAMessageKey = {
|
||||||
|
remoteJid,
|
||||||
|
fromMe: isMe,
|
||||||
|
id: dec.msgId,
|
||||||
|
participant: dec.participant
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const msg of dec.successes) {
|
||||||
|
// send message receipt
|
||||||
let recpAttrs: { [_: string]: any }
|
let recpAttrs: { [_: string]: any }
|
||||||
if(isMe) {
|
if(isMe) {
|
||||||
recpAttrs = {
|
recpAttrs = {
|
||||||
@@ -383,16 +397,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
await sendDeliveryReceipt(dec.chatId, dec.participant, [dec.msgId])
|
await sendDeliveryReceipt(dec.chatId, dec.participant, [dec.msgId])
|
||||||
logger.debug({ msgId: dec.msgId }, 'sent delivery receipt')
|
logger.debug({ msgId: dec.msgId }, 'sent delivery receipt')
|
||||||
|
|
||||||
const remoteJid = jidNormalizedUser(dec.chatId)
|
|
||||||
|
|
||||||
const message = msg.deviceSentMessage?.message || msg
|
const message = msg.deviceSentMessage?.message || msg
|
||||||
fullMessages.push({
|
fullMessages.push({
|
||||||
key: {
|
key,
|
||||||
remoteJid,
|
|
||||||
fromMe: isMe,
|
|
||||||
id: dec.msgId,
|
|
||||||
participant: dec.participant
|
|
||||||
},
|
|
||||||
message,
|
message,
|
||||||
status: isMe ? proto.WebMessageInfo.WebMessageInfoStatus.SERVER_ACK : null,
|
status: isMe ? proto.WebMessageInfo.WebMessageInfoStatus.SERVER_ACK : null,
|
||||||
messageTimestamp: dec.timestamp,
|
messageTimestamp: dec.timestamp,
|
||||||
@@ -400,19 +407,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
participant: dec.participant
|
participant: dec.participant
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dec.successes.length) {
|
|
||||||
ev.emit('auth-state.update', authState)
|
|
||||||
if(fullMessages.length) {
|
|
||||||
ev.emit(
|
|
||||||
'messages.upsert',
|
|
||||||
{
|
|
||||||
messages: fullMessages.map(m => proto.WebMessageInfo.fromObject(m)),
|
|
||||||
type: stanza.attrs.offline ? 'append' : 'notify'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(const { error } of dec.failures) {
|
for(const { error } of dec.failures) {
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -420,6 +414,22 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
'failure in decrypting message'
|
'failure in decrypting message'
|
||||||
)
|
)
|
||||||
await sendRetryRequest(stanza)
|
await sendRetryRequest(stanza)
|
||||||
|
|
||||||
|
fullMessages.push({
|
||||||
|
key,
|
||||||
|
messageStubType: WAMessageStubType.CIPHERTEXT,
|
||||||
|
messageStubParameters: [error.message]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fullMessages.length) {
|
||||||
|
ev.emit(
|
||||||
|
'messages.upsert',
|
||||||
|
{
|
||||||
|
messages: fullMessages.map(m => proto.WebMessageInfo.fromObject(m)),
|
||||||
|
type: stanza.attrs.offline ? 'append' : 'notify'
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user