From 3be7566483afddb781242a33d78b5a86334d46f8 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:27:24 +0300 Subject: [PATCH] fix: CallCollection (#2385) * fix: changed module for CallCollection * code refactored * compareWwebVersions fixed and moved to window.compareWwebVersions * code refactoring --- src/Client.js | 44 ++++++++++++++++++++++++++++++++++++++++++ src/util/Injected.js | 46 ++------------------------------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/Client.js b/src/Client.js index 51a6f25..490b70d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -275,6 +275,50 @@ class Client extends EventEmitter { } + await page.evaluate(() => { + /** + * Helper function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version. + * @param {string} lOperand The left operand for the WWeb version string to compare with + * @param {string} operator The comparison operator + * @param {string} rOperand The right operand for the WWeb version string to compare with + * @returns {boolean} Boolean value that indicates the result of the comparison + */ + window.compareWwebVersions = (lOperand, operator, rOperand) => { + if (!['>', '>=', '<', '<=', '='].includes(operator)) { + throw class _ extends Error { + constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; } + }('Invalid comparison operator is provided'); + + } + if (typeof lOperand !== 'string' || typeof rOperand !== 'string') { + throw class _ extends Error { + constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; } + }('A non-string WWeb version type is provided'); + } + + lOperand = lOperand.replace(/-beta$/, ''); + rOperand = rOperand.replace(/-beta$/, ''); + + while (lOperand.length !== rOperand.length) { + lOperand.length > rOperand.length + ? rOperand = rOperand.concat('0') + : lOperand = lOperand.concat('0'); + } + + lOperand = Number(lOperand.replace(/\./g, '')); + rOperand = Number(rOperand.replace(/\./g, '')); + + return ( + operator === '>' ? lOperand > rOperand : + operator === '>=' ? lOperand >= rOperand : + operator === '<' ? lOperand < rOperand : + operator === '<=' ? lOperand <= rOperand : + operator === '=' ? lOperand === rOperand : + false + ); + }; + }); + await page.evaluate(ExposeStore, moduleRaid.toString()); const authEventPayload = await this.authStrategy.getAuthEventPayload(); diff --git a/src/util/Injected.js b/src/util/Injected.js index da8fb2f..d73115f 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -9,7 +9,7 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.AppState = window.mR.findModule('Socket')[0].Socket; window.Store.Conn = window.mR.findModule('Conn')[0].Conn; window.Store.BlockContact = window.mR.findModule('blockContact')[0]; - window.Store.Call = window.mR.findModule('CallCollection')[0].CallCollection; + window.Store.Call = window.mR.findModule((module) => module.default && module.default.Call)[0].default.Call; window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd; window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0]; window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager; @@ -511,7 +511,7 @@ exports.LoadUtils = () => { // TODO: remove useOldImplementation and its checks once all clients are updated to >= v2.2327.4 const useOldImplementation - = window.WWebJS.compareWwebVersions(window.Debug.VERSION, '<', '2.2327.4'); + = window.compareWwebVersions(window.Debug.VERSION, '<', '2.2327.4'); res.isMe = useOldImplementation ? contact.isMe @@ -787,46 +787,4 @@ exports.LoadUtils = () => { throw err; } }; - - /** - * Inner function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version. - * @param {string} lOperand The left operand for the WWeb version string to compare with - * @param {string} operator The comparison operator - * @param {string} rOperand The right operand for the WWeb version string to compare with - * @returns {boolean} Boolean value that indicates the result of the comparison - */ - window.WWebJS.compareWwebVersions = (lOperand, operator, rOperand) => { - if (!['>', '>=', '<', '<=', '='].includes(operator)) { - throw class _ extends Error { - constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; } - }('Invalid comparison operator is provided'); - - } - if (typeof lOperand !== 'string' || typeof rOperand !== 'string') { - throw class _ extends Error { - constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; } - }('A non-string WWeb version type is provided'); - } - - lOperand = lOperand.replace(/-beta$/, ''); - rOperand = rOperand.replace(/-beta$/, ''); - - while (lOperand.length !== rOperand.length) { - lOperand.length > rOperand.length - ? rOperand = rOperand.concat('0') - : lOperand = lOperand.concat('0'); - } - - lOperand = Number(lOperand.replace(/\./g, '')); - rOperand = Number(rOperand.replace(/\./g, '')); - - return ( - operator === '>' ? lOperand > rOperand : - operator === '>=' ? lOperand >= rOperand : - operator === '<' ? lOperand < rOperand : - operator === '<=' ? lOperand <= rOperand : - operator === '=' ? lOperand === rOperand : - false - ); - }; };