From 016a56bb5648fb8f9b91dadabca4d4b870ef4f6b Mon Sep 17 00:00:00 2001 From: Adi1231234 Date: Tue, 24 Mar 2026 15:42:28 +0200 Subject: [PATCH] fix: use WA's own LID resolution for block/unblock (#201671) * fix: use WA's own LID resolution for block/unblock 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. * fix: check alternate WID for blocked status in getContactModel iscontactblocked on PN contacts returns false because the Blocklist only contains LID entries. Use getAlternateUserWid() to resolve the PN/LID mapping and check the Blocklist directly, matching WA web's own $Contact$p_3 fallback logic. --------- Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> --- src/structures/Contact.js | 24 +++++++++++++++++++----- src/util/Injected/Utils.js | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/structures/Contact.js b/src/structures/Contact.js index 38f88da..4ee5194 100644 --- a/src/structures/Contact.js +++ b/src/structures/Contact.js @@ -155,10 +155,18 @@ class Contact extends Base { if (this.isGroup) return false; await this.client.pupPage.evaluate(async (contactId) => { - const chat = await window.WWebJS.getChat(contactId); + const contact = await window + .require('WAWebCollections') + .Contact.find(contactId); + const resolved = window + .require('WAWebBlockContactUtils') + .getContactToBlockOnlyUseIfNoAssociatedChat( + contact, + 'ChatListBlock', + ); await window .require('WAWebBlockContactAction') - .blockContact({ contact: chat }); + .blockContact({ contact: resolved }); }, this.id._serialized); this.isBlocked = true; @@ -173,12 +181,18 @@ class Contact extends Base { if (this.isGroup) return false; await this.client.pupPage.evaluate(async (contactId) => { - const contact = window + const contact = await window .require('WAWebCollections') - .Contact.get(contactId); + .Contact.find(contactId); + const resolved = window + .require('WAWebBlockContactUtils') + .getContactToBlockOnlyUseIfNoAssociatedChat( + contact, + 'ChatListBlock', + ); await window .require('WAWebBlockContactAction') - .unblockContact(contact); + .unblockContact(resolved); }, this.id._serialized); this.isBlocked = false; diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index ab9bb04..547f917 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -1023,6 +1023,20 @@ exports.LoadUtils = () => { } res.isBlocked = contact.isContactBlocked; + if (!res.isBlocked) { + const alt = window + .require('WAWebApiContact') + .getAlternateUserWid( + window + .require('WAWebWidFactory') + .asUserWidOrThrow(contact.id), + ); + if (alt) { + res.isBlocked = !!window + .require('WAWebCollections') + .Blocklist.get(alt); + } + } const ContactMethods = window.require('WAWebContactGetters'); res.isMe = ContactMethods.getIsMe(contact);