mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: proper send receipt to Meta Ia trigger messages to avoid offline pending notifications hang
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { SignalRepository, WAMessageKey } from '../Types'
|
import { SignalRepository, WAMessageKey } from '../Types'
|
||||||
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidMetaIa, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
|
||||||
import { unpadRandomMax16 } from './generics'
|
import { unpadRandomMax16 } from './generics'
|
||||||
import { ILogger } from './logger'
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
@@ -47,27 +47,14 @@ export function decodeMessageNode(
|
|||||||
const isMe = (jid: string) => areJidsSameUser(jid, meId)
|
const isMe = (jid: string) => areJidsSameUser(jid, meId)
|
||||||
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
|
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
|
||||||
|
|
||||||
if(isJidUser(from)) {
|
if(isJidUser(from) || isLidUser(from)) {
|
||||||
if(recipient) {
|
if (recipient && !isJidMetaIa(recipient)) {
|
||||||
if(!isMe(from)) {
|
if(!isMe(from) && !isMeLid(from)) {
|
||||||
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
||||||
}
|
}
|
||||||
|
|
||||||
chatId = recipient
|
chatId = recipient
|
||||||
} else {
|
} else {
|
||||||
chatId = from
|
|
||||||
}
|
|
||||||
|
|
||||||
msgType = 'chat'
|
|
||||||
author = from
|
|
||||||
} else if(isLidUser(from)) {
|
|
||||||
if(recipient) {
|
|
||||||
if(!isMeLid(from)) {
|
|
||||||
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
|
||||||
}
|
|
||||||
|
|
||||||
chatId = recipient
|
|
||||||
} else {
|
|
||||||
chatId = from
|
chatId = from
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +109,8 @@ export function decodeMessageNode(
|
|||||||
|
|
||||||
if(key.fromMe) {
|
if(key.fromMe) {
|
||||||
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK
|
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fullMessage,
|
fullMessage,
|
||||||
author,
|
author,
|
||||||
@@ -183,7 +170,7 @@ export const decryptMessageNode = (
|
|||||||
type: e2eType,
|
type: e2eType,
|
||||||
ciphertext: content
|
ciphertext: content
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'plaintext':
|
case 'plaintext':
|
||||||
msgBuffer = content
|
msgBuffer = content
|
||||||
break
|
break
|
||||||
@@ -209,7 +196,7 @@ export const decryptMessageNode = (
|
|||||||
Object.assign(fullMessage.message, msg)
|
Object.assign(fullMessage.message, msg)
|
||||||
} else {
|
} else {
|
||||||
fullMessage.message = msg
|
fullMessage.message = msg
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ key: fullMessage.key, err },
|
{ key: fullMessage.key, err },
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
|||||||
export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefined) => (
|
export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefined) => (
|
||||||
jidDecode(jid1)?.user === jidDecode(jid2)?.user
|
jidDecode(jid1)?.user === jidDecode(jid2)?.user
|
||||||
)
|
)
|
||||||
|
/** is the jid Meta IA */
|
||||||
|
export const isJidMetaIa = (jid: string | undefined) => (jid?.endsWith('@bot'))
|
||||||
/** is the jid a user */
|
/** is the jid a user */
|
||||||
export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net'))
|
export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net'))
|
||||||
/** is the jid a group */
|
/** is the jid a group */
|
||||||
|
|||||||
Reference in New Issue
Block a user