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

Fix Whatsapp recipe unread counts for muted conversations #408

Merged

Conversation

gmurdocca
Copy link
Contributor

…ions.

Pre-flight Checklist

Please ensure you've completed all of the following.

Description of Change

This is a bugfix for issue #1303. Unread counts/badges were erroneously incrementing for Whatsapp conversations that were marked as muted. When mute option "Always" is chosen in Whatsapp Web, the value of chat.muteExpiration in webview.js is set to -1, however the conditional that governs incrementing of unread counts expected a positive non-zero value in this variable to indicate a muted conversation. Chaging the comparison from > 0 to != 0 solved the issue.

@SpecialAro SpecialAro requested a review from a team August 25, 2023 15:02
@victorbnl
Copy link
Contributor

Did you test it? I didn’t but I’m not sure it would work.

If a chat is unmuted, then chat.muteExpiration will be set to undefined. With the previous code, it did the comparison undefined > 0, which was false. So unmuted chats were indeed considered unmuted. Now, it will do undefined != 0, which will be true. This will make unmuted chats be considered muted.

Note: I’m not sure all unmuted chats’ muteExpiration attributes are set to undefined, but as far as I remember at least some of them are.

@gmurdocca
Copy link
Contributor Author

gmurdocca commented Aug 25, 2023

Thanks for the insight @victorbnl. The patch is tested working on Version: 6.5.0-nightly.2 (rpm release deployed to Fedora Linux 38). Tests were simple however, observing the unread count change as expected when conversations were muted and unmuted, and correctly aggregating unread counts in other unmuted conversations.

If Whatsapp Web behavior is intermittent (where only some chats yield a value of undefined), then perhaps the following update to the conditional would be an improvement:

if (chat.muteExpiration == -1 || chat.muteExpiration > 0 || chat.isAutoMuted) {

I tested the above change and observed correct expected behavior with the same described rudimentary test. I did not see a value of undefined for chat.muteExpiration in my console logs however, but the above conditional should work if it is set to that intermittently.

I should add that the OP of the issue also validated the patch to be working for them in the issue comments.

@victorbnl
Copy link
Contributor

victorbnl commented Aug 25, 2023

Well, I just checked again on WhatsApp and it seems that all my chats do have muteExpiration and isAutoMuted attributes set to 0 and false, respectively. Thus maybe it would require some further testing to make sure these attributes are never undefined. I just remember having issues with it (perhaps on an old version), but maybe I don’t remember well, I should look for the issue.

Though if we were to assume I am correct, that fix looks good to me.

Edit: If everyone reports the presence of a muteExpiration attribute set to 0, I guess we can assume it will be there.

Edit 2: It seems like it’s chat.archive that is not present on unmuted chat, chat.muteExpiration seems always present and set to 0.

@gmurdocca
Copy link
Contributor Author

Let me know if you prefer the updated conditional which covers the case that an errant undefined value appears for muteExpiration and I will update the PR.

@victorbnl
Copy link
Contributor

For me you can let it as it is. Testing seems to show the attributes are present. Let’s wait for feedback from the developers.

@SpecialAro
Copy link
Member

Hi guys! This is looking good :D Just tested and it works fine. I'm approving and merging this PR. Thank you @gmurdocca for your contribution

@SpecialAro SpecialAro merged commit e63fed2 into ferdium:main Aug 26, 2023
2 checks passed
@SpecialAro
Copy link
Member

@all-contributors - please add @gmurdocca for code

@allcontributors
Copy link
Contributor

@SpecialAro

I've put up a pull request to add @gmurdocca! 🎉

@gmurdocca gmurdocca deleted the bugfix-issue_1303-fix-whatsapp-unread-count branch August 26, 2023 23:33
@gmurdocca gmurdocca restored the bugfix-issue_1303-fix-whatsapp-unread-count branch August 26, 2023 23:40
@victorbnl victorbnl mentioned this pull request Aug 29, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants