mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: incorrect updates being forwarded to messages.update
This commit is contained in:
@@ -7,7 +7,15 @@ import { KEY_BUNDLE_TYPE } from "../Defaults"
|
|||||||
import { makeChatsSocket } from "./chats"
|
import { makeChatsSocket } from "./chats"
|
||||||
import { extractGroupMetadata } from "./groups"
|
import { extractGroupMetadata } from "./groups"
|
||||||
|
|
||||||
const isReadReceipt = (type: string) => type === 'read' || type === 'read-self'
|
const getStatusFromReceiptType = (type: string | undefined) => {
|
||||||
|
if(type === 'read' || type === 'read-self') {
|
||||||
|
return proto.WebMessageInfo.WebMessageInfoStatus.READ
|
||||||
|
}
|
||||||
|
if(typeof type === 'undefined') {
|
||||||
|
return proto.WebMessageInfo.WebMessageInfoStatus.DELIVERY_ACK
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||||
const { logger } = config
|
const { logger } = config
|
||||||
@@ -458,25 +466,27 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
const handleReceipt = async(node: BinaryNode) => {
|
const handleReceipt = async(node: BinaryNode) => {
|
||||||
const { attrs, content } = node
|
const { attrs, content } = node
|
||||||
const isRead = isReadReceipt(attrs.type)
|
const status = getStatusFromReceiptType(attrs.type)
|
||||||
const status = isRead ? proto.WebMessageInfo.WebMessageInfoStatus.READ : proto.WebMessageInfo.WebMessageInfoStatus.DELIVERY_ACK
|
|
||||||
const ids = [attrs.id]
|
|
||||||
if(Array.isArray(content)) {
|
|
||||||
const items = getBinaryNodeChildren(content[0], 'item')
|
|
||||||
ids.push(...items.map(i => i.attrs.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
const remoteJid = attrs.recipient || attrs.from
|
if(typeof status !== 'undefined' && !areJidsSameUser(attrs.from, authState.creds.me?.id)) {
|
||||||
const fromMe = attrs.recipient ? false : true
|
const ids = [attrs.id]
|
||||||
ev.emit('messages.update', ids.map(id => ({
|
if(Array.isArray(content)) {
|
||||||
key: {
|
const items = getBinaryNodeChildren(content[0], 'item')
|
||||||
remoteJid,
|
ids.push(...items.map(i => i.attrs.id))
|
||||||
id: id,
|
}
|
||||||
fromMe,
|
|
||||||
participant: attrs.participant
|
const remoteJid = attrs.recipient || attrs.from
|
||||||
},
|
const fromMe = attrs.recipient ? false : true
|
||||||
update: { status }
|
ev.emit('messages.update', ids.map(id => ({
|
||||||
})))
|
key: {
|
||||||
|
remoteJid,
|
||||||
|
id: id,
|
||||||
|
fromMe,
|
||||||
|
participant: attrs.participant
|
||||||
|
},
|
||||||
|
update: { status }
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
|
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user