mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Android chat read fix + debounceTimeout bug fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@adiwajshing/baileys",
|
"name": "@adiwajshing/baileys",
|
||||||
"version": "3.2.3",
|
"version": "3.2.4",
|
||||||
"description": "WhatsApp Web API",
|
"description": "WhatsApp Web API",
|
||||||
"homepage": "https://github.com/adiwajshing/Baileys",
|
"homepage": "https://github.com/adiwajshing/Baileys",
|
||||||
"main": "lib/WAConnection/WAConnection.js",
|
"main": "lib/WAConnection/WAConnection.js",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const testJid = process.env.TEST_JID || '1234@s.whatsapp.net' // set TEST
|
|||||||
|
|
||||||
export const makeConnection = () => {
|
export const makeConnection = () => {
|
||||||
const conn = new WAConnection()
|
const conn = new WAConnection()
|
||||||
conn.connectOptions.maxIdleTimeMs = 30_000
|
conn.connectOptions.maxIdleTimeMs = 45_000
|
||||||
conn.logger.level = 'debug'
|
conn.logger.level = 'debug'
|
||||||
|
|
||||||
let evCounts = {}
|
let evCounts = {}
|
||||||
|
|||||||
@@ -71,21 +71,24 @@ WAConnectionTest('Misc', (conn) => {
|
|||||||
assert.ok(response)
|
assert.ok(response)
|
||||||
})
|
})
|
||||||
it('should change a chat read status', async () => {
|
it('should change a chat read status', async () => {
|
||||||
const waitForEvent = new Promise (resolve => {
|
const jids = conn.chats.all ().map (c => c.jid)
|
||||||
conn.on ('chat-update', ({jid, count}) => {
|
for (let jid of jids.slice(0, 5)) {
|
||||||
if (jid === testJid) {
|
console.log (`changing read status for ${jid}`)
|
||||||
assert.ok (count < 0)
|
const waitForEvent = new Promise (resolve => {
|
||||||
conn.removeAllListeners ('chat-update')
|
conn.once ('chat-update', ({jid: tJid, count}) => {
|
||||||
resolve ()
|
if (jid === tJid) {
|
||||||
}
|
assert.ok (count < 0)
|
||||||
|
resolve ()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
await conn.chatRead (jid, 'unread')
|
||||||
await conn.chatRead (testJid, 'unread')
|
await waitForEvent
|
||||||
await waitForEvent
|
|
||||||
|
await delay (5000)
|
||||||
await delay (5000)
|
|
||||||
|
await conn.chatRead (jid, 'read')
|
||||||
await conn.chatRead (testJid, 'read')
|
}
|
||||||
})
|
})
|
||||||
it('should archive & unarchive', async () => {
|
it('should archive & unarchive', async () => {
|
||||||
await conn.modifyChat (testJid, ChatModification.archive)
|
await conn.modifyChat (testJid, ChatModification.archive)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class WAConnection extends EventEmitter {
|
|||||||
state: WAConnectionState = 'close'
|
state: WAConnectionState = 'close'
|
||||||
connectOptions: WAConnectOptions = {
|
connectOptions: WAConnectOptions = {
|
||||||
regenerateQRIntervalMs: 30_000,
|
regenerateQRIntervalMs: 30_000,
|
||||||
maxIdleTimeMs: 15_000,
|
maxIdleTimeMs: 40_000,
|
||||||
waitOnlyForLastMessage: false,
|
waitOnlyForLastMessage: false,
|
||||||
waitForChats: true,
|
waitForChats: true,
|
||||||
maxRetries: 10,
|
maxRetries: 10,
|
||||||
@@ -219,6 +219,10 @@ export class WAConnection extends EventEmitter {
|
|||||||
tag = tag || this.generateMessageTag (longTag)
|
tag = tag || this.generateMessageTag (longTag)
|
||||||
const promise = this.waitForMessage(tag, json, requiresPhoneConnection, timeoutMs)
|
const promise = this.waitForMessage(tag, json, requiresPhoneConnection, timeoutMs)
|
||||||
|
|
||||||
|
if (this.logger.level === 'trace') {
|
||||||
|
this.logger.trace ({ fromMe: true },`${tag},${JSON.stringify(json)}`)
|
||||||
|
}
|
||||||
|
|
||||||
if (binaryTags) tag = await this.sendBinary(json as WANode, binaryTags, tag)
|
if (binaryTags) tag = await this.sendBinary(json as WANode, binaryTags, tag)
|
||||||
else tag = await this.sendJSON(json, tag)
|
else tag = await this.sendJSON(json, tag)
|
||||||
|
|
||||||
@@ -238,7 +242,7 @@ export class WAConnection extends EventEmitter {
|
|||||||
{query: json, message, status: response.status}
|
{query: json, message, status: response.status}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (startDebouncedTimeout) this.stopDebouncedTimeout ()
|
if (startDebouncedTimeout) this.startDebouncedTimeout ()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
/** interval is started when a query takes too long to respond */
|
/** interval is started when a query takes too long to respond */
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ export class WAConnection extends Base {
|
|||||||
jid = whatsappID (jid)
|
jid = whatsappID (jid)
|
||||||
const chat = this.assertChatGet (jid)
|
const chat = this.assertChatGet (jid)
|
||||||
|
|
||||||
if (type === 'unread') await this.sendReadReceipt (jid, null, -2)
|
const message = (await this.loadMessages(jid, 1)).messages[0]
|
||||||
else if (chat.count !== 0) {
|
const count = type === 'unread' ? -2 : Math.abs(chat.count)
|
||||||
const {messages} = await this.loadMessages (jid, 1)
|
if (type === 'unread' || chat.count !== 0) {
|
||||||
await this.sendReadReceipt (jid, messages[0].key, Math.abs(chat.count))
|
await this.sendReadReceipt (jid, message.key, count)
|
||||||
}
|
}
|
||||||
chat.count = type === 'unread' ? -1 : 0
|
chat.count = type === 'unread' ? -1 : 0
|
||||||
this.emit ('chat-update', {jid, count: chat.count})
|
this.emit ('chat-update', {jid, count: chat.count})
|
||||||
@@ -59,14 +59,15 @@ export class WAConnection extends Base {
|
|||||||
* @param messageKey the key of the message
|
* @param messageKey the key of the message
|
||||||
* @param count number of messages to read, set to < 0 to unread a message
|
* @param count number of messages to read, set to < 0 to unread a message
|
||||||
*/
|
*/
|
||||||
async sendReadReceipt(jid: string, messageKey: { id?: string, fromMe?: boolean }, count: number) {
|
async sendReadReceipt(jid: string, messageKey: WAMessageKey, count: number) {
|
||||||
const attributes = {
|
const attributes = {
|
||||||
jid: jid,
|
jid,
|
||||||
count: count.toString(),
|
count: count.toString(),
|
||||||
index: messageKey?.id,
|
index: messageKey?.id,
|
||||||
|
participant: messageKey?.participant || undefined,
|
||||||
owner: messageKey?.fromMe?.toString()
|
owner: messageKey?.fromMe?.toString()
|
||||||
}
|
}
|
||||||
const read = await this.setQuery ([['read', attributes, null]])
|
const read = await this.setQuery ([['read', attributes, null]], [ WAMetric.read, WAFlag.ignore ])
|
||||||
return read
|
return read
|
||||||
}
|
}
|
||||||
async fetchMessagesFromWA (jid: string, count: number, indexMessage?: { id?: string; fromMe?: boolean }, mostRecentFirst: boolean = true) {
|
async fetchMessagesFromWA (jid: string, count: number, indexMessage?: { id?: string; fromMe?: boolean }, mostRecentFirst: boolean = true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user