Skip to content

Commit 883d7e4

Browse files
purpshellBenyFilho
andauthored
Store: remove all mentions of window.Store (#127077)
* Store: remove all mentions of window.Store * Apply suggestion from @BenyFilho Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> --------- Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
1 parent 9e42f1e commit 883d7e4

14 files changed

Lines changed: 522 additions & 754 deletions

File tree

index.d.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ declare namespace WAWebJS {
322322
on(event: 'auth_failure', listener: (message: string) => void): this
323323

324324
/** Emitted when authentication is successful */
325-
on(event: 'authenticated', listener: (
326-
) => void): this
325+
on(event: 'authenticated', listener: () => void): this
327326

328327
/**
329328
* Emitted when the battery percentage for the attached device changes
@@ -563,7 +562,7 @@ declare namespace WAWebJS {
563562
evalOnNewDoc?: Function,
564563
/** Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ */
565564
puppeteer?: puppeteer.PuppeteerNodeLaunchOptions & puppeteer.ConnectOptions
566-
/** Determines how to save and restore sessions. Otherwise, NoAuth will be used. */
565+
/** Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. */
567566
authStrategy?: AuthStrategy,
568567
/** The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. */
569568
webVersion?: string,
@@ -688,16 +687,6 @@ declare namespace WAWebJS {
688687
extract: (options: { session: string, path: string }) => Promise<any> | any,
689688
}
690689

691-
/**
692-
* Represents a WhatsApp client session
693-
*/
694-
export interface ClientSession {
695-
WABrowserId: string,
696-
WASecretBundle: string,
697-
WAToken1: string,
698-
WAToken2: string,
699-
}
700-
701690
/**
702691
* @deprecated
703692
*/

src/Client.js

Lines changed: 163 additions & 165 deletions
Large diffs are not rendered by default.

src/structures/Channel.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class Channel extends Base {
103103
return await this.client.pupPage.evaluate(async (channelId, limit) => {
104104
const channel = await window.WWebJS.getChat(channelId, { getAsModel: false });
105105
if (!channel) return [];
106-
!limit && (limit = window.Store.ChannelUtils.getMaxSubscriberNumber());
107-
const response = await window.Store.ChannelSubscribers.mexFetchNewsletterSubscribers(channelId, limit);
108-
const contacts = window.Store.ChannelSubscribers.getSubscribersInContacts(response.subscribers);
106+
!limit && (limit = window.require('WAWebNewsletterGatingUtils').getMaxSubscriberNumber());
107+
const response = await (window.require('WAWebMexFetchNewsletterSubscribersJob')).mexFetchNewsletterSubscribers(channelId, limit);
108+
const contacts = (window.require('WAWebNewsletterSubscriberListAction')).getSubscribersInContacts(response.subscribers);
109109
return Promise.all(contacts.map((obj) => ({
110110
...obj,
111111
contact: window.WWebJS.getContactModel(obj.contact)
@@ -303,7 +303,7 @@ class Channel extends Base {
303303

304304
if (searchOptions && searchOptions.limit > 0) {
305305
while (msgs.length < searchOptions.limit) {
306-
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(channel);
306+
const loadedMessages = await (window.require('WAWebChatLoadMessages')).loadEarlierMsgs(channel);
307307
if (!loadedMessages || !loadedMessages.length) break;
308308
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
309309
}
@@ -350,7 +350,7 @@ class Channel extends Base {
350350
: null;
351351
}
352352
try {
353-
await window.Store.ChannelUtils.editNewsletterMetadataAction(channel, property, value);
353+
await (window.require('WAWebEditNewsletterMetadataAction')).editNewsletterMetadataAction(channel, property, value);
354354
return true;
355355
} catch (err) {
356356
if (err.name === 'ServerStatusCodeError') return false;
@@ -367,9 +367,11 @@ class Channel extends Base {
367367
async _muteUnmuteChannel(action) {
368368
return await this.client.pupPage.evaluate(async (channelId, action) => {
369369
try {
370-
action === 'MUTE'
371-
? await window.Store.ChannelUtils.muteNewsletter([channelId])
372-
: await window.Store.ChannelUtils.unmuteNewsletter([channelId]);
370+
await (window.require('WAWebNewsletterUpdateUserSettingJob')).updateNewsletterUserSetting({
371+
newsletterJid: window.require('WAJids').toNewsletterJid(channelId),
372+
type: window.require('WAWebNewsletterModelUtils').ADMIN_NOTIFICATIONS,
373+
muteExpirationValue: action === 'MUTE' ? window.require('WAWebNewsletterModelUtils').MUTED_STATE : window.require('WAWebNewsletterModelUtils').UNMUTED_STATE
374+
});
373375
return true;
374376
} catch (err) {
375377
if (err.name === 'ServerStatusCodeError') return false;

src/structures/Chat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Chat extends Base {
212212

213213
if (searchOptions && searchOptions.limit > 0) {
214214
while (msgs.length < searchOptions.limit) {
215-
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat,chat.msgs);
215+
const loadedMessages = await (window.require('WAWebChatLoadMessages')).loadEarlierMsgs(chat,chat.msgs);
216216
if (!loadedMessages || !loadedMessages.length) break;
217217
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
218218
}

src/structures/ClientInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ClientInfo extends Base {
6262
*/
6363
async getBatteryStatus() {
6464
return await this.client.pupPage.evaluate(() => {
65-
const { battery, plugged } = window.Store.Conn;
65+
const { battery, plugged } = window.require('WAWebConnModel').Conn;
6666
return { battery, plugged };
6767
});
6868
}

src/structures/Contact.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ class Contact extends Base {
155155
if(this.isGroup) return false;
156156

157157
await this.client.pupPage.evaluate(async (contactId) => {
158-
const contact = window.Store.Contact.get(contactId);
159-
await window.Store.BlockContact.blockContact({contact});
158+
const contact = (window.require('WAWebCollections')).Contact.get(contactId);
159+
await (window.require('WAWebBlockContactAction')).blockContact({contact});
160160
}, this.id._serialized);
161161

162162
this.isBlocked = true;
@@ -171,8 +171,8 @@ class Contact extends Base {
171171
if(this.isGroup) return false;
172172

173173
await this.client.pupPage.evaluate(async (contactId) => {
174-
const contact = window.Store.Contact.get(contactId);
175-
await window.Store.BlockContact.unblockContact(contact);
174+
const contact = (window.require('WAWebCollections')).Contact.get(contactId);
175+
await (window.require('WAWebBlockContactAction')).unblockContact(contact);
176176
}, this.id._serialized);
177177

178178
this.isBlocked = false;
@@ -185,8 +185,8 @@ class Contact extends Base {
185185
*/
186186
async getAbout() {
187187
const about = await this.client.pupPage.evaluate(async (contactId) => {
188-
const wid = window.Store.WidFactory.createWid(contactId);
189-
return window.Store.StatusUtils.getStatus({'token':'', 'wid': wid});
188+
const wid = window.require('WAWebWidFactory').createWid(contactId);
189+
return (window.require('WAWebContactStatusBridge')).getStatus({'token':'', 'wid': wid});
190190
}, this.id._serialized);
191191

192192
if (typeof about.status !== 'string')

src/structures/GroupChat.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class GroupChat extends Chat {
8181
const participantData = {};
8282

8383
!Array.isArray(participantIds) && (participantIds = [participantIds]);
84-
const groupWid = window.Store.WidFactory.createWid(groupId);
85-
const group = window.Store.Chat.get(groupWid) || (await window.Store.Chat.find(groupWid));
86-
const participantWids = participantIds.map((p) => window.Store.WidFactory.createWid(p));
84+
const groupWid = window.require('WAWebWidFactory').createWid(groupId);
85+
const group = (window.require('WAWebCollections')).Chat.get(groupWid) || (await (window.require('WAWebCollections')).Chat.find(groupWid));
86+
const participantWids = participantIds.map((p) => window.require('WAWebWidFactory').createWid(p));
8787

8888
const errorCodes = {
8989
default: 'An unknown error occupied while adding a participant',
@@ -98,7 +98,7 @@ class GroupChat extends Chat {
9898
419: 'The participant can\'t be added because the group is full'
9999
};
100100

101-
await window.Store.GroupQueryAndUpdate({ id: groupId });
101+
await (window.require('WAWebGroupQueryJob')).queryAndUpdateGroupMetadataById({ id: groupId });
102102

103103
let groupParticipants = group.groupMetadata?.participants.serialize();
104104

@@ -111,7 +111,7 @@ class GroupChat extends Chat {
111111
}
112112

113113
groupParticipants.map(({ id }) => {
114-
return id.server === 'lid' ? window.Store.LidUtils.getPhoneNumber(id) : id;
114+
return id.server === 'lid' ? window.require('WAWebApiContact').getPhoneNumber(id) : id;
115115
});
116116

117117
const _getSleepTime = (sleep) => {
@@ -127,7 +127,7 @@ class GroupChat extends Chat {
127127

128128
for (let pWid of participantWids) {
129129
const pId = pWid._serialized;
130-
pWid = pWid.server === 'lid' ? window.Store.LidUtils.getPhoneNumber(pWid) : pWid;
130+
pWid = pWid.server === 'lid' ? window.require('WAWebApiContact').getPhoneNumber(pWid) : pWid;
131131

132132
participantData[pId] = {
133133
code: undefined,
@@ -141,7 +141,7 @@ class GroupChat extends Chat {
141141
continue;
142142
}
143143

144-
if (!(await window.Store.QueryExist(pWid))?.wid) {
144+
if (!(await (window.require('WAWebQueryExistsJob').queryWidExists)(pWid))?.wid) {
145145
participantData[pId].code = 404;
146146
participantData[pId].message = errorCodes[404];
147147
continue;
@@ -157,12 +157,12 @@ class GroupChat extends Chat {
157157

158158
if (autoSendInviteV4 && rpcResultCode === 403) {
159159
let userChat, isInviteV4Sent = false;
160-
window.Store.Contact.gadd(pWid, { silent: true });
160+
(window.require('WAWebCollections')).Contact.gadd(pWid, { silent: true });
161161

162162
if (rpcResult.name === 'ParticipantRequestCodeCanBeSent' &&
163-
(userChat = window.Store.Chat.get(pWid) || (await window.Store.Chat.find(pWid)))) {
163+
(userChat = (window.require('WAWebCollections')).Chat.get(pWid) || (await (window.require('WAWebCollections')).Chat.find(pWid)))) {
164164
const groupName = group.formattedTitle || group.name;
165-
const res = await window.Store.GroupInviteV4.sendGroupInviteMessage(
165+
const res = await (window.require('WAWebChatSendMessages')).sendGroupInviteMessage(
166166
userChat,
167167
group.id._serialized,
168168
groupName,
@@ -201,7 +201,7 @@ class GroupChat extends Chat {
201201
return chat.groupMetadata.participants.get(lid?._serialized) ||
202202
chat.groupMetadata.participants.get(phone?._serialized);
203203
}))).filter(Boolean);
204-
await window.Store.GroupParticipants.removeParticipants(chat, participants);
204+
await (window.require('WAWebModifyParticipantsGroupAction')).removeParticipants(chat, participants);
205205
return { status: 200 };
206206
}, this.id._serialized, participantIds);
207207
}
@@ -220,7 +220,7 @@ class GroupChat extends Chat {
220220
return chat.groupMetadata.participants.get(lid?._serialized) ||
221221
chat.groupMetadata.participants.get(phone?._serialized);
222222
}))).filter(Boolean);
223-
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
223+
await (window.require('WAWebModifyParticipantsGroupAction')).promoteParticipants(chat, participants);
224224
return { status: 200 };
225225
}, this.id._serialized, participantIds);
226226
}
@@ -239,7 +239,7 @@ class GroupChat extends Chat {
239239
return chat.groupMetadata.participants.get(lid?._serialized) ||
240240
chat.groupMetadata.participants.get(phone?._serialized);
241241
}))).filter(Boolean);
242-
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
242+
await (window.require('WAWebModifyParticipantsGroupAction')).demoteParticipants(chat, participants);
243243
return { status: 200 };
244244
}, this.id._serialized, participantIds);
245245
}
@@ -251,9 +251,9 @@ class GroupChat extends Chat {
251251
*/
252252
async setSubject(subject) {
253253
const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
254-
const chatWid = window.Store.WidFactory.createWid(chatId);
254+
const chatWid = window.require('WAWebWidFactory').createWid(chatId);
255255
try {
256-
await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
256+
await (window.require('WAWebGroupModifyInfoJob')).setGroupSubject(chatWid, subject);
257257
return true;
258258
} catch (err) {
259259
if(err.name === 'ServerStatusCodeError') return false;
@@ -273,12 +273,12 @@ class GroupChat extends Chat {
273273
*/
274274
async setDescription(description) {
275275
const success = await this.client.pupPage.evaluate(async (chatId, description) => {
276-
const chatWid = window.Store.WidFactory.createWid(chatId);
276+
const chatWid = window.require('WAWebWidFactory').createWid(chatId);
277277
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
278278
let descId = chat.groupMetadata.descId;
279-
let newId = await window.Store.MsgKey.newId();
279+
let newId = await (window.require('WAWebMsgKey')).newId();
280280
try {
281-
await window.Store.GroupUtils.setGroupDescription(chatWid, description, newId, descId);
281+
await (window.require('WAWebGroupModifyInfoJob')).setGroupDescription(chatWid, description, newId, descId);
282282
return true;
283283
} catch (err) {
284284
if(err.name === 'ServerStatusCodeError') return false;
@@ -300,7 +300,7 @@ class GroupChat extends Chat {
300300
const success = await this.client.pupPage.evaluate(async (groupId, adminsOnly) => {
301301
const chat = await window.WWebJS.getChat(groupId, { getAsModel: false });
302302
try {
303-
await window.Store.GroupUtils.setGroupProperty(chat, 'member_add_mode', adminsOnly ? 0 : 1);
303+
await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'member_add_mode', adminsOnly ? 0 : 1);
304304
return true;
305305
} catch (err) {
306306
if(err.name === 'ServerStatusCodeError') return false;
@@ -321,7 +321,7 @@ class GroupChat extends Chat {
321321
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
322322
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
323323
try {
324-
await window.Store.GroupUtils.setGroupProperty(chat, 'announcement', adminsOnly ? 1 : 0);
324+
await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'announcement', adminsOnly ? 1 : 0);
325325
return true;
326326
} catch (err) {
327327
if(err.name === 'ServerStatusCodeError') return false;
@@ -344,7 +344,7 @@ class GroupChat extends Chat {
344344
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
345345
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
346346
try {
347-
await window.Store.GroupUtils.setGroupProperty(chat, 'restrict', adminsOnly ? 1 : 0);
347+
await (window.require('WAWebSetPropertyGroupAction')).setGroupProperty(chat, 'restrict', adminsOnly ? 1 : 0);
348348
return true;
349349
} catch (err) {
350350
if(err.name === 'ServerStatusCodeError') return false;
@@ -390,7 +390,7 @@ class GroupChat extends Chat {
390390
async getInviteCode() {
391391
const codeRes = await this.client.pupPage.evaluate(async chatId => {
392392
try {
393-
return await window.Store.GroupInvite.fetchMexGroupInviteCode(chatId);
393+
return await (window.require('WAWebMexFetchGroupInviteCodeJob')).fetchMexGroupInviteCode(chatId);
394394
}
395395
catch (err) {
396396
if(err.name === 'ServerStatusCodeError') return undefined;
@@ -409,8 +409,8 @@ class GroupChat extends Chat {
409409
*/
410410
async revokeInvite() {
411411
const codeRes = await this.client.pupPage.evaluate(chatId => {
412-
const chatWid = window.Store.WidFactory.createWid(chatId);
413-
return window.Store.GroupInvite.resetGroupInviteCode(chatWid);
412+
const chatWid = window.require('WAWebWidFactory').createWid(chatId);
413+
return (window.require('WAWebGroupQueryJob')).resetGroupInviteCode(chatWid);
414414
}, this.id._serialized);
415415

416416
return codeRes.code;
@@ -474,7 +474,7 @@ class GroupChat extends Chat {
474474
async leave() {
475475
await this.client.pupPage.evaluate(async chatId => {
476476
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
477-
return window.Store.GroupUtils.sendExitGroup(chat);
477+
return (window.require('WAWebExitGroupAction')).sendExitGroup(chat);
478478
}, this.id._serialized);
479479
}
480480

0 commit comments

Comments
 (0)