Update WhatsAppWeb.Session.js

This commit is contained in:
Adhiraj
2020-06-06 13:05:34 +05:30
parent 5bb9bbd1ef
commit c2661186f1

View File

@@ -107,12 +107,14 @@ module.exports = {
const chatUpdate = (json) => { const chatUpdate = (json) => {
const isLast = json[1].last const isLast = json[1].last
json = json[2] json = json[2]
for (var k = json.length-1;k >= 0;k--) { if (json) {
const message = json[k][2] for (var k = json.length-1;k >= 0;k--) {
const jid = message.key.remoteJid.replace ("@s.whatsapp.net", "@c.us") const message = json[k][2]
if (!message.key.fromMe && unreadMap[jid] > 0) { // only forward if the message is from the sender const jid = message.key.remoteJid.replace ("@s.whatsapp.net", "@c.us")
unreadMessages.push (message) if (!message.key.fromMe && unreadMap[jid] > 0) { // only forward if the message is from the sender
unreadMap[jid] -= 1 // reduce unreadMessages.push (message)
unreadMap[jid] -= 1 // reduce
}
} }
} }
if (isLast) { if (isLast) {
@@ -131,7 +133,7 @@ module.exports = {
const waitForChats = this.registerCallbackOneTime (["response", "type:chat"]).then (json => { const waitForChats = this.registerCallbackOneTime (["response", "type:chat"]).then (json => {
chats = json[2] // chats data (log json to see what it looks like) 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 chats.forEach (chat => unreadMap [chat[1].jid] = chat[1].count) // store the number of unread messages for each sender
if (chats.length > 0) { if (chats && chats.length > 0) {
return waitForConvos () return waitForConvos ()
} }
}) })