tomer8007 / whatsapp-web-incognito

A Chrome extension that disables read receipts and presence updates on WhatsApp Web
MIT License
319 stars 75 forks source link

Getting online status / Simulating chat click #11

Closed amanharwara closed 4 years ago

amanharwara commented 4 years ago

I have a couple of questions which if you could answer, would be amazing.

  1. I know of a way to check if the user is online by getting the value of props.chat.presence.isOnline, but the correct value of that can only be gotten once the chat is opened. I want to get the correct value of the presence when all the chats are loaded, without having to open them. Is this possible?

  2. Is there a way to programmatically open a chat? By this, I mean is it possible to simulate clicking one of the chats to open that certain chat? I tried using the element.click() method, but that doesn't do anything.

Thanks, Aman.

amanharwara commented 4 years ago

By the way, I'm sorry if this is off-topic. I think you might be able to help me out, which is why I've asked you.

tomer8007 commented 4 years ago

Yes.

  1. Two ways, if your JID is something like "PHONE_NUMBER@g.us": a. WhatsAppAPI_1.Chat.get(jid).presence.isOnline b. getChatByJID(jid).presence.isOnline
  2. This can be a matter of extracting the module that exports the function openChat and calling it. I'm not sure how to do that at the moment, but I can see that it's getting called when you open a chat. Maybe I'll get back to that later.
amanharwara commented 4 years ago
  1. Two ways, if your JID is something like PHONE_NUMBER@g.us: a. WhatsAppAPI_1.Chat.get(jid).presence.isOnline b. getChatByJID(jid).presence.isOnline

I tried doing this, but it keeps showing false even when it is actually false.

tomer8007 commented 4 years ago

I tried doing this, but it keeps showing false even when it is actually false.

Do you mean that when you get a chat object via getChatByJID(jid) or by any other method, that would not reflect the real online status unless the chat is opened?

I think this could be because you need to subscribe to presence updates somehow.

Did you try typing WADebugMode = true? When you click on a chat, you see:

image

In the worst case, maybe you could try sending this request yourself, with WACrypto.sendNode.

amanharwara commented 4 years ago

Do you mean that when you get a chat object via getChatByJID(jid) or by any other method, that would not reflect the real online status unless the chat is opened?

Yes, that is what I mean.

amanharwara commented 4 years ago

Is there a way to use your API in an Electron app? I'm trying to implement a feature in my electron app where it checks if the chats are online or not and shows a marker if someone is online.

tomer8007 commented 4 years ago

If I were you I would spend time trying to extract the modules I need to open a chat, subscribe to presence updates of users, etc. This is what I've done with the API that sends read receipts. You can see the code that finds some of the webpack modules here.

This should work straight-away in javascript, assuming the javascript in WhatsApp's Electron app (or whatever it is) is similar in its form to the WhatsApp Web version.

tomer8007 commented 4 years ago

In fact, it looks like the sulla project has already extracted the OpenChat API in this way over here.

amanharwara commented 4 years ago

@tomer8007 Thank you very much! I got the chats to open with the OpenChat API. And with the presence thing, I need to find a way to make the chats not stale. It doesn't get the correct presence.isOnline value if presence.stale is true.

tomer8007 commented 4 years ago

Turns out that's easier:

chat.presence.subscribe()

will turn your char.presence.stale to false and reveal the real chat.presence.isOnline.

amanharwara commented 4 years ago

Thank you so much! It works now! I'll close this issue now.