fix: CallCollection (#2385)
* fix: changed module for CallCollection * code refactored * compareWwebVersions fixed and moved to window.compareWwebVersions * code refactoring
This commit is contained in:
parent
1ebcdee3b9
commit
3be7566483
2 changed files with 46 additions and 44 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue