From 7180beda2ee7d85a6a3073629a0182b0776d8761 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Mon, 17 Aug 2020 23:31:19 -0400 Subject: [PATCH] feat: Get corresponding Chat from Contact object and vice versa close #269 --- index.d.ts | 7 +++++++ src/structures/Chat.js | 8 ++++++++ src/structures/Contact.js | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/index.d.ts b/index.d.ts index 5d2552c..b9e5a1c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -610,6 +610,11 @@ declare namespace WAWebJS { /** Returns the contact's profile picture URL, if privacy settings allow it */ getProfilePicUrl: () => Promise, + + /** Returns the Chat that corresponds to this Contact. + * Will return null when getting chat for currently logged in user. + */ + getChat: () => Promise, } export interface ContactId { @@ -688,6 +693,8 @@ declare namespace WAWebJS { unarchive: () => Promise, /** Unmutes this chat */ unmute: () => Promise, + /** Returns the Contact that corresponds to this Chat. */ + getContact: () => Promise, } export interface MessageSearchOptions { diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 08b7999..d3174c7 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -186,6 +186,14 @@ class Chat extends Base { return true; }, this.id._serialized); } + + /** + * Returns the Contact that corresponds to this Chat. + * @returns {Promise} + */ + async getContact() { + return await this.client.getContactById(this.id._serialized); + } } module.exports = Chat; diff --git a/src/structures/Contact.js b/src/structures/Contact.js index 2321ccc..ec577cd 100644 --- a/src/structures/Contact.js +++ b/src/structures/Contact.js @@ -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} + */ + async getChat() { + if(this.isMe) return null; + + return await this.client.getChatById(this.id._serialized); + } }