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:
Adhiraj Singh
2022-06-01 13:20:21 +05:30
parent cafc707628
commit 6824a203d0
7 changed files with 29 additions and 5 deletions

View File

@@ -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,