From e9104b390d9ad19dce1512588758a7f99506eb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BC=BA=20L=E1=B4=87G=CC=B8=E1=B4=87=C9=B4D=20=E0=BC=BB?= <39593002+jtourisNS@users.noreply.github.com> Date: Tue, 29 Mar 2022 00:17:55 -0300 Subject: [PATCH] Fix: Cannot read properties of undefined (reading 'getProfilePicFull') (#1362) * Fix for issue#1356 - Cannot read properties of undefined reading getProfilePicFull * use cross-compatible profilePicFind function Co-authored-by: Joaquin Touris Co-authored-by: Pedro Lopez --- src/Client.js | 16 ++++++---------- src/util/Injected.js | 2 +- tests/client.js | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Client.js b/src/Client.js index 5d5e94f..b8a45a2 100644 --- a/src/Client.js +++ b/src/Client.js @@ -877,19 +877,15 @@ class Client extends EventEmitter { */ async getProfilePicUrl(contactId) { const profilePic = await this.pupPage.evaluate(async contactId => { - let asyncPic; - if (window.Store.Features.features.MD_BACKEND) { + try { const chatWid = window.Store.WidFactory.createWid(contactId); - asyncPic = await window.Store.getProfilePicFull(chatWid).catch(() => { - return undefined; - }); - } else { - asyncPic = await window.Store.Wap.profilePicFind(contactId).catch(() => { - return undefined; - }); + return await window.Store.ProfilePic.profilePicFind(chatWid); + } catch (err) { + if(err.name === 'ServerStatusCodeError') return undefined; + throw err; } - return asyncPic; }, contactId); + return profilePic ? profilePic.eurl : undefined; } diff --git a/src/util/Injected.js b/src/util/Injected.js index 3524e0d..8addf6c 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -40,7 +40,7 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0]; window.Store.Wap = window.mR.findModule('queryLinkPreview')[0].default; window.Store.WidFactory = window.mR.findModule('createWid')[0]; - window.Store.getProfilePicFull = window.mR.findModule('getProfilePicFull')[0].getProfilePicFull; + window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0]; window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0]; window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0]; window.Store.GroupParticipants = window.mR.findModule('sendPromoteParticipants')[0]; diff --git a/tests/client.js b/tests/client.js index a73a24d..37b7805 100644 --- a/tests/client.js +++ b/tests/client.js @@ -279,7 +279,7 @@ describe('Client', function() { 'Wap', 'WidFactory', 'findCommonGroups', - 'getProfilePicFull', + 'ProfilePic', ]; const loadedModules = await client.pupPage.evaluate((expectedModules) => {