mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 20:49:14 +00:00
feat: block/unblock contacts (#397)
This commit is contained in:
7
index.d.ts
vendored
7
index.d.ts
vendored
@@ -601,6 +601,8 @@ declare namespace WAWebJS {
|
|||||||
isUser: boolean,
|
isUser: boolean,
|
||||||
/** Indicates if the number is registered on WhatsApp */
|
/** Indicates if the number is registered on WhatsApp */
|
||||||
isWAContact: boolean,
|
isWAContact: boolean,
|
||||||
|
/** Indicates if you have blocked this contact */
|
||||||
|
isBlocked: boolean,
|
||||||
/** @todo verify labels type. didn't have any documentation */
|
/** @todo verify labels type. didn't have any documentation */
|
||||||
labels?: string[],
|
labels?: string[],
|
||||||
/** The contact's name, as saved by the current user */
|
/** The contact's name, as saved by the current user */
|
||||||
@@ -627,6 +629,11 @@ declare namespace WAWebJS {
|
|||||||
* Will return null when getting chat for currently logged in user.
|
* Will return null when getting chat for currently logged in user.
|
||||||
*/
|
*/
|
||||||
getChat: () => Promise<Chat>,
|
getChat: () => Promise<Chat>,
|
||||||
|
|
||||||
|
/** Blocks this contact from WhatsApp */
|
||||||
|
block: () => Promise<boolean>,
|
||||||
|
/** Unlocks this contact from WhatsApp */
|
||||||
|
unblock: () => Promise<boolean>,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContactId {
|
export interface ContactId {
|
||||||
|
|||||||
@@ -95,6 +95,12 @@ class Contact extends Base {
|
|||||||
*/
|
*/
|
||||||
this.isMyContact = data.isMyContact;
|
this.isMyContact = data.isMyContact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if you have blocked this contact
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.isBlocked = data.isBlocked;
|
||||||
|
|
||||||
return super._patch(data);
|
return super._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +123,36 @@ class Contact extends Base {
|
|||||||
return await this.client.getChatById(this.id._serialized);
|
return await this.client.getChatById(this.id._serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks this contact from WhatsApp
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
async block() {
|
||||||
|
if(this.isGroup) return false;
|
||||||
|
|
||||||
|
await this.client.pupPage.evaluate(async (contactId) => {
|
||||||
|
const contact = window.Store.Contact.get(contactId);
|
||||||
|
await window.Store.BlockContact.blockContact(contact);
|
||||||
|
}, this.id._serialized);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unblocks this contact from WhatsApp
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
async unblock() {
|
||||||
|
if(this.isGroup) return false;
|
||||||
|
|
||||||
|
await this.client.pupPage.evaluate(async (contactId) => {
|
||||||
|
const contact = window.Store.Contact.get(contactId);
|
||||||
|
await window.Store.BlockContact.unblockContact(contact);
|
||||||
|
}, this.id._serialized);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Contact;
|
module.exports = Contact;
|
||||||
@@ -27,6 +27,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
||||||
window.Store.Validators = window.mR.findModule('findLinks')[0];
|
window.Store.Validators = window.mR.findModule('findLinks')[0];
|
||||||
window.Store.WidFactory = window.mR.findModule('createWid')[0];
|
window.Store.WidFactory = window.mR.findModule('createWid')[0];
|
||||||
|
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.LoadUtils = () => {
|
exports.LoadUtils = () => {
|
||||||
@@ -246,6 +247,7 @@ exports.LoadUtils = () => {
|
|||||||
res.isGroup = contact.isGroup;
|
res.isGroup = contact.isGroup;
|
||||||
res.isWAContact = contact.isWAContact;
|
res.isWAContact = contact.isWAContact;
|
||||||
res.isMyContact = contact.isMyContact;
|
res.isMyContact = contact.isMyContact;
|
||||||
|
res.isBlocked = contact.isContactBlocked;
|
||||||
res.userid = contact.userid;
|
res.userid = contact.userid;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Reference in New Issue
Block a user