feat: Get corresponding Chat from Contact object and vice versa

close #269
This commit is contained in:
Pedro Lopez
2020-08-17 23:31:19 -04:00
parent 34aa136bf9
commit 7180beda2e
3 changed files with 26 additions and 0 deletions

7
index.d.ts vendored
View File

@@ -610,6 +610,11 @@ declare namespace WAWebJS {
/** Returns the contact's profile picture URL, if privacy settings allow it */
getProfilePicUrl: () => Promise<string>,
/** Returns the Chat that corresponds to this Contact.
* Will return null when getting chat for currently logged in user.
*/
getChat: () => Promise<Chat>,
}
export interface ContactId {
@@ -688,6 +693,8 @@ declare namespace WAWebJS {
unarchive: () => Promise<void>,
/** Unmutes this chat */
unmute: () => Promise<void>,
/** Returns the Contact that corresponds to this Chat. */
getContact: () => Promise<Contact>,
}
export interface MessageSearchOptions {

View File

@@ -186,6 +186,14 @@ class Chat extends Base {
return true;
}, this.id._serialized);
}
/**
* Returns the Contact that corresponds to this Chat.
* @returns {Promise<Contact>}
*/
async getContact() {
return await this.client.getContactById(this.id._serialized);
}
}
module.exports = Chat;

View File

@@ -105,6 +105,17 @@ class Contact extends Base {
async getProfilePicUrl() {
return await this.client.getProfilePicUrl(this.id._serialized);
}
/**
* Returns the Chat that corresponds to this Contact.
* Will return null when getting chat for currently logged in user.
* @returns {Promise<Chat>}
*/
async getChat() {
if(this.isMe) return null;
return await this.client.getChatById(this.id._serialized);
}
}