mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: correctly handle presence being offline for receipts
When sendPresenceUpdate('unavailable') is called, it should allow notifications to be received on the phone
This commit is contained in:
@@ -9,7 +9,7 @@ import { makeMessagesSocket } from './messages-send'
|
||||
const MAX_SYNC_ATTEMPTS = 5
|
||||
|
||||
export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const { logger } = config
|
||||
const { logger, markOnlineOnConnect } = config
|
||||
const sock = makeMessagesSocket(config)
|
||||
const {
|
||||
ev,
|
||||
@@ -379,6 +379,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
return
|
||||
}
|
||||
|
||||
ev.emit('connection.update', { isOnline: type === 'available' })
|
||||
|
||||
await sendNode({
|
||||
tag: 'presence',
|
||||
attrs: {
|
||||
@@ -467,7 +469,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const events = processSyncActions(actions, authState.creds.me!, logger)
|
||||
emitEventsFromMap(events)
|
||||
// resend available presence to update name on servers
|
||||
if(events['creds.update']?.me?.name) {
|
||||
if(events['creds.update']?.me?.name && markOnlineOnConnect) {
|
||||
sendPresenceUpdate('available')
|
||||
}
|
||||
}
|
||||
@@ -610,7 +612,9 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
fetchProps(),
|
||||
fetchBlocklist(),
|
||||
fetchPrivacySettings(),
|
||||
sendPresenceUpdate('available')
|
||||
markOnlineOnConnect
|
||||
? sendPresenceUpdate('available')
|
||||
: undefined
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
const historyCache = new Set<string>()
|
||||
|
||||
let sendActiveReceipts = false
|
||||
|
||||
const sendMessageAck = async({ tag, attrs }: BinaryNode, extraAttrs: BinaryNodeAttributes = { }) => {
|
||||
const stanza: BinaryNode = {
|
||||
tag: 'ack',
|
||||
@@ -511,6 +513,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
if(isJidUser(msg.key.remoteJid)) {
|
||||
participant = author
|
||||
}
|
||||
} else if(!sendActiveReceipts) {
|
||||
type = 'inactive'
|
||||
}
|
||||
|
||||
await sendReceipt(msg.key.remoteJid!, participant, [msg.key.id!], type)
|
||||
@@ -617,6 +621,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
})
|
||||
|
||||
ev.on('connection.update', ({ isOnline }) => {
|
||||
if(typeof isOnline !== 'undefined') {
|
||||
sendActiveReceipts = isOnline
|
||||
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`)
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
...sock,
|
||||
processMessage: processMessageLocal,
|
||||
|
||||
Reference in New Issue
Block a user