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>
This commit is contained in:
parent
51f5920153
commit
016a56bb56
2 changed files with 33 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue