fix: use WA's own LID resolution for block/unblock#201671
Open
Adi1231234 wants to merge 1 commit intowwebjs:mainfrom
Open
fix: use WA's own LID resolution for block/unblock#201671Adi1231234 wants to merge 1 commit intowwebjs:mainfrom
Adi1231234 wants to merge 1 commit intowwebjs:mainfrom
Conversation
block() was passing a Chat object to blockContact() which expects a contact. unblock() was using synchronous Contact.get() which returns undefined if the contact isn't cached. with blocklist migration enabled, blocking a PN contact without a chat fails because the internal S() function needs a LID or an existing chat to resolve the accountLid. The old getChat() approach worked around this by creating a chat via findOrCreateLatestChat, but that's a side effect and passes the wrong type. use WAWebBlockContactUtils.getContactToBlockOnlyUseIfNoAssociatedChat() instead, which is WA's own utility for this exact case. It resolves the contact's LID via getCurrentLidContact() without needing to create a chat.
Adi1231234
added a commit
to Adi1231234/whatsapp-web.js
that referenced
this pull request
Mar 18, 2026
moved to a dedicated PR (wwebjs#201671) with a proper fix using wawebblockcontactutils.getContactToBlockOnlyUseIfNoAssociatedChat() for correct LID resolution.
Adi1231234
added a commit
to Adi1231234/whatsapp-web.js
that referenced
this pull request
Mar 18, 2026
moved to a dedicated PR (wwebjs#201671) with a proper fix using wawebblockcontactutils.getContactToBlockOnlyUseIfNoAssociatedChat() for correct LID resolution.
BenyFilho
approved these changes
Mar 18, 2026
Contributor
|
This resolved contact.unblock() for me, which hadn't been working for about 15 days. However, the contact still marks isBlocked: false even when the contact is blocked. It was tested on 4 different numbers running the code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
block() and unblock() have two issues:
blockContact(), which expects a Contact model. It works by accident because both have.id, but it's the wrong type. ThegetChat()call also creates an unnecessary chat as a side effect viafindOrCreateLatestChat.Contact.get()which returnsundefinedwhen the contact isn't in the local cache yet.With blocklist migration enabled (
isBlocklistMigrated() === true),blockContact()internally callsS()which needs either a LID or an existing chat withaccountLidto resolve the target. The oldgetChat()workaround created a chat to satisfy this, but the proper way is to resolve the contact's LID directly.This PR uses
WAWebBlockContactUtils.getContactToBlockOnlyUseIfNoAssociatedChat(), which is WA's own utility for this exact scenario. It callsgetCurrentLidContact()to convert PN contacts to their LID equivalent without creating unnecessary chats.Tested in WhatsApp Web DevTools: block + unblock cycle works correctly for contacts with and without existing chats.
Test plan