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

[Bug]: WhatsApp wrong message count #230

Closed
3 tasks done
victorbnl opened this issue Nov 10, 2022 · 55 comments · Fixed by #240
Closed
3 tasks done

[Bug]: WhatsApp wrong message count #230

victorbnl opened this issue Nov 10, 2022 · 55 comments · Fixed by #240
Labels
bug 🪲 Something isn't working help wanted Extra attention is needed question ❓ Further information is requested

Comments

@victorbnl
Copy link
Contributor

victorbnl commented Nov 10, 2022

Preflight Checklist

Ferdium Version

6.2.1-nightly.39

Recipe Name

whatsapp

Recipe Version

3.4.6

Last Known working version of the recipe

No response

Steps to reproduce

Just create a WhatsApp service and use it I guess (I think it's due to updates to the website and not specific to my setup)

Expected Behavior

The message count shows the correct count which is in my case 0 messages

Actual Behavior

The message count shows 88 messages

Screenshots

image

Additional Information

No response

@victorbnl victorbnl added the bug 🪲 Something isn't working label Nov 10, 2022
@victorbnl
Copy link
Contributor Author

Update : the count isn't stuck at 88 but starts at this number and increments. I now have two messages so it now shows 90

@cino cino added this to Ferdium Nov 11, 2022
@cino cino moved this to New in Ferdium Nov 11, 2022
@cino
Copy link

cino commented Nov 11, 2022

@victorbnl Is this something you would be able to debug? As this would be really hard to debug without experiencing the same issue.

@cino cino moved this from New to Todo in Ferdium Nov 11, 2022
@cino cino added the help wanted Extra attention is needed label Nov 11, 2022
@victorbnl
Copy link
Contributor Author

It is indeed. I tried to understand how the script works and it seems that it:

  1. looks for the first div[aria-label] which is indeed the chat list, no problem here
  2. looks for each span[aria-label], converts its content to an int using Ferdium.safeParseInt and adds it to the counter

The issue could be that not only is the new message count a span[aria-label], the name and last message excerpt are too

image

So for each chat Ferdium.safeParseInt("Chat name") and Ferdium.safeParseInt("Chat last message excerpt") are added to Ferdium's counter

But again this is from my understanding of how the script works. Also maybe it would help to know what Ferdium.safeParseInt("string without number") does

@nathanaelhoun
Copy link
Contributor

nathanaelhoun commented Nov 11, 2022

I can confirm that before, only the message count for each conversation had a aria-label, and it's why we used this selector to find the number of message for each conversation.
I think they added aria-labels to each part now, it''s why

Also maybe it would help to know what Ferdium.safeParseInt("string without number") does

@victorbnl Ferdium.safeParseInt("string without number") returns 0 when the string doesn't start with a number. In my case, some of my conversation are phone numbers, and so Ferdium.safeParseInt("+33 6 79 xx xx xx") returns 33.

Updating the selector in the script to div[role="gridcell"] > span > div > span[aria-label] works for me, and select only the numbers of unread messages in each conversation. I'll open a PR :-)

@cino
Copy link

cino commented Nov 12, 2022

image

Just woke up to this, so looks like it's rolling out slowly, will test the PR.

@MichalPodeszwa
Copy link

MichalPodeszwa commented Nov 12, 2022

Just to shed some light, until about 5 minutes ago I've been using Ferdi. This particular issue was the reason I've looked into Ferdi again and realized it's unmaintained and found this project.
This issue has become present there in the last couple of days, so it might be something related to WhatsApp changes internally?

EDIT. Whoops, seems like you guys have figured that out as well 😂 Sorry

@victorbnl
Copy link
Contributor Author

I have two conversations with phone numbers which start by respectively 33 and 55 which sum is indeed 88, so I can confirm this is the issue!

@AGCaesar
Copy link

I have the same issue. I get a 3 or 4 digit number of unread messages, in reality it is 0. The number changes when I scroll through my contact list.

@ursie
Copy link

ursie commented Nov 12, 2022

Exactly ... I can confirm as soon the message start with a number that number is added to the unread counter of the whatsapp icon. When I archive that specific chat the unread counter disappears again (because it is zero).

Tried to apply the fix as being suggested nathanaelhoun but I couln't get it to work. I run Ferdium on a mac and I edited the file whatsapp.tar.gz in directory /Applications/Ferdium.app/Contents/Resources/app.asar.unpacked/recipes but that didn't solve the problem.

@Alphrag
Copy link
Member

Alphrag commented Nov 12, 2022

Tried to apply the fix as being suggested nathanaelhoun but I couln't get it to work. I run Ferdium on a mac and I edited the file whatsapp.tar.gz in directory /Applications/Ferdium.app/Contents/Resources/app.asar.unpacked/recipes but that didn't solve the problem.

@ursie If you want to apply it without building, you can modify the file in ~/Library/Application Support/Ferdium/recipes/whatsapp/webview.js. Then, simply reload the service and the changes will be applied. Let us know if that patch works for you 🙂

@ursie
Copy link

ursie commented Nov 13, 2022

div[role="gridcell"] > span > div > span[aria-label]

afaik see and test this fix works for me. I have scrolled through my conversations and the unread counter stays on the number as it should be.

@notapelican
Copy link

I can confirm that before, only the message count for each conversation had a aria-label, and it's why we used this selector to find the number of message for each conversation. I think they added aria-labels to each part now, it''s why

Also maybe it would help to know what Ferdium.safeParseInt("string without number") does

@victorbnl Ferdium.safeParseInt("string without number") returns 0 when the string doesn't start with a number. In my case, some of my conversation are phone numbers, and so Ferdium.safeParseInt("+33 6 79 xx xx xx") returns 33.

Updating the selector in the script to div[role="gridcell"] > span > div > span[aria-label] works for me, and select only the numbers of unread messages in each conversation. I'll open a PR :-)

Thank you! That worked for getting rid of the fake numbers.
But now I'm not getting any whatsapp unread message numbers at all... Any ideas?

@cedricroijakkers
Copy link

I found out the issue also happens if:

  • You get a message from someone (either in a group or directly) that starts with a number
  • You get a message from someone that is not in your contact list (i.e. their name will start with a number)
  • Someone not in your contact list does something in a group (i.e. their name will start with a number)

Archiving conversations with these cases solves the issue for now.

@pacstah
Copy link

pacstah commented Nov 14, 2022

I found out the issue also happens if:

* You get a message from someone (either in a group or directly) that starts with a number

* You get a message from someone that is not in your contact list (i.e. their name will start with a number)

* Someone not in your contact list does something in a group (i.e. their name will start with a number)

Archiving conversations with these cases solves the issue for now.

If you don't want to archive your chats, you can also add the people to your contact list from whom you received that last message.

@akatarmo
Copy link

I'm the author of the fix. The problem is Ferdium is looking all topics subjects and messages. So if someone send to you 1234 in the conversation, you will have +1234 in the red bubble ;p

You can try an other fix (always the line ferdium/ferdium-app#1008) +1 const unreadSpans = parentChatElem.querySelectorAll('span.ovhn1urg');

It's a better fix, because need less CPU to count the new messages

I'm using this fix in webview.js

const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]:not(span[aria-label=""])');

@SpecialAro
Copy link
Member

The badges count continues wrong

image

This is working as expected. Unread messages from muted chats don't count for the count.

@leandrogehlen
Copy link

i'm sorry, i did not pay attention

@calvinwyoung
Copy link
Contributor

@leandrogehlen How did you apply the latest version of the recipe? Did you have to clone it locally?

@Alphrag
Copy link
Member

Alphrag commented Nov 21, 2022

This is working as expected. Unread messages from muted chats don't count for the count.

Hmm, it should show a blue dot as indirect message anyway...

How did you apply the latest version of the recipe? Did you have to clone it locally?

@calvinwyoung It has been shipped on the last nightlies but if you are using the stable release and want that fix in before the next update for you, you can modify the webview.js file of that recipe by hand (right-click on whatsapp then Edit -> Open user.js to get to the appropriate location if you don't know where that is).

@Gaibhne
Copy link

Gaibhne commented Nov 22, 2022

I have tried const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]:not(span[aria-label=""])');, const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]:not(span[aria-label=""])'); and const unreadSpans = parentChatElem.querySelectorAll('span.ovhn1urg'); and none have reliably fixed the problem. Either I still get unread counts when I have no unreads, or I get no unread count even though I have unreads. Happy to help debug if someone tells me what to do.

@Alphrag
Copy link
Member

Alphrag commented Nov 22, 2022

@Gaibhne What version of the service are you using (you can see it at the bottom in the edit window)? If it is not 3.4.7, you can either wait to get it, or manually put the fix from #240.

@akatarmo
Copy link

akatarmo commented Nov 22, 2022

@Gaibhne What version of the service are you using (you can see it at the bottom in the edit window)? If it is not 3.4.7, you can either wait to get it, or manually put the fix from #240.

I have tried to update manually to v3.4.7 but it is quite confusing to determine how many and which are the exact files that I have to edit/replace. I have done it following the link,

#240

but it doesn't work, it doesn't mark the number of unread messages, so I have to go back to the second manual fix that worked for me, posted by @ysoudy above

@Glennmen
Copy link

How do we get this fix? (Without needing to manually change values)
An update recipes button would be useful 😅

@Alphrag
Copy link
Member

Alphrag commented Nov 22, 2022

How do we get this fix? (Without needing to manually change values) An update recipes button would be useful sweat_smile

At the moment you can't just update the recipe directly at the moment (cf my previous answer about that). So either you wait for the release or you get your hands just a bit dirty by updating the webview.js file yourself.

@akatarmo The best way is to take the updated webview.js file in the repo and to replace your old one by this one if you want to manually get exactly the change introduced. If that doesn't solve the problem, then that fix is unfortunately not enough and we need to dig a bit deeper (as the fix you mention will definitely break again on a next update from whatsapp).

@akatarmo
Copy link

Hi, @Alphrag

Thanks, everything is fine now, with the file you have put in the link.

https://github.com/ferdium/ferdium-recipes/blob/main/recipes/whatsapp/webview.js

I don't know where the hell I copied-pasted a webview.js with 98 lines (when it should have 80) that I understood was the new one.

@Gaibhne
Copy link

Gaibhne commented Nov 22, 2022

Thank you, the fix from the PR seems to be working so far. One question: now that I have manually updated my recipe, will it still auto-update on the next release ? If not, what must I do to go back to stock once the release version has the PR ?

@Alphrag
Copy link
Member

Alphrag commented Nov 22, 2022

now that I have manually updated my recipe, will it still auto-update on the next release ?

When you update the app, it looks at the version of all the services you are using and compare them with the version packaged within the app. If the packaged version is higher, it will replace the files of the local recipe with the one from the app. So, as long as you do not change the version number in the package.json file of the recipe, updates will propagate normally when new versions are happening.

@akatarmo
Copy link

akatarmo commented Nov 25, 2022

Hi guys.

WhatsApp has stopped working today for me on Ferdium. Although I try to reload, I can't connect, it keeps waiting for the dot code for login. I have removed the service and added it again, the problem persists. However, if I set WhatsApp as Custom Service, everything is fine, can login with de dot code, but I don't have the unread message notification in the Windows status bar (neither in the Ferdium WhatsApp icon service, at left).

Does anyone else have this problem?

@nathanaelhoun
Copy link
Contributor

Hi @akatarmo,
I think your issue is the one fixed in #247, but I can't be sure.
Since it's not link to this current issue (wrong message count on Whatsapp), I encourage you to create a new issue for your bug if it persists.

@akatarmo
Copy link

Hello, thanks for answering @nathanaelhoun

This receipe 3.4.8 #247

fixed the logging problem, but the wrong message counter problem came back again. After installing and uninstalling several times, finally with receipe 3.4.7 it works again, I don't know how or why.

@SpecialAro
Copy link
Member

I'm reopening this issue given that I too have the same problem with the message count again with the latest recipe (3.4.8).

@SpecialAro SpecialAro reopened this Nov 26, 2022
@hakanalpp
Copy link

hakanalpp commented Nov 26, 2022

I'm reopening this issue given that I too have the same problem with the message count again with the latest recipe (3.4.8).

Have you also tried updating the webview.js as @akatarmo suggested? (Link is this one https://github.com/ferdium/ferdium-recipes/blob/main/recipes/whatsapp/webview.js)

One I had to replace was in this directory ~/.config/Ferdium/recipes/whatsapp. If you are replacing the one that is under /opt folder, that does not work.

@SpecialAro
Copy link
Member

Hey @hakanalpp thank you for trying to help out!

After talking with @Alphrag and @vraravam I concluded that this was a problem with my local, manly related to some toggle being off which previously wasn't (this is an known issue that users will face in the next stable release most likely).

As a future reference for anyone checking this issue, make sure you have this toggle on!
image

I'm closing this issue back again as the cause of the issue is not related to the WA message count.

@peteracworth
Copy link

the fix has worked for me on windows 10 and 11 (change line 19 in webview.js to const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]:not(span[aria-label=""])'); )

Version: 6.2.0
Server: Ferdium Server
Electron: 20.2.0
Chrome: 104.0.5112.124
Node.js: 16.15.0
Platform: Windows 11
Arch: x64
Build date: Thu Sep 22 2022 10:13:21 GMT-0700 (Pacific Daylight Time)
Git SHA: 84613b5
Git branch: release

@phiexz
Copy link

phiexz commented Dec 8, 2022

seems like new recipe also counting Archived chat.
is there a way to skip counting archived chat?

@sellout
Copy link

sellout commented May 19, 2023

I am still dealing with this issue (I see a badge with “927”). I think I have done all the right things:

  • Ferdium 6.2.7, on macOS Ventura 13.3.1, installed via Homebrew;
  • “Show unread message badges” is enabled; and
  • I have no archived chats (I did, but they had no unreads, then I deleted them all, toggled “Show unread message badges”, restarted Ferdium, etc.).

The problem appears to be that the WhatsApp service settings says “Recipe version 3.4.5”, when at least 3.4.7 is required for this to be fixed.

Considering I’m on the current version of Ferdium, why do I not have the latest recipies? I actually uninstalled/re-installed Ferdium to see if that would do it, but no luck.

The console has a lot of messages about Ferdium. I could help diagnose if I knew what to look for. In particular, these four lines repeat every 5 seconds:

error	14:48:24.501276-0600	kernel	System Policy: Ferdium(36800) deny(1) file-read-data /Users/greg/Library/DoNotDisturb/DB/ModeConfigurations.json
default	14:48:24.501615-0600	Ferdium	Failed to open \M-q\M-lD\M-q\^A, error Error Domain=NSCocoaErrorDomain Code=257 "The file “ModeConfigurations.json” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Users/greg/Library/DoNotDisturb/DB/ModeConfigurations.json, NSUnderlyingError=0x149197c60 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
error	14:48:24.502166-0600	kernel	System Policy: Ferdium(36800) deny(1) file-read-data /Users/greg/Library/DoNotDisturb/DB/Assertions.json
default	14:48:24.502593-0600	Ferdium	Failed to open \M-q\M-lD\M-q\^A, error Error Domain=NSCocoaErrorDomain Code=257 "The file “Assertions.json” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Users/greg/Library/DoNotDisturb/DB/Assertions.json, NSUnderlyingError=0x14c89ff90 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Copying the latest webview.js contents into my local one “fixed” it, but the problem I’m concerned about is not having current recipes in general. How do I know if they’re out of date (without having to look up a bug)? Is it possible to force a fetch of the new versions and get an error if updating them fails?

@vraravam
Copy link
Contributor

Recipes are bundled within the Ferdium installer and so are auto-upgraded only with each new nightly/beta/stable release of the app. There's a discussion thread about decoupling this behavior so that the recipes can be independently released and upgraded without having to upgrade the app itself. As with other ideas, there aren't any contributors who are working on this atm

@Yelizaroff
Copy link

Hi, @Alphrag

Thanks, everything is fine now, with the file you have put in the link.

https://github.com/ferdium/ferdium-recipes/blob/main/recipes/whatsapp/webview.js

I don't know where the hell I copied-pasted a webview.js with 98 lines (when it should have 80) that I understood was the new one.

Thank you! I found a solution on my MacBookPro M1 in Sonoma.

Go to folder:
~\Library\Application Support\Franz\recipes\whatsapp

Rename file webview.js as webview._old.js

Download & replace file with this file: webview.js

Restart Franz.

Good Luck for all!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working help wanted Extra attention is needed question ❓ Further information is requested
Projects
Status: Done