fix: incorrect updates being forwarded to messages.update

This commit is contained in:
Adhiraj Singh
2021-11-26 10:31:46 +05:30
parent 6786576d13
commit b9d37a06a3

View File

@@ -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,8 +466,9 @@ 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
if(typeof status !== 'undefined' && !areJidsSameUser(attrs.from, authState.creds.me?.id)) {
const ids = [attrs.id] const ids = [attrs.id]
if(Array.isArray(content)) { if(Array.isArray(content)) {
const items = getBinaryNodeChildren(content[0], 'item') const items = getBinaryNodeChildren(content[0], 'item')
@@ -477,6 +486,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
}, },
update: { status } update: { status }
}))) })))
}
await sendMessageAck(node, { class: 'receipt', type: attrs.type }) await sendMessageAck(node, { class: 'receipt', type: attrs.type })
} }