Skip to content

Commit 9b1eb76

Browse files
purpshellBenyFilhotuyuribr
authored
general: tree-shaking pre-MD and old comet versions (#5675)
Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>
1 parent 073cf31 commit 9b1eb76

10 files changed

Lines changed: 70 additions & 469 deletions

File tree

index.d.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,6 @@ declare namespace WAWebJS {
323323

324324
/** Emitted when authentication is successful */
325325
on(event: 'authenticated', listener: (
326-
/**
327-
* Object containing session information, when using LegacySessionAuth. Can be used to restore the session
328-
*/
329-
session?: ClientSession
330326
) => void): this
331327

332328
/**
@@ -567,23 +563,15 @@ declare namespace WAWebJS {
567563
evalOnNewDoc?: Function,
568564
/** Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ */
569565
puppeteer?: puppeteer.PuppeteerNodeLaunchOptions & puppeteer.ConnectOptions
570-
/** Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. */
566+
/** Determines how to save and restore sessions. Otherwise, NoAuth will be used. */
571567
authStrategy?: AuthStrategy,
572568
/** The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. */
573569
webVersion?: string,
574570
/** Determines how to retrieve the WhatsApp Web version specified in options.webVersion. */
575571
webVersionCache?: WebCacheOptions,
576572
/** How many times should the qrcode be refreshed before giving up
577573
* @default 0 (disabled) */
578-
qrMaxRetries?: number,
579-
/**
580-
* @deprecated This option should be set directly on the LegacySessionAuth
581-
*/
582-
restartOnAuthFail?: boolean
583-
/**
584-
* @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
585-
*/
586-
session?: ClientSession
574+
qrMaxRetries?: number
587575
/** If another whatsapp web session is detected (another browser), take over the session in the current browser
588576
* @default false */
589577
takeoverOnConflict?: boolean,
@@ -700,17 +688,6 @@ declare namespace WAWebJS {
700688
extract: (options: { session: string, path: string }) => Promise<any> | any,
701689
}
702690

703-
/**
704-
* Legacy session auth strategy
705-
* Not compatible with multi-device accounts.
706-
*/
707-
export class LegacySessionAuth extends AuthStrategy {
708-
constructor(options?: {
709-
session?: ClientSession,
710-
restartOnAuthFail?: boolean,
711-
})
712-
}
713-
714691
/**
715692
* Represents a WhatsApp client session
716693
*/

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
},
3030
"homepage": "https://wwebjs.dev/",
3131
"dependencies": {
32-
"@pedroslopez/moduleraid": "^5.0.2",
3332
"fluent-ffmpeg": "2.1.3",
3433
"mime": "^3.0.0",
3534
"node-fetch": "^2.6.9",

src/Client.js

Lines changed: 57 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
const EventEmitter = require('events');
44
const puppeteer = require('puppeteer');
5-
const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
65

76
const Util = require('./util/Util');
87
const InterfaceController = require('./util/InterfaceController');
98
const { WhatsWebURL, DefaultOptions, Events, WAState, MessageTypes } = require('./util/Constants');
109
const { ExposeAuthStore } = require('./util/Injected/AuthStore/AuthStore');
1110
const { ExposeStore } = require('./util/Injected/Store');
12-
const { ExposeLegacyAuthStore } = require('./util/Injected/AuthStore/LegacyAuthStore');
13-
const { ExposeLegacyStore } = require('./util/Injected/LegacyStore');
1411
const { LoadUtils } = require('./util/Injected/Utils');
1512
const ChatFactory = require('./factories/ChatFactory');
1613
const ContactFactory = require('./factories/ContactFactory');
@@ -23,15 +20,13 @@ const {exposeFunctionIfAbsent} = require('./util/Puppeteer');
2320
* Starting point for interacting with the WhatsApp Web API
2421
* @extends {EventEmitter}
2522
* @param {object} options - Client options
26-
* @param {AuthStrategy} options.authStrategy - Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used.
23+
* @param {AuthStrategy} options.authStrategy - Determines how to save and restore sessions. Otherwise, NoAuth will be used.
2724
* @param {string} options.webVersion - The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved.
2825
* @param {object} options.webVersionCache - Determines how to retrieve the WhatsApp Web version. Defaults to a local cache (LocalWebCache) that falls back to latest if the requested version is not found.
2926
* @param {number} options.authTimeoutMs - Timeout for authentication selector in puppeteer
3027
* @param {function} options.evalOnNewDoc - function to eval on new doc
3128
* @param {object} options.puppeteer - Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/
3229
* @param {number} options.qrMaxRetries - How many times should the qrcode be refreshed before giving up
33-
* @param {string} options.restartOnAuthFail - @deprecated This option should be set directly on the LegacySessionAuth.
34-
* @param {object} options.session - @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
3530
* @param {number} options.takeoverOnConflict - If another whatsapp web session is detected (another browser), take over the session in the current browser
3631
* @param {number} options.takeoverTimeoutMs - How much time to wait before taking over the session
3732
* @param {string} options.userAgent - User agent to use in puppeteer
@@ -113,13 +108,8 @@ class Client extends EventEmitter {
113108
await this.setDeviceName(this.options.deviceName, this.options.browserName);
114109
const pairWithPhoneNumber = this.options.pairWithPhoneNumber;
115110
const version = await this.getWWebVersion();
116-
const isCometOrAbove = parseInt(version.split('.')?.[1]) >= 3000;
117111

118-
if (isCometOrAbove) {
119-
await this.pupPage.evaluate(ExposeAuthStore);
120-
} else {
121-
await this.pupPage.evaluate(ExposeLegacyAuthStore, moduleRaid.toString());
122-
}
112+
await this.pupPage.evaluate(ExposeAuthStore);
123113

124114
const needAuthentication = await this.pupPage.evaluate(async () => {
125115
let state = window.AuthStore.AppState.state;
@@ -231,14 +221,8 @@ class Client extends EventEmitter {
231221
await webCache.persist(this.currentIndexHtml, version);
232222
}
233223

234-
if (isCometOrAbove) {
235-
await this.pupPage.evaluate(ExposeStore);
236-
} else {
237-
// make sure all modules are ready before injection
238-
// 2 second delay after authentication makes sense and does not need to be made dyanmic or removed
239-
await new Promise(r => setTimeout(r, 2000));
240-
await this.pupPage.evaluate(ExposeLegacyStore);
241-
}
224+
await this.pupPage.evaluate(ExposeStore);
225+
242226
let start = Date.now();
243227
let res = false;
244228
while(start > (Date.now() - 30000)){
@@ -354,17 +338,14 @@ class Client extends EventEmitter {
354338
}
355339

356340
// ocVersion (isOfficialClient patch)
357-
// remove after 2.3000.x hard release
358341
await page.evaluateOnNewDocument(() => {
359-
const originalError = Error;
360-
window.originalError = originalError;
342+
window.originalError = Error;
361343
//eslint-disable-next-line no-global-assign
362-
Error = function (message) {
363-
const error = new originalError(message);
364-
const originalStack = error.stack;
365-
if (error.stack.includes('moduleRaid')) error.stack = originalStack + '\n at https://web.whatsapp.com/vendors~lazy_loaded_low_priority_components.05e98054dbd60f980427.js:2:44';
344+
Error = ((message) => {
345+
const error = new window.originalError(message);
346+
error.stack = error.stack + '\n at https://web.whatsapp.com/vendors~lazy_loaded_low_priority_components.05e98054dbd60f980427.js:2:44';
366347
return error;
367-
};
348+
}).bind(Error);
368349
});
369350

370351
await page.goto(WhatsWebURL, {
@@ -778,70 +759,54 @@ class Client extends EventEmitter {
778759
});
779760
window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);});
780761

781-
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620')) {
782-
const module = window.Store.AddonReactionTable;
783-
const ogMethod = module.bulkUpsert;
784-
module.bulkUpsert = ((...args) => {
785-
window.onReaction(args[0].map(reaction => {
786-
const msgKey = reaction.id;
787-
const parentMsgKey = reaction.reactionParentKey;
788-
const timestamp = reaction.reactionTimestamp / 1000;
789-
const sender = reaction.author ?? reaction.from;
790-
const senderUserJid = sender._serialized;
791-
792-
return {...reaction, msgKey, parentMsgKey, senderUserJid, timestamp };
793-
}));
794-
795-
return ogMethod(...args);
796-
}).bind(module);
797-
798-
const pollVoteModule = window.Store.AddonPollVoteTable;
799-
const ogPollVoteMethod = pollVoteModule.bulkUpsert;
800-
801-
pollVoteModule.bulkUpsert = (async (...args) => {
802-
const votes = await Promise.all(args[0].map(async vote => {
803-
const msgKey = vote.id;
804-
const parentMsgKey = vote.pollUpdateParentKey;
805-
const timestamp = vote.t / 1000;
806-
const sender = vote.author ?? vote.from;
807-
const senderUserJid = sender._serialized;
808-
809-
let parentMessage = window.Store.Msg.get(parentMsgKey._serialized);
810-
if (!parentMessage) {
811-
const fetched = await window.Store.Msg.getMessagesById([parentMsgKey._serialized]);
812-
parentMessage = fetched?.messages?.[0] || null;
813-
}
762+
const module = window.Store.AddonReactionTable;
763+
const ogMethod = module.bulkUpsert;
764+
module.bulkUpsert = ((...args) => {
765+
window.onReaction(args[0].map(reaction => {
766+
const msgKey = reaction.id;
767+
const parentMsgKey = reaction.reactionParentKey;
768+
const timestamp = reaction.reactionTimestamp / 1000;
769+
const sender = reaction.author ?? reaction.from;
770+
const senderUserJid = sender._serialized;
771+
772+
return {...reaction, msgKey, parentMsgKey, senderUserJid, timestamp };
773+
}));
814774

815-
return {
816-
...vote,
817-
msgKey,
818-
sender,
819-
parentMsgKey,
820-
senderUserJid,
821-
timestamp,
822-
parentMessage
823-
};
824-
}));
825-
826-
window.onPollVoteEvent(votes);
827-
828-
return ogPollVoteMethod.apply(pollVoteModule, args);
829-
}).bind(pollVoteModule);
830-
} else {
831-
const module = window.Store.createOrUpdateReactionsModule;
832-
const ogMethod = module.createOrUpdateReactions;
833-
module.createOrUpdateReactions = ((...args) => {
834-
window.onReaction(args[0].map(reaction => {
835-
const msgKey = window.Store.MsgKey.fromString(reaction.msgKey);
836-
const parentMsgKey = window.Store.MsgKey.fromString(reaction.parentMsgKey);
837-
const timestamp = reaction.timestamp / 1000;
838-
839-
return {...reaction, msgKey, parentMsgKey, timestamp };
840-
}));
841-
842-
return ogMethod(...args);
843-
}).bind(module);
844-
}
775+
return ogMethod(...args);
776+
}).bind(module);
777+
778+
const pollVoteModule = window.Store.AddonPollVoteTable;
779+
const ogPollVoteMethod = pollVoteModule.bulkUpsert;
780+
781+
pollVoteModule.bulkUpsert = (async (...args) => {
782+
const votes = await Promise.all(args[0].map(async vote => {
783+
const msgKey = vote.id;
784+
const parentMsgKey = vote.pollUpdateParentKey;
785+
const timestamp = vote.t / 1000;
786+
const sender = vote.author ?? vote.from;
787+
const senderUserJid = sender._serialized;
788+
789+
let parentMessage = window.Store.Msg.get(parentMsgKey._serialized);
790+
if (!parentMessage) {
791+
const fetched = await window.Store.Msg.getMessagesById([parentMsgKey._serialized]);
792+
parentMessage = fetched?.messages?.[0] || null;
793+
}
794+
795+
return {
796+
...vote,
797+
msgKey,
798+
sender,
799+
parentMsgKey,
800+
senderUserJid,
801+
timestamp,
802+
parentMessage
803+
};
804+
}));
805+
806+
window.onPollVoteEvent(votes);
807+
808+
return ogPollVoteMethod.apply(pollVoteModule, args);
809+
}).bind(pollVoteModule);
845810
});
846811
}
847812

@@ -1564,9 +1529,7 @@ class Client extends EventEmitter {
15641529
const profilePic = await this.pupPage.evaluate(async contactId => {
15651530
try {
15661531
const chatWid = window.Store.WidFactory.createWid(contactId);
1567-
return window.compareWwebVersions(window.Debug.VERSION, '<', '2.3000.0')
1568-
? await window.Store.ProfilePic.profilePicFind(chatWid)
1569-
: await window.Store.ProfilePic.requestProfilePicFromServer(chatWid);
1532+
return await window.Store.ProfilePic.requestProfilePicFromServer(chatWid);
15701533
} catch (err) {
15711534
if(err.name === 'ServerStatusCodeError') return undefined;
15721535
throw err;

src/structures/GroupChat.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,8 @@ class GroupChat extends Chat {
389389
*/
390390
async getInviteCode() {
391391
const codeRes = await this.client.pupPage.evaluate(async chatId => {
392-
const chatWid = window.Store.WidFactory.createWid(chatId);
393392
try {
394-
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1020730154')
395-
? await window.Store.GroupInvite.fetchMexGroupInviteCode(chatId)
396-
: await window.Store.GroupInvite.queryGroupInviteCode(chatWid, true);
393+
return await window.Store.GroupInvite.fetchMexGroupInviteCode(chatId);
397394
}
398395
catch (err) {
399396
if(err.name === 'ServerStatusCodeError') return undefined;

src/structures/Message.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,10 @@ class Message extends Base {
515515
window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
516516

517517
if (everyone && canRevoke) {
518-
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
519-
? window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: clearMedia })
520-
: window.Store.Cmd.sendRevokeMsgs(chat, [msg], { clearMedia: true, type: msg.id.fromMe ? 'Sender' : 'Admin' });
518+
return window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: clearMedia });
521519
}
522520

523-
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
524-
? window.Store.Cmd.sendDeleteMsgs(chat, { list: [msg], type: 'message' }, clearMedia)
525-
: window.Store.Cmd.sendDeleteMsgs(chat, [msg], clearMedia);
521+
return window.Store.Cmd.sendDeleteMsgs(chat, { list: [msg], type: 'message' }, clearMedia);
526522
}, this.id._serialized, everyone, clearMedia);
527523
}
528524

src/util/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports.DefaultOptions = {
77
headless: true,
88
defaultViewport: null
99
},
10-
webVersion: '2.3000.1017054665',
10+
webVersion: '2.3000.1030947950',
1111
webVersionCache: {
1212
type: 'local',
1313
},

src/util/Injected/AuthStore/LegacyAuthStore.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)