Possible connect timeout bug fix + added ability to relay own messages

This commit is contained in:
Adhiraj
2020-06-06 13:00:38 +05:30
parent f24f83331c
commit 5bb9bbd1ef
5 changed files with 19 additions and 13 deletions

View File

@@ -103,8 +103,7 @@ module.exports = {
}) // validate the connection
.then (() => {
this.log ("waiting for chats & contacts") // wait for the message with chats
const waitForConvos = new Promise ((resolve, _) => {
const waitForConvos = () => new Promise ((resolve, _) => {
const chatUpdate = (json) => {
const isLast = json[1].last
json = json[2]
@@ -132,11 +131,14 @@ module.exports = {
const waitForChats = this.registerCallbackOneTime (["response", "type:chat"]).then (json => {
chats = json[2] // chats data (log json to see what it looks like)
chats.forEach (chat => unreadMap [chat[1].jid] = chat[1].count) // store the number of unread messages for each sender
if (chats.length > 0) {
return waitForConvos ()
}
})
const waitForContacts = this.registerCallbackOneTime (["response", "type:contacts"])
.then (json => contacts = json[2])
// wait for the chats & contacts to load
return Promise.all ([waitForConvos, waitForChats, waitForContacts])
return Promise.all ([waitForChats, waitForContacts])
})
.then (() => {
// now we're successfully connected