Android chat read fix + debounceTimeout bug fix

This commit is contained in:
Adhiraj Singh
2020-11-03 13:24:56 +05:30
parent e0fd554aa0
commit 155df2bc4f
5 changed files with 33 additions and 25 deletions

View File

@@ -43,7 +43,7 @@ export class WAConnection extends EventEmitter {
state: WAConnectionState = 'close'
connectOptions: WAConnectOptions = {
regenerateQRIntervalMs: 30_000,
maxIdleTimeMs: 15_000,
maxIdleTimeMs: 40_000,
waitOnlyForLastMessage: false,
waitForChats: true,
maxRetries: 10,
@@ -219,6 +219,10 @@ export class WAConnection extends EventEmitter {
tag = tag || this.generateMessageTag (longTag)
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)
else tag = await this.sendJSON(json, tag)
@@ -238,7 +242,7 @@ export class WAConnection extends EventEmitter {
{query: json, message, status: response.status}
)
}
if (startDebouncedTimeout) this.stopDebouncedTimeout ()
if (startDebouncedTimeout) this.startDebouncedTimeout ()
return response
}
/** interval is started when a query takes too long to respond */

View File

@@ -44,10 +44,10 @@ export class WAConnection extends Base {
jid = whatsappID (jid)
const chat = this.assertChatGet (jid)
if (type === 'unread') await this.sendReadReceipt (jid, null, -2)
else if (chat.count !== 0) {
const {messages} = await this.loadMessages (jid, 1)
await this.sendReadReceipt (jid, messages[0].key, Math.abs(chat.count))
const message = (await this.loadMessages(jid, 1)).messages[0]
const count = type === 'unread' ? -2 : Math.abs(chat.count)
if (type === 'unread' || chat.count !== 0) {
await this.sendReadReceipt (jid, message.key, count)
}
chat.count = type === 'unread' ? -1 : 0
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 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 = {
jid: jid,
jid,
count: count.toString(),
index: messageKey?.id,
participant: messageKey?.participant || undefined,
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
}
async fetchMessagesFromWA (jid: string, count: number, indexMessage?: { id?: string; fromMe?: boolean }, mostRecentFirst: boolean = true) {