From 8528d9b0b6a7b9267d218a119e3040e5d501a9ea Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Sat, 11 Apr 2020 19:03:47 -0400 Subject: [PATCH] feat: get profile pic url by user ID This moves the function from Contact to Client to enable getting profile picture without requiring a conversation before. The old function is still available on Contact for convenience and backwards-compatibility. --- src/Client.js | 12 ++++++++++++ src/structures/Contact.js | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Client.js b/src/Client.js index 2bed2c2..2b7aaec 100644 --- a/src/Client.js +++ b/src/Client.js @@ -547,6 +547,18 @@ class Client extends EventEmitter { }, chatId); } + /** + * Returns the contact ID's profile picture URL, if privacy settings allow it + * @returns {Promise} + */ + async getProfilePicUrl(contactId) { + const profilePic = await this.pupPage.evaluate((contactId) => { + return window.Store.Wap.profilePicFind(contactId); + }, contactId); + + return profilePic ? profilePic.eurl : undefined; + } + /** * Force reset of connection state for the client */ diff --git a/src/structures/Contact.js b/src/structures/Contact.js index 60fd3b7..2321ccc 100644 --- a/src/structures/Contact.js +++ b/src/structures/Contact.js @@ -103,11 +103,7 @@ class Contact extends Base { * @returns {Promise} */ async getProfilePicUrl() { - const profilePic = await this.client.pupPage.evaluate((contactId) => { - return window.Store.Wap.profilePicFind(contactId); - }, this.id._serialized); - - return profilePic ? profilePic.eurl : undefined; + return await this.client.getProfilePicUrl(this.id._serialized); } }