Added Contact Model (#34)

This commit is contained in:
Aliyss Snow
2020-02-03 00:08:36 +01:00
committed by GitHub
parent b597e4a504
commit e2351db722
7 changed files with 134 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ const Util = require('./util/Util');
const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require('./util/Constants');
const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const ClientInfo = require('./structures/ClientInfo');
const Message = require('./structures/Message');
@@ -210,6 +211,29 @@ class Client extends EventEmitter {
return ChatFactory.create(this, chat);
}
/**
* Get all current contact instances
*/
async getContacts() {
let contacts = await this.pupPage.evaluate(() => {
return window.WWebJS.getContacts();
});
return contacts.map(contact => ContactFactory.create(this, contact));
}
/**
* Get contact instance by ID
* @param {string} contactId
*/
async getContactById(contactId) {
let contact = await this.pupPage.evaluate(contactId => {
return window.WWebJS.getContact(contactId);
}, contactId);
return ContactFactory.create(this, contact);
}
/**
* Accepts an invite by code
* @param {string} inviteCode