mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: handle receipts more accurately
1. only send timestamp with read receipts 2. use unix timestamp in seconds instead of millis 3. use "sender" receipts for own messages
This commit is contained in:
@@ -3,8 +3,8 @@ import NodeCache from 'node-cache'
|
||||
import { proto } from '../../WAProto'
|
||||
import { WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig } from '../Types'
|
||||
import { encodeWAMessage, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions } from '../Utils'
|
||||
import { BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary'
|
||||
import { encodeWAMessage, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
||||
import { BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary'
|
||||
import { makeGroupsSocket } from './groups'
|
||||
|
||||
export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
@@ -85,22 +85,27 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
tag: 'receipt',
|
||||
attrs: {
|
||||
id: messageIds[0],
|
||||
to: jid,
|
||||
},
|
||||
}
|
||||
const isProtoReceipt = type === 'hist_sync' || type === 'peer_msg'
|
||||
if(!isProtoReceipt) {
|
||||
node.attrs.t = Date.now().toString()
|
||||
const isReadReceipt = type === 'read' || type === 'read-self'
|
||||
if(isReadReceipt) {
|
||||
node.attrs.t = unixTimestampSeconds().toString()
|
||||
}
|
||||
|
||||
if(type === 'sender' && isJidUser(jid)) {
|
||||
node.attrs.recipient = jid
|
||||
node.attrs.to = participant
|
||||
} else {
|
||||
node.attrs.to = jid
|
||||
if(participant) {
|
||||
node.attrs.participant = participant
|
||||
}
|
||||
}
|
||||
|
||||
if(type) {
|
||||
node.attrs.type = type
|
||||
}
|
||||
|
||||
if(participant) {
|
||||
node.attrs.participant = participant
|
||||
}
|
||||
|
||||
const remainingMessageIds = messageIds.slice(1)
|
||||
if(remainingMessageIds.length) {
|
||||
node.content = [
|
||||
@@ -115,7 +120,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
]
|
||||
}
|
||||
|
||||
logger.debug({ jid, messageIds, type }, 'sending receipt for messages')
|
||||
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages')
|
||||
await sendNode(node)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user