From 5b0e0612dee15b46bce01c7ee54ba18161b1b61b Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:12:17 +0300 Subject: [PATCH] fix: make function getContactDeviceCount work (#3284) Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com> --- index.d.ts | 2 +- src/Client.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index fd08c43..eed78b5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -183,7 +183,7 @@ declare namespace WAWebJS { * So for a non-enterprise user with one WaWeb connection it should return "2" * @param {string} contactId */ - getContactDeviceCount(contactId: string): Promise + getContactDeviceCount(userId: string): Promise /** Sync history conversation of the Chat */ syncHistory(chatId: string): Promise diff --git a/src/Client.js b/src/Client.js index d923453..e51810c 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1729,15 +1729,17 @@ class Client extends EventEmitter { * Get user device count by ID * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one * So for a non-enterprise user with one WaWeb connection it should return "2" - * @param {string} contactId - * @returns {number} + * @param {string} userId + * @returns {Promise} */ - async getContactDeviceCount(contactId) { - let devices = await window.Store.DeviceList.getDeviceIds([window.Store.WidFactory.createWid(contactId)]); - if(devices && devices.length && devices[0] != null && typeof devices[0].devices == 'object'){ - return devices[0].devices.length; - } - return 0; + async getContactDeviceCount(userId) { + return await this.pupPage.evaluate(async (userId) => { + const devices = await window.Store.DeviceList.getDeviceIds([window.Store.WidFactory.createWid(userId)]); + if (devices && devices.length && devices[0] != null && typeof devices[0].devices == 'object') { + return devices[0].devices.length; + } + return 0; + }, userId); } /**