Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The isNewMsg property only appears in the latest unread message. #1333

Closed
daviladanielc opened this issue Aug 30, 2023 · 2 comments
Closed
Labels
bug Something isn't working needs triage

Comments

@daviladanielc
Copy link

daviladanielc commented Aug 30, 2023

Description

I have implemented the following function:

window.WAPI.list = async function () {
  const options = {
    onlyWithUnreadMessage: true
  };

  const chats = await WPP.chat.list(options);
  let messagesResult = [];

  if (chats) {
    try {
      for (var i = 0; i < chats.length; i++) {
        if (chats[i].unreadCount > 0) { // Verifique se msgs existe
          let msgs = await WPP.chat.getMessages(chats[i].__x_id._serialized, {count: -1, onlyUnread: true});
          for (var j = 0; j < msgs.length; j++) {   
            console.log("msg:", JSON.stringify(msgs[j]));         
            if (msgs[j].__x_isNewMsg === true) {                    
              messagesResult.push(msgs[j]);
            }
          }
        }
      }
      console.log(JSON.stringify(messagesResult));
      //SetConsoleMessage("getList", JSON.stringify(messagesResult));
    } catch (e) {
      console.log('Erro:'.concat(e));
    }
  } else {
    console.log('ERRO');
  }
};

Previously, in the version of wa-js v2.24.7 with WhatsApp 2.2333.11, if I sent the messages:
1
2
3

using my implementation:

if (msgs[j].__x_type === 'chat' && msgs[j].__x_isNewMsg === true) {                    
    messagesResult.push(msgs[j]);
}

All three messages were added within the messagesResult.push(msgs[j]);.

However, in the latest versions of wa-js (v2.25.0) and WhatsApp Web (2.2335.9), only the message "3" retains the isNewMsg property, and the messages "1" and "2" do not have this property anymore.

But in my test case, messages 1 and 2 should have isNewMsg = true because they were sent simultaneously along with message 3.

Environment

  • WhatsApp version: 2.2336.8
  • WA-JS version(s): v2.25.0
  • Browser: Chrome 110.0.5481.179 / Chromium 110.0.31.0
  • OS: Windows 10
  • MultiDevice (BETA): yes

Steps to Reproduce

Log Output

@daviladanielc daviladanielc added bug Something isn't working needs triage labels Aug 30, 2023
@edgardmessias
Copy link
Contributor

@daviladanielc , please, don't use __x_ attributes, they are non standard

@marcelo386
Copy link
Contributor

window.WAPI.list = async function () {
const options = {
onlyWithUnreadMessage: true
};

const chats = await WPP.chat.list(options);
let messagesResult = [];

if (chats) {
try {
for (var i = 0; i < chats.length; i++) {
if (chats[i].unreadCount > 0) { // Verifique se msgs existe
let msgs = await WPP.chat.getMessages(chats[i].id._serialized, {count: -1, onlyUnread: true});
for (var j = 0; j < msgs.length; j++) {

        if (msgs[j].isNewMsg === true) {                    
          messagesResult.push(msgs[j]);
        }
      }
    }
  }
  //console.log(JSON.stringify(messagesResult));
  SetConsoleMessage("getList", JSON.stringify(messagesResult));
} catch (e) {
  console.log('Erro:'.concat(e));
}

} else {
console.log('ERRO');
}
};

modified the attribute _x even so it is not returning all messages pending reading, it only lists the last message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants