From 50f8922cecb976bc3c8836389c8509cc6ede905a Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Mon, 20 Jul 2020 13:07:50 +0530 Subject: [PATCH] Fixes --- src/WAConnection/Connect.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/WAConnection/Connect.ts b/src/WAConnection/Connect.ts index 08783fe..65f6bf3 100644 --- a/src/WAConnection/Connect.ts +++ b/src/WAConnection/Connect.ts @@ -112,7 +112,9 @@ export default class WAConnectionConnector extends WAConnectionValidator { this.registerCallback(['action', 'add:unread'], chatUpdate) }) const waitForChats = async () => { - const json = await this.registerCallbackOneTime(['response', 'type:chat']) + let json = await this.registerCallbackOneTime(['response', 'type:chat']) + if (json[1].duplicate) json = await this.registerCallbackOneTime (['response', 'type:chat']) + json[2].forEach(chat => { chat[1].count = parseInt(chat[1].count) chat[1].messages = [] @@ -123,7 +125,9 @@ export default class WAConnectionConnector extends WAConnectionValidator { if (chats.length > 0) return waitForConvos() } const waitForContacts = async () => { - const json = await this.registerCallbackOneTime(['response', 'type:contacts']) + let json = await this.registerCallbackOneTime(['response', 'type:contacts']) + if (json[1].duplicate) json = await this.registerCallbackOneTime (['response', 'type:contacts']) + contacts = json[2].map(item => item[1]) receivedContacts = true // if you receive contacts after messages