@pney/whatsapp-web 1.34.4-node20 → 1.34.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,32 +3,123 @@
3
3
  exports.LoadUtils = () => {
4
4
  window.WWebJS = {};
5
5
 
6
+ /**
7
+ * 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.
8
+ * @param {string} lOperand The left operand for the WWeb version string to compare with
9
+ * @param {string} operator The comparison operator
10
+ * @param {string} rOperand The right operand for the WWeb version string to compare with
11
+ * @returns {boolean} Boolean value that indicates the result of the comparison
12
+ */
13
+ window.WWebJS.compareWwebVersions = (lOperand, operator, rOperand) => {
14
+ if (!['>', '>=', '<', '<=', '='].includes(operator)) {
15
+ throw new class _ extends Error {
16
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
17
+ }('Invalid comparison operator is provided');
18
+
19
+ }
20
+ if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
21
+ throw new class _ extends Error {
22
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
23
+ }('A non-string WWeb version type is provided');
24
+ }
25
+
26
+ lOperand = lOperand.replace(/-beta$/, '');
27
+ rOperand = rOperand.replace(/-beta$/, '');
28
+
29
+ while (lOperand.length !== rOperand.length) {
30
+ lOperand.length > rOperand.length
31
+ ? rOperand = rOperand.concat('0')
32
+ : lOperand = lOperand.concat('0');
33
+ }
34
+
35
+ lOperand = Number(lOperand.replace(/\./g, ''));
36
+ rOperand = Number(rOperand.replace(/\./g, ''));
37
+
38
+ return (
39
+ operator === '>' ? lOperand > rOperand :
40
+ operator === '>=' ? lOperand >= rOperand :
41
+ operator === '<' ? lOperand < rOperand :
42
+ operator === '<=' ? lOperand <= rOperand :
43
+ operator === '=' ? lOperand === rOperand :
44
+ false
45
+ );
46
+ };
47
+
48
+ /**
49
+ * Target options object description
50
+ * @typedef {Object} TargetOptions
51
+ * @property {string|number} module The target module
52
+ * @property {string} function The function name to get from a module
53
+ */
54
+ /**
55
+ * Function to modify functions
56
+ * @param {TargetOptions} target Options specifying the target function to search for modifying
57
+ * @param {Function} callback Modified function
58
+ */
59
+ window.WWebJS.injectToFunction = (target, callback) => {
60
+ try {
61
+ let module = window.require(target.module);
62
+ if (!module) return;
63
+
64
+ const path = target.function.split('.');
65
+ const funcName = path.pop();
66
+
67
+ for (const key of path) {
68
+ if (!module[key]) return;
69
+ module = module[key];
70
+ }
71
+
72
+ const originalFunction = module[funcName];
73
+ if (typeof originalFunction !== 'function') return;
74
+
75
+ module[funcName] = ((...args) => {
76
+ try {
77
+ return callback(module, originalFunction, ...args);
78
+ } catch {
79
+ return originalFunction.apply(module, args);
80
+ }
81
+ }).bind(module);
82
+
83
+ } catch {
84
+ return;
85
+ }
86
+ };
87
+
88
+ window.WWebJS.injectToFunction({ module: 'WAWebBackendJobsCommon', function: 'mediaTypeFromProtobuf' }, (module, func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
89
+
90
+ window.WWebJS.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (module, func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
91
+
92
+
6
93
  window.WWebJS.forwardMessage = async (chatId, msgId) => {
7
- const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
94
+ const msg = (window.require('WAWebCollections')).Msg.get(msgId) || (await (window.require('WAWebCollections')).Msg.getMessagesById([msgId]))?.messages?.[0];
8
95
  const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
9
- return await window.Store.ForwardUtils.forwardMessages({'chat': chat, 'msgs' : [msg], 'multicast': true, 'includeCaption': true, 'appendedText' : undefined});
96
+ return await (window.require('WAWebChatForwardMessage')).forwardMessages({'chat': chat, 'msgs' : [msg], 'multicast': true, 'includeCaption': true, 'appendedText' : undefined});
10
97
  };
11
98
 
12
99
  window.WWebJS.sendSeen = async (chatId) => {
13
100
  const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
14
101
  if (chat) {
15
- window.Store.WAWebStreamModel.Stream.markAvailable();
16
- await window.Store.SendSeen.sendSeen({
102
+ window.require('WAWebStreamModel').Stream.markAvailable();
103
+ await (window.require('WAWebUpdateUnreadChatAction')).sendSeen({
17
104
  chat: chat,
18
105
  threadId: undefined
19
- });
20
- window.Store.WAWebStreamModel.Stream.markUnavailable();
106
+ });
107
+ window.require('WAWebStreamModel').Stream.markUnavailable();
21
108
  return true;
22
109
  }
23
110
  return false;
24
111
  };
25
112
 
26
113
  window.WWebJS.sendMessage = async (chat, content, options = {}) => {
27
- const isChannel = window.Store.ChatGetters.getIsNewsletter(chat);
114
+ const { getIsNewsletter, getIsBroadcast } = window.require('WAWebChatGetters');
115
+ const isChannel = getIsNewsletter(chat);
116
+ const isStatus = getIsBroadcast(chat);
28
117
 
118
+ const { findLink } = window.require('WALinkify');
119
+
29
120
  let mediaOptions = {};
30
121
  if (options.media) {
31
- mediaOptions = options.sendMediaAsSticker && !isChannel
122
+ mediaOptions = options.sendMediaAsSticker && !isChannel && !isStatus
32
123
  ? await window.WWebJS.processStickerData(options.media)
33
124
  : await window.WWebJS.processMediaData(options.media, {
34
125
  forceSticker: options.sendMediaAsSticker,
@@ -36,7 +127,8 @@ exports.LoadUtils = () => {
36
127
  forceVoice: options.sendAudioAsVoice,
37
128
  forceDocument: options.sendMediaAsDocument,
38
129
  forceMediaHd: options.sendMediaAsHd,
39
- sendToChannel: isChannel
130
+ sendToChannel: isChannel,
131
+ sendToStatus: isStatus
40
132
  });
41
133
  mediaOptions.caption = options.caption;
42
134
  content = options.sendMediaAsSticker ? undefined : mediaOptions.preview;
@@ -47,12 +139,13 @@ exports.LoadUtils = () => {
47
139
 
48
140
  let quotedMsgOptions = {};
49
141
  if (options.quotedMessageId) {
50
- let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
51
- !quotedMessage && (quotedMessage = (await window.Store.Msg.getMessagesById([options.quotedMessageId]))?.messages?.[0]);
142
+ let quotedMessage = (window.require('WAWebCollections')).Msg.get(options.quotedMessageId);
143
+ !quotedMessage && (quotedMessage = (await (window.require('WAWebCollections')).Msg.getMessagesById([options.quotedMessageId]))?.messages?.[0]);
52
144
  if (quotedMessage) {
53
145
 
54
- const canReply = window.Store.ReplyUtils
55
- ? window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe())
146
+ const ReplyUtils = window.require('WAWebMsgReply');
147
+ const canReply = ReplyUtils
148
+ ? ReplyUtils.canReplyMsg(quotedMessage.unsafe())
56
149
  : quotedMessage.canReply();
57
150
 
58
151
  if (canReply) {
@@ -69,21 +162,21 @@ exports.LoadUtils = () => {
69
162
  }
70
163
 
71
164
  if (options.mentionedJidList) {
72
- options.mentionedJidList = options.mentionedJidList.map((id) => window.Store.WidFactory.createWid(id));
165
+ options.mentionedJidList = options.mentionedJidList.map((id) => window.require('WAWebWidFactory').createWid(id));
73
166
  options.mentionedJidList = options.mentionedJidList.filter(Boolean);
74
167
  }
75
168
 
76
169
  if (options.groupMentions) {
77
170
  options.groupMentions = options.groupMentions.map((e) => ({
78
171
  groupSubject: e.subject,
79
- groupJid: window.Store.WidFactory.createWid(e.id)
172
+ groupJid: window.require('WAWebWidFactory').createWid(e.id)
80
173
  }));
81
174
  }
82
175
 
83
176
  let locationOptions = {};
84
177
  if (options.location) {
85
178
  let { latitude, longitude, description, url } = options.location;
86
- url = window.Store.Validators.findLink(url)?.href;
179
+ url = findLink(url)?.href;
87
180
  url && !description && (description = url);
88
181
  locationOptions = {
89
182
  type: 'location',
@@ -128,7 +221,7 @@ exports.LoadUtils = () => {
128
221
  degreesLongitude: 0,
129
222
  name: eventSendOptions.location
130
223
  },
131
- eventJoinLink: eventSendOptions.callType === 'none' ? null : await window.Store.ScheduledEventMsgUtils.createEventCallLink(
224
+ eventJoinLink: eventSendOptions.callType === 'none' ? null : await (window.require('WAWebGenerateEventCallLink')).createEventCallLink(
132
225
  startTimeTs,
133
226
  eventSendOptions.callType
134
227
  ),
@@ -143,16 +236,16 @@ exports.LoadUtils = () => {
143
236
 
144
237
  let vcardOptions = {};
145
238
  if (options.contactCard) {
146
- let contact = window.Store.Contact.get(options.contactCard);
239
+ let contact = (window.require('WAWebCollections')).Contact.get(options.contactCard);
147
240
  vcardOptions = {
148
- body: window.Store.VCard.vcardFromContactModel(contact).vcard,
241
+ body: window.require('WAWebFrontendVcardUtils').vcardFromContactModel(contact).vcard,
149
242
  type: 'vcard',
150
243
  vcardFormattedName: contact.formattedName
151
244
  };
152
245
  delete options.contactCard;
153
246
  } else if (options.contactCardList) {
154
- let contacts = options.contactCardList.map(c => window.Store.Contact.get(c));
155
- let vcards = contacts.map(c => window.Store.VCard.vcardFromContactModel(c));
247
+ let contacts = options.contactCardList.map(c => (window.require('WAWebCollections')).Contact.get(c));
248
+ let vcards = contacts.map(c => window.require('WAWebFrontendVcardUtils').vcardFromContactModel(c));
156
249
  vcardOptions = {
157
250
  type: 'multi_vcard',
158
251
  vcardList: vcards,
@@ -163,11 +256,11 @@ exports.LoadUtils = () => {
163
256
  delete options.parseVCards;
164
257
  delete options.linkPreview;
165
258
  try {
166
- const parsed = window.Store.VCard.parseVcard(content);
259
+ const parsed = window.require('WAWebVcardParsingUtils').parseVcard(content);
167
260
  if (parsed) {
168
261
  vcardOptions = {
169
262
  type: 'vcard',
170
- vcardFormattedName: window.Store.VCard.vcardGetNameFromParsed(parsed)
263
+ vcardFormattedName: window.require('WAWebVcardGetNameFromParsed').vcardGetNameFromParsed(parsed)
171
264
  };
172
265
  }
173
266
  } catch (_) {
@@ -177,9 +270,9 @@ exports.LoadUtils = () => {
177
270
 
178
271
  if (options.linkPreview) {
179
272
  delete options.linkPreview;
180
- const link = window.Store.Validators.findLink(content);
273
+ const link = findLink(content);
181
274
  if (link) {
182
- let preview = await window.Store.LinkPreview.getLinkPreview(link);
275
+ let preview = await (window.require('WAWebLinkPreviewChatAction')).getLinkPreview(link);
183
276
  if (preview && preview.data) {
184
277
  preview = preview.data;
185
278
  preview.preview = true;
@@ -213,7 +306,7 @@ exports.LoadUtils = () => {
213
306
 
214
307
  let listOptions = {};
215
308
  if (options.list) {
216
- if (window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi') {
309
+ if ((window.require('WAWebConnModel').Conn).platform === 'smba' || (window.require('WAWebConnModel').Conn).platform === 'smbi') {
217
310
  throw '[LT01] Whatsapp business can\'t send this yet';
218
311
  }
219
312
  listOptions = {
@@ -232,24 +325,28 @@ exports.LoadUtils = () => {
232
325
  const botOptions = {};
233
326
  if (options.invokedBotWid) {
234
327
  botOptions.messageSecret = window.crypto.getRandomValues(new Uint8Array(32));
235
- botOptions.botMessageSecret = await window.Store.BotSecret.genBotMsgSecretFromMsgSecret(botOptions.messageSecret);
236
- botOptions.invokedBotWid = window.Store.WidFactory.createWid(options.invokedBotWid);
237
- botOptions.botPersonaId = window.Store.BotProfiles.BotProfileCollection.get(options.invokedBotWid).personaId;
328
+ botOptions.botMessageSecret = await (window.require('WAWebBotMessageSecret')).genBotMsgSecretFromMsgSecret(botOptions.messageSecret);
329
+ botOptions.invokedBotWid = window.require('WAWebWidFactory').createWid(options.invokedBotWid);
330
+ botOptions.botPersonaId = window.require('WAWebBotProfileCollection').BotProfileCollection.get(options.invokedBotWid).personaId;
238
331
  delete options.invokedBotWid;
239
332
  }
240
-
241
- const lidUser = window.Store.User.getMaybeMeLidUser();
242
- const meUser = window.Store.User.getMaybeMePnUser();
243
- const newId = await window.Store.MsgKey.newId();
333
+ const { getMaybeMeLidUser, getMaybeMePnUser } = window.require('WAWebUserPrefsMeUser');
334
+ const lidUser = getMaybeMeLidUser();
335
+ const meUser = getMaybeMePnUser();
336
+ const newId = await (window.require('WAWebMsgKey')).newId();
244
337
  let from = chat.id.isLid() ? lidUser : meUser;
245
338
  let participant;
246
339
 
247
340
  if (typeof chat.id?.isGroup === 'function' && chat.id.isGroup()) {
248
341
  from = chat.groupMetadata && chat.groupMetadata.isLidAddressingMode ? lidUser : meUser;
249
- participant = window.Store.WidFactory.asUserWidOrThrow(from);
342
+ participant = window.require('WAWebWidFactory').asUserWidOrThrow(from);
343
+ }
344
+
345
+ if (typeof chat.id?.isStatus === 'function' && chat.id.isStatus()) {
346
+ participant = window.require('WAWebWidFactory').asUserWidOrThrow(from);
250
347
  }
251
348
 
252
- const newMsgKey = new window.Store.MsgKey({
349
+ const newMsgKey = new (window.require('WAWebMsgKey'))({
253
350
  from: from,
254
351
  to: chat.id,
255
352
  id: newId,
@@ -260,7 +357,7 @@ exports.LoadUtils = () => {
260
357
  const extraOptions = options.extraOptions || {};
261
358
  delete options.extraOptions;
262
359
 
263
- const ephemeralFields = window.Store.EphemeralFields.getEphemeralFields(chat);
360
+ const ephemeralFields = window.require('WAWebGetEphemeralFieldsMsgActionsUtils').getEphemeralFields(chat);
264
361
 
265
362
  const message = {
266
363
  ...options,
@@ -294,14 +391,14 @@ exports.LoadUtils = () => {
294
391
  }
295
392
 
296
393
  if (isChannel) {
297
- const msg = new window.Store.Msg.modelClass(message);
298
- const msgDataFromMsgModel = window.Store.SendChannelMessage.msgDataFromMsgModel(msg);
394
+ const msg = new (window.require('WAWebCollections')).Msg.modelClass(message);
395
+ const msgDataFromMsgModel = (window.require('WAWebMsgDataFromModel')).msgDataFromMsgModel(msg);
299
396
  const isMedia = Object.keys(mediaOptions).length > 0;
300
- await window.Store.SendChannelMessage.addNewsletterMsgsRecords([msgDataFromMsgModel]);
397
+ await (window.require('WAWebNewsletterUpdateMsgsRecordsJob')).addNewsletterMsgsRecords([msgDataFromMsgModel]);
301
398
  chat.msgs.add(msg);
302
399
  chat.t = msg.t;
303
400
 
304
- const sendChannelMsgResponse = await window.Store.SendChannelMessage.sendNewsletterMessageJob({
401
+ const sendChannelMsgResponse = await (window.require('WAWebNewsletterSendMessageJob')).sendNewsletterMessageJob({
305
402
  msg: msg,
306
403
  type: message.type === 'chat' ? 'text' : isMedia ? 'media' : 'pollCreation',
307
404
  newsletterJid: chat.id.toJid(),
@@ -319,16 +416,47 @@ exports.LoadUtils = () => {
319
416
  msg.serverId = sendChannelMsgResponse.serverId;
320
417
  }
321
418
  msg.updateAck(1, true);
322
- await window.Store.SendChannelMessage.updateNewsletterMsgRecord(msg);
419
+ await (window.require('WAWebNewsletterUpdateMsgsRecordsJob')).updateNewsletterMsgRecord(msg);
323
420
  return msg;
324
421
  }
325
422
 
326
- const [msgPromise, sendMsgResultPromise] = window.Store.SendMessage.addAndSendMsgToChat(chat, message);
423
+ if (isStatus) {
424
+ const { backgroundColor, fontStyle } = extraOptions;
425
+ const isMedia = Object.keys(mediaOptions).length > 0;
426
+ const mediaUpdate = data => (window.require('WAWebMediaUpdateMsg'))(data, mediaOptions);
427
+ const msg = new (window.require('WAWebCollections')).Msg.modelClass({
428
+ ...message,
429
+ author: participant ? participant : null,
430
+ messageSecret: window.crypto.getRandomValues(new Uint8Array(32)),
431
+ cannotBeRanked: (window.require('WAWebStatusGatingUtils')).canCheckStatusRankingPosterGating()
432
+ });
433
+
434
+ // for text only
435
+ const statusOptions = {
436
+ color: backgroundColor && window.WWebJS.assertColor(backgroundColor) || 0xff7acca5,
437
+ font: fontStyle >= 0 && fontStyle <= 7 && fontStyle || 0,
438
+ text: msg.body
439
+ };
440
+
441
+ await (window.require('WAWebSendStatusMsgAction'))[
442
+ isMedia ?
443
+ 'sendStatusMediaMsgAction' : 'sendStatusTextMsgAction'
444
+ ](
445
+ ...(
446
+ isMedia ?
447
+ [msg, mediaUpdate] : [statusOptions]
448
+ )
449
+ );
450
+
451
+ return msg;
452
+ }
453
+
454
+ const [msgPromise, sendMsgResultPromise] = (window.require('WAWebSendMsgChatAction')).addAndSendMsgToChat(chat, message);
327
455
  await msgPromise;
328
456
 
329
457
  if (options.waitUntilMsgSent) await sendMsgResultPromise;
330
458
 
331
- return window.Store.Msg.get(newMsgKey._serialized);
459
+ return (window.require('WAWebCollections')).Msg.get(newMsgKey._serialized);
332
460
  };
333
461
 
334
462
  window.WWebJS.editMessage = async (msg, content, options = {}) => {
@@ -336,22 +464,23 @@ exports.LoadUtils = () => {
336
464
  delete options.extraOptions;
337
465
 
338
466
  if (options.mentionedJidList) {
339
- options.mentionedJidList = options.mentionedJidList.map((id) => window.Store.WidFactory.createWid(id));
467
+ options.mentionedJidList = options.mentionedJidList.map((id) => window.require('WAWebWidFactory').createWid(id));
340
468
  options.mentionedJidList = options.mentionedJidList.filter(Boolean);
341
469
  }
342
470
 
343
471
  if (options.groupMentions) {
344
472
  options.groupMentions = options.groupMentions.map((e) => ({
345
473
  groupSubject: e.subject,
346
- groupJid: window.Store.WidFactory.createWid(e.id)
474
+ groupJid: window.require('WAWebWidFactory').createWid(e.id)
347
475
  }));
348
476
  }
349
477
 
350
478
  if (options.linkPreview) {
479
+ const { findLink } = window.require('WALinkify');
351
480
  delete options.linkPreview;
352
- const link = window.Store.Validators.findLink(content);
481
+ const link = findLink(content);
353
482
  if (link) {
354
- const preview = await window.Store.LinkPreview.getLinkPreview(link);
483
+ const preview = await (window.require('WAWebLinkPreviewChatAction')).getLinkPreview(link);
355
484
  preview.preview = true;
356
485
  preview.subtype = 'url';
357
486
  options = { ...options, ...preview };
@@ -364,15 +493,15 @@ exports.LoadUtils = () => {
364
493
  ...extraOptions
365
494
  };
366
495
 
367
- await window.Store.EditMessage.sendMessageEdit(msg, content, internalOptions);
368
- return window.Store.Msg.get(msg.id._serialized);
496
+ await (window.require('WAWebSendMessageEditAction')).sendMessageEdit(msg, content, internalOptions);
497
+ return (window.require('WAWebCollections')).Msg.get(msg.id._serialized);
369
498
  };
370
499
 
371
500
  window.WWebJS.toStickerData = async (mediaInfo) => {
372
501
  if (mediaInfo.mimetype == 'image/webp') return mediaInfo;
373
502
 
374
503
  const file = window.WWebJS.mediaInfoToFile(mediaInfo);
375
- const webpSticker = await window.Store.StickerTools.toWebpSticker(file);
504
+ const webpSticker = await (window.require('WAWebImageUtils')).toWebpSticker(file);
376
505
  const webpBuffer = await webpSticker.arrayBuffer();
377
506
  const data = window.WWebJS.arrayBufferToBase64(webpBuffer);
378
507
 
@@ -390,11 +519,14 @@ exports.LoadUtils = () => {
390
519
  let mediaKey = await window.WWebJS.generateHash(32);
391
520
 
392
521
  const controller = new AbortController();
393
- const uploadedInfo = await window.Store.UploadUtils.encryptAndUpload({
522
+ const uploadedInfo = await (window.require('WAWebUploadManager')).encryptAndUpload({
394
523
  blob: file,
395
524
  type: 'sticker',
396
525
  signal: controller.signal,
397
- mediaKey
526
+ mediaKey,
527
+ uploadQpl: window.require('WAWebStartMediaUploadQpl').startMediaUploadQpl({
528
+ entryPoint: 'MediaUpload'
529
+ }),
398
530
  });
399
531
 
400
532
  const stickerInfo = {
@@ -410,9 +542,10 @@ exports.LoadUtils = () => {
410
542
  return stickerInfo;
411
543
  };
412
544
 
413
- window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel }) => {
545
+ window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel, sendToStatus }) => {
414
546
  const file = window.WWebJS.mediaInfoToFile(mediaInfo);
415
- const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);
547
+ const OpaqueData = window.require('WAWebMediaOpaqueData');
548
+ const opaqueData = await OpaqueData.createFromData(file, mediaInfo.mimetype);
416
549
  const mediaParams = {
417
550
  asSticker: forceSticker,
418
551
  asGif: forceGif,
@@ -424,10 +557,10 @@ exports.LoadUtils = () => {
424
557
  mediaParams.maxDimension = 2560;
425
558
  }
426
559
 
427
- const mediaPrep = window.Store.MediaPrep.prepRawMedia(opaqueData, mediaParams);
560
+ const mediaPrep = window.require('WAWebPrepRawMedia').prepRawMedia(opaqueData, mediaParams);
428
561
  const mediaData = await mediaPrep.waitForPrep();
429
- const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
430
- const mediaType = window.Store.MediaTypes.msgToMediaType({
562
+ const mediaObject = window.require('WAWebMediaStorage').getOrCreateMediaObject(mediaData.filehash);
563
+ const mediaType = window.require('WAWebMmsMediaTypes').msgToMediaType({
431
564
  type: mediaData.type,
432
565
  isGif: mediaData.isGif,
433
566
  isNewsletter: sendToChannel,
@@ -437,14 +570,14 @@ exports.LoadUtils = () => {
437
570
  throw new Error('media-fault: sendToChat filehash undefined');
438
571
  }
439
572
 
440
- if (forceVoice && mediaData.type === 'ptt') {
573
+ if ((forceVoice && mediaData.type === 'ptt') || (sendToStatus && mediaData.type === 'audio')) {
441
574
  const waveform = mediaObject.contentInfo.waveform;
442
575
  mediaData.waveform =
443
576
  waveform || await window.WWebJS.generateWaveform(file);
444
577
  }
445
578
 
446
- if (!(mediaData.mediaBlob instanceof window.Store.OpaqueData)) {
447
- mediaData.mediaBlob = await window.Store.OpaqueData.createFromData(
579
+ if (!(mediaData.mediaBlob instanceof OpaqueData)) {
580
+ mediaData.mediaBlob = await OpaqueData.createFromData(
448
581
  mediaData.mediaBlob,
449
582
  mediaData.mediaBlob.type
450
583
  );
@@ -454,24 +587,25 @@ exports.LoadUtils = () => {
454
587
  mediaObject.consolidate(mediaData.toJSON());
455
588
 
456
589
  mediaData.mediaBlob.autorelease();
457
- const shouldUseMediaCache = window.Store.MediaDataUtils.shouldUseMediaCache(
458
- window.Store.MediaTypes.castToV4(mediaObject.type)
590
+ const shouldUseMediaCache = (window.require('WAWebMediaDataUtils')).shouldUseMediaCache(
591
+ window.require('WAWebMmsMediaTypes').castToV4(mediaObject.type)
459
592
  );
460
- if (shouldUseMediaCache && mediaData.mediaBlob instanceof window.Store.OpaqueData) {
593
+ if (shouldUseMediaCache && mediaData.mediaBlob instanceof OpaqueData) {
461
594
  const formData = mediaData.mediaBlob.formData();
462
- window.Store.BlobCache.InMemoryMediaBlobCache.put(mediaObject.filehash, formData);
595
+ (window.require('WAWebMediaInMemoryBlobCache')).InMemoryMediaBlobCache.put(mediaObject.filehash, formData);
463
596
  }
464
597
 
465
598
  const dataToUpload = {
466
599
  mimetype: mediaData.mimetype,
467
600
  mediaObject,
468
601
  mediaType,
469
- ...(sendToChannel ? { calculateToken: window.Store.SendChannelMessage.getRandomFilehash } : {})
602
+ ...(sendToChannel ? { calculateToken: window.require('WAMediaCalculateFilehash').getRandomFilehash } : {})
470
603
  };
471
604
 
605
+ const { uploadMedia, uploadUnencryptedMedia } = window.require('WAWebMediaMmsV4Upload');
472
606
  const uploadedMedia = !sendToChannel
473
- ? await window.Store.MediaUpload.uploadMedia(dataToUpload)
474
- : await window.Store.MediaUpload.uploadUnencryptedMedia(dataToUpload);
607
+ ? await uploadMedia(dataToUpload)
608
+ : await uploadUnencryptedMedia(dataToUpload);
475
609
 
476
610
  const mediaEntry = uploadedMedia.mediaEntry;
477
611
  if (!mediaEntry) {
@@ -499,9 +633,11 @@ exports.LoadUtils = () => {
499
633
  window.WWebJS.getMessageModel = (message) => {
500
634
  const msg = message.serialize();
501
635
 
636
+ const { findLinks } = window.require('WALinkify');
637
+
502
638
  msg.isEphemeral = message.isEphemeral;
503
639
  msg.isStatusV3 = message.isStatusV3;
504
- msg.links = (window.Store.Validators.findLinks(message.mediaObject ? message.caption : message.body)).map((link) => ({
640
+ msg.links = findLinks(message.mediaObject ? message.caption : message.body).map((link) => ({
505
641
  link: link.href,
506
642
  isSuspicious: Boolean(link.suspiciousCharacters && link.suspiciousCharacters.size)
507
643
  }));
@@ -527,21 +663,21 @@ exports.LoadUtils = () => {
527
663
 
528
664
  window.WWebJS.getChat = async (chatId, { getAsModel = true } = {}) => {
529
665
  const isChannel = /@\w*newsletter\b/.test(chatId);
530
- const chatWid = window.Store.WidFactory.createWid(chatId);
666
+ const chatWid = window.require('WAWebWidFactory').createWid(chatId);
531
667
  let chat;
532
668
 
533
669
  if (isChannel) {
534
670
  try {
535
- chat = window.Store.NewsletterCollection.get(chatId);
671
+ chat = (window.require('WAWebCollections')).WAWebNewsletterCollection.get(chatId);
536
672
  if (!chat) {
537
- await window.Store.ChannelUtils.loadNewsletterPreviewChat(chatId);
538
- chat = await window.Store.NewsletterCollection.find(chatWid);
673
+ await (window.require('WAWebLoadNewsletterPreviewChatAction')).loadNewsletterPreviewChat(chatId);
674
+ chat = await (window.require('WAWebCollections')).WAWebNewsletterCollection.find(chatWid);
539
675
  }
540
676
  } catch (err) {
541
677
  chat = null;
542
678
  }
543
679
  } else {
544
- chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat;
680
+ chat = (window.require('WAWebCollections')).Chat.get(chatWid) || (await (window.require('WAWebFindChatAction')).findOrCreateLatestChat(chatWid))?.chat;
545
681
  }
546
682
 
547
683
  return getAsModel && chat
@@ -550,10 +686,11 @@ exports.LoadUtils = () => {
550
686
  };
551
687
 
552
688
  window.WWebJS.getChannelMetadata = async (inviteCode) => {
689
+ const role = (window.require('WAWebNewsletterModelUtils')).getRoleByIdentifier(inviteCode);
553
690
  const response =
554
- await window.Store.ChannelUtils.queryNewsletterMetadataByInviteCode(
691
+ await (window.require('WAWebNewsletterMetadataQueryJob')).queryNewsletterMetadataByInviteCode(
555
692
  inviteCode,
556
- window.Store.ChannelUtils.getRoleByIdentifier(inviteCode)
693
+ role
557
694
  );
558
695
 
559
696
  const picUrl = response.newsletterPictureMetadataMixin?.picture[0]?.queryPictureDirectPathOrEmptyResponseMixinGroup.value.directPath;
@@ -570,7 +707,7 @@ exports.LoadUtils = () => {
570
707
  updatedAtTs: response.newsletterDescriptionMetadataMixin.descriptionQueryDescriptionResponseMixin.updateTime
571
708
  },
572
709
  inviteLink: `https://whatsapp.com/channel/${response.newsletterInviteLinkMetadataMixin.inviteCode}`,
573
- membershipType: window.Store.ChannelUtils.getRoleByIdentifier(inviteCode),
710
+ membershipType: role,
574
711
  stateType: response.newsletterStateMetadataMixin.stateType,
575
712
  pictureUrl: picUrl ? `https://pps.whatsapp.net${picUrl}` : null,
576
713
  subscribersCount: response.newsletterSubscribersMetadataMixin.subscribersCount,
@@ -579,13 +716,13 @@ exports.LoadUtils = () => {
579
716
  };
580
717
 
581
718
  window.WWebJS.getChats = async () => {
582
- const chats = window.Store.Chat.getModelsArray();
719
+ const chats = (window.require('WAWebCollections')).Chat.getModelsArray();
583
720
  const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat));
584
721
  return await Promise.all(chatPromises);
585
722
  };
586
723
 
587
724
  window.WWebJS.getChannels = async () => {
588
- const channels = window.Store.NewsletterCollection.getModelsArray();
725
+ const channels = (window.require('WAWebCollections')).WAWebNewsletterCollection.getModelsArray();
589
726
  const channelPromises = channels?.map((channel) => window.WWebJS.getChatModel(channel, { isChannel: true }));
590
727
  return await Promise.all(channelPromises);
591
728
  };
@@ -597,15 +734,16 @@ exports.LoadUtils = () => {
597
734
  model.isGroup = false;
598
735
  model.isMuted = chat.mute?.expiration !== 0;
599
736
  if (isChannel) {
600
- model.isChannel = window.Store.ChatGetters.getIsNewsletter(chat);
737
+ model.isChannel = (window.require('WAWebChatGetters')).getIsNewsletter(chat);
601
738
  } else {
602
739
  model.formattedTitle = chat.formattedTitle;
603
740
  }
604
741
 
605
742
  if (chat.groupMetadata) {
606
743
  model.isGroup = true;
607
- const chatWid = window.Store.WidFactory.createWid(chat.id._serialized);
608
- await window.Store.GroupMetadata.update(chatWid);
744
+ const chatWid = window.require('WAWebWidFactory').createWid(chat.id._serialized);
745
+ const groupMetadata = (window.require('WAWebCollections')).GroupMetadata || (window.require('WAWebCollections')).WAWebGroupMetadataCollection;
746
+ await groupMetadata.update(chatWid);
609
747
  chat.groupMetadata.participants._models
610
748
  .filter(x => x.id?._serialized?.endsWith('@lid'))
611
749
  .forEach(x => x.contact?.phoneNumber && (x.id = x.contact.phoneNumber));
@@ -614,7 +752,8 @@ exports.LoadUtils = () => {
614
752
  }
615
753
 
616
754
  if (chat.newsletterMetadata) {
617
- await window.Store.NewsletterMetadataCollection.update(chat.id);
755
+ const newsletterMetadata = (window.require('WAWebCollections')).NewsletterMetadataCollection || (window.require('WAWebCollections')).WAWebNewsletterMetadataCollection;
756
+ await newsletterMetadata.update(chat.id);
618
757
  model.channelMetadata = chat.newsletterMetadata.serialize();
619
758
  model.channelMetadata.createdAtTs = chat.newsletterMetadata.creationTime;
620
759
  }
@@ -622,7 +761,7 @@ exports.LoadUtils = () => {
622
761
  model.lastMessage = null;
623
762
  if (model.msgs && model.msgs.length) {
624
763
  const lastMessage = chat.lastReceivedKey
625
- ? window.Store.Msg.get(chat.lastReceivedKey._serialized) || (await window.Store.Msg.getMessagesById([chat.lastReceivedKey._serialized]))?.messages?.[0]
764
+ ? (window.require('WAWebCollections')).Msg.get(chat.lastReceivedKey._serialized) || (await (window.require('WAWebCollections')).Msg.getMessagesById([chat.lastReceivedKey._serialized]))?.messages?.[0]
626
765
  : null;
627
766
  lastMessage && (model.lastMessage = window.WWebJS.getMessageModel(lastMessage));
628
767
  }
@@ -641,38 +780,42 @@ exports.LoadUtils = () => {
641
780
  if (contact.businessProfile) {
642
781
  res.businessProfile = contact.businessProfile.serialize();
643
782
  }
644
-
645
- res.isMe = window.Store.ContactMethods.getIsMe(contact);
646
- res.isUser = window.Store.ContactMethods.getIsUser(contact);
647
- res.isGroup = window.Store.ContactMethods.getIsGroup(contact);
648
- res.isWAContact = window.Store.ContactMethods.getIsWAContact(contact);
649
- res.isMyContact = window.Store.ContactMethods.getIsMyContact(contact);
783
+
650
784
  res.isBlocked = contact.isContactBlocked;
651
- res.userid = window.Store.ContactMethods.getUserid(contact);
652
- res.isEnterprise = window.Store.ContactMethods.getIsEnterprise(contact);
653
- res.verifiedName = window.Store.ContactMethods.getVerifiedName(contact);
654
- res.verifiedLevel = window.Store.ContactMethods.getVerifiedLevel(contact);
655
- res.statusMute = window.Store.ContactMethods.getStatusMute(contact);
656
- res.name = window.Store.ContactMethods.getName(contact);
657
- res.shortName = window.Store.ContactMethods.getShortName(contact);
658
- res.pushname = window.Store.ContactMethods.getPushname(contact);
785
+
786
+ const ContactMethods = window.require('WAWebContactGetters');
787
+ res.isMe = ContactMethods.getIsMe(contact);
788
+ res.isUser = ContactMethods.getIsUser(contact);
789
+ res.isGroup = ContactMethods.getIsGroup(contact);
790
+ res.isWAContact = ContactMethods.getIsWAContact(contact);
791
+ res.userid = ContactMethods.getUserid(contact);
792
+ res.verifiedName = ContactMethods.getVerifiedName(contact);
793
+ res.verifiedLevel = ContactMethods.getVerifiedLevel(contact);
794
+ res.statusMute = ContactMethods.getStatusMute(contact);
795
+ res.name = ContactMethods.getName(contact);
796
+ res.shortName = ContactMethods.getShortName(contact);
797
+ res.pushname = ContactMethods.getPushname(contact);
798
+
799
+ const { getIsMyContact } = window.require('WAWebFrontendContactGetters');
800
+ res.isMyContact = getIsMyContact(contact);
801
+ res.isEnterprise = ContactMethods.getIsEnterprise(contact);
659
802
 
660
803
  return res;
661
804
  };
662
805
 
663
806
  window.WWebJS.getContact = async contactId => {
664
- const wid = window.Store.WidFactory.createWid(contactId);
665
- let contact = await window.Store.Contact.find(wid);
807
+ const wid = window.require('WAWebWidFactory').createWid(contactId);
808
+ let contact = await (window.require('WAWebCollections')).Contact.find(wid);
666
809
  if (contact.id._serialized.endsWith('@lid')) {
667
810
  contact.id = contact.phoneNumber;
668
811
  }
669
- const bizProfile = await window.Store.BusinessProfile.fetchBizProfile(wid);
812
+ const bizProfile = await (window.require('WAWebCollections')).BusinessProfile.fetchBizProfile(wid);
670
813
  bizProfile.profileOptions && (contact.businessProfile = bizProfile);
671
814
  return window.WWebJS.getContactModel(contact);
672
815
  };
673
816
 
674
817
  window.WWebJS.getContacts = () => {
675
- const contacts = window.Store.Contact.getModelsArray();
818
+ const contacts = (window.require('WAWebCollections')).Contact.getModelsArray();
676
819
  return contacts.map(contact => window.WWebJS.getContactModel(contact));
677
820
  };
678
821
 
@@ -767,7 +910,7 @@ exports.LoadUtils = () => {
767
910
  window.WWebJS.sendClearChat = async (chatId) => {
768
911
  let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
769
912
  if (chat !== undefined) {
770
- await window.Store.SendClear.sendClear(chat, false);
913
+ await (window.require('WAWebChatClearBridge')).sendClear(chat, false);
771
914
  return true;
772
915
  }
773
916
  return false;
@@ -776,24 +919,25 @@ exports.LoadUtils = () => {
776
919
  window.WWebJS.sendDeleteChat = async (chatId) => {
777
920
  let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
778
921
  if (chat !== undefined) {
779
- await window.Store.SendDelete.sendDelete(chat);
922
+ await (window.require('WAWebDeleteChatAction')).sendDelete(chat);
780
923
  return true;
781
924
  }
782
925
  return false;
783
926
  };
784
927
 
785
928
  window.WWebJS.sendChatstate = async (state, chatId) => {
786
- chatId = window.Store.WidFactory.createWid(chatId);
929
+ chatId = window.require('WAWebWidFactory').createWid(chatId);
787
930
 
931
+ const ChatState = window.require('WAWebChatStateBridge');
788
932
  switch (state) {
789
933
  case 'typing':
790
- await window.Store.ChatState.sendChatStateComposing(chatId);
934
+ await ChatState.sendChatStateComposing(chatId);
791
935
  break;
792
936
  case 'recording':
793
- await window.Store.ChatState.sendChatStateRecording(chatId);
937
+ await ChatState.sendChatStateRecording(chatId);
794
938
  break;
795
939
  case 'stop':
796
- await window.Store.ChatState.sendChatStatePaused(chatId);
940
+ await ChatState.sendChatStatePaused(chatId);
797
941
  break;
798
942
  default:
799
943
  throw 'Invalid chatstate';
@@ -810,12 +954,12 @@ exports.LoadUtils = () => {
810
954
  };
811
955
 
812
956
  window.WWebJS.getLabels = () => {
813
- const labels = window.Store.Label.getModelsArray();
957
+ const labels = (window.require('WAWebCollections')).Label.getModelsArray();
814
958
  return labels.map(label => window.WWebJS.getLabelModel(label));
815
959
  };
816
960
 
817
961
  window.WWebJS.getLabel = (labelId) => {
818
- const label = window.Store.Label.get(labelId);
962
+ const label = (window.require('WAWebCollections')).Label.get(labelId);
819
963
  return window.WWebJS.getLabelModel(label);
820
964
  };
821
965
 
@@ -825,13 +969,13 @@ exports.LoadUtils = () => {
825
969
  };
826
970
 
827
971
  window.WWebJS.getOrderDetail = async (orderId, token, chatId) => {
828
- const chatWid = window.Store.WidFactory.createWid(chatId);
829
- return window.Store.QueryOrder.queryOrder(chatWid, orderId, 80, 80, token);
972
+ const chatWid = window.require('WAWebWidFactory').createWid(chatId);
973
+ return (window.require('WAWebBizOrderBridge')).queryOrder(chatWid, orderId, 80, 80, token);
830
974
  };
831
975
 
832
976
  window.WWebJS.getProductMetadata = async (productId) => {
833
- let sellerId = window.Store.Conn.wid;
834
- let product = await window.Store.QueryProduct.queryProduct(sellerId, productId);
977
+ let sellerId = (window.require('WAWebConnModel').Conn).wid;
978
+ let product = await (window.require('WAWebBizProductCatalogBridge')).queryProduct(sellerId, productId);
835
979
  if (product && product.data) {
836
980
  return product.data;
837
981
  }
@@ -840,20 +984,20 @@ exports.LoadUtils = () => {
840
984
  };
841
985
 
842
986
  window.WWebJS.rejectCall = async (peerJid, id) => {
843
- let userId = window.Store.User.getMaybeMePnUser()._serialized;
987
+ let userId = (window.require('WAWebUserPrefsMeUser')).getMaybeMePnUser()._serialized;
844
988
 
845
- const stanza = window.Store.SocketWap.wap('call', {
846
- id: window.Store.SocketWap.generateId(),
989
+ const stanza = window.require('WAWap').wap('call', {
990
+ id: window.require('WAWap').generateId(),
847
991
  from: userId,
848
992
  to: peerJid,
849
993
  }, [
850
- window.Store.SocketWap.wap('reject', {
994
+ window.require('WAWap').wap('reject', {
851
995
  'call-id': id,
852
996
  'call-creator': peerJid,
853
997
  count: '0',
854
998
  })
855
999
  ]);
856
- await window.Store.Socket.deprecatedCastStanza(stanza);
1000
+ await (window.require('WADeprecatedSendIq')).deprecatedCastStanza(stanza);
857
1001
  };
858
1002
 
859
1003
  window.WWebJS.cropAndResizeImage = async (media, options = {}) => {
@@ -898,12 +1042,12 @@ exports.LoadUtils = () => {
898
1042
  const thumbnail = await window.WWebJS.cropAndResizeImage(media, { asDataUrl: true, mimetype: 'image/jpeg', size: 96 });
899
1043
  const profilePic = await window.WWebJS.cropAndResizeImage(media, { asDataUrl: true, mimetype: 'image/jpeg', size: 640 });
900
1044
 
901
- const chatWid = window.Store.WidFactory.createWid(chatId);
1045
+ const chatWid = window.require('WAWebWidFactory').createWid(chatId);
902
1046
  try {
903
- const collection = window.Store.ProfilePicThumb.get(chatId) || await window.Store.ProfilePicThumb.find(chatId);
1047
+ const collection = (window.require('WAWebCollections')).ProfilePicThumb.get(chatId) || await (window.require('WAWebCollections')).ProfilePicThumb.find(chatId);
904
1048
  if (!collection?.canSet()) return false;
905
1049
 
906
- const res = await window.Store.GroupUtils.sendSetPicture(chatWid, thumbnail, profilePic);
1050
+ const res = await (window.require('WAWebContactProfilePicThumbBridge')).sendSetPicture(chatWid, thumbnail, profilePic);
907
1051
  return res ? res.status === 200 : false;
908
1052
  } catch (err) {
909
1053
  if (err.name === 'ServerStatusCodeError') return false;
@@ -912,12 +1056,12 @@ exports.LoadUtils = () => {
912
1056
  };
913
1057
 
914
1058
  window.WWebJS.deletePicture = async (chatid) => {
915
- const chatWid = window.Store.WidFactory.createWid(chatid);
1059
+ const chatWid = window.require('WAWebWidFactory').createWid(chatid);
916
1060
  try {
917
- const collection = window.Store.ProfilePicThumb.get(chatid);
1061
+ const collection = (window.require('WAWebCollections')).ProfilePicThumb.get(chatid);
918
1062
  if (!collection.canDelete()) return;
919
1063
 
920
- const res = await window.Store.GroupUtils.requestDeletePicture(chatWid);
1064
+ const res = await (window.require('WAWebContactProfilePicThumbBridge')).requestDeletePicture(chatWid);
921
1065
  return res ? res.status === 200 : false;
922
1066
  } catch (err) {
923
1067
  if(err.name === 'ServerStatusCodeError') return false;
@@ -926,7 +1070,7 @@ exports.LoadUtils = () => {
926
1070
  };
927
1071
 
928
1072
  window.WWebJS.getProfilePicThumbToBase64 = async (chatWid) => {
929
- const profilePicCollection = await window.Store.ProfilePicThumb.find(chatWid);
1073
+ const profilePicCollection = await (window.require('WAWebCollections')).ProfilePicThumb.find(chatWid);
930
1074
 
931
1075
  const _readImageAsBase64 = (imageBlob) => {
932
1076
  return new Promise((resolve) => {
@@ -960,10 +1104,10 @@ exports.LoadUtils = () => {
960
1104
  };
961
1105
 
962
1106
  window.WWebJS.getAddParticipantsRpcResult = async (groupWid, participantWid) => {
963
- const iqTo = window.Store.WidToJid.widToGroupJid(groupWid);
1107
+ const iqTo = window.require('WAWebWidToJid').widToGroupJid(groupWid);
964
1108
 
965
1109
  const participantArgs = [{
966
- participantJid: window.Store.WidToJid.widToUserJid(participantWid)
1110
+ participantJid: window.require('WAWebWidToJid').widToUserJid(participantWid)
967
1111
  }];
968
1112
 
969
1113
  let rpcResult, resultArgs;
@@ -975,7 +1119,7 @@ exports.LoadUtils = () => {
975
1119
  };
976
1120
 
977
1121
  try {
978
- rpcResult = await window.Store.GroupParticipants.sendAddParticipantsRPC({ participantArgs, iqTo });
1122
+ rpcResult = await (window.require('WASmaxGroupsAddParticipantsRPC')).sendAddParticipantsRPC({ participantArgs, iqTo });
979
1123
  resultArgs = rpcResult.value.addParticipant[0]
980
1124
  .addParticipantsParticipantAddedOrNonRegisteredWaUserParticipantErrorLidResponseMixinGroup
981
1125
  .value
@@ -1007,20 +1151,20 @@ exports.LoadUtils = () => {
1007
1151
  };
1008
1152
 
1009
1153
  window.WWebJS.membershipRequestAction = async (groupId, action, requesterIds, sleep) => {
1010
- const groupWid = window.Store.WidFactory.createWid(groupId);
1011
- const group = await window.Store.Chat.find(groupWid);
1154
+ const groupWid = window.require('WAWebWidFactory').createWid(groupId);
1155
+ const group = await (window.require('WAWebCollections')).Chat.find(groupWid);
1012
1156
  const toApprove = action === 'Approve';
1013
1157
  let membershipRequests;
1014
1158
  let response;
1015
1159
  let result = [];
1016
1160
 
1017
- await window.Store.GroupQueryAndUpdate({ id: groupId });
1161
+ await (window.require('WAWebGroupQueryJob')).queryAndUpdateGroupMetadataById({ id: groupId });
1018
1162
 
1019
1163
  if (!requesterIds?.length) {
1020
1164
  membershipRequests = group.groupMetadata.membershipApprovalRequests._models.map(({ id }) => id);
1021
1165
  } else {
1022
1166
  !Array.isArray(requesterIds) && (requesterIds = [requesterIds]);
1023
- membershipRequests = requesterIds.map(r => window.Store.WidFactory.createWid(r));
1167
+ membershipRequests = requesterIds.map(r => window.require('WAWebWidFactory').createWid(r));
1024
1168
  }
1025
1169
 
1026
1170
  if (!membershipRequests.length) return [];
@@ -1028,12 +1172,12 @@ exports.LoadUtils = () => {
1028
1172
  const participantArgs = membershipRequests.map(m => ({
1029
1173
  participantArgs: [
1030
1174
  {
1031
- participantJid: window.Store.WidToJid.widToUserJid(m)
1175
+ participantJid: window.require('WAWebWidToJid').widToUserJid(m)
1032
1176
  }
1033
1177
  ]
1034
1178
  }));
1035
1179
 
1036
- const groupJid = window.Store.WidToJid.widToGroupJid(groupWid);
1180
+ const groupJid = window.require('WAWebWidToJid').widToGroupJid(groupWid);
1037
1181
 
1038
1182
  const _getSleepTime = (sleep) => {
1039
1183
  if (!Array.isArray(sleep) || (sleep.length === 2 && sleep[0] === sleep[1])) {
@@ -1060,7 +1204,7 @@ exports.LoadUtils = () => {
1060
1204
 
1061
1205
  try {
1062
1206
  for (const participant of participantArgs) {
1063
- response = await window.Store.MembershipRequestUtils.sendMembershipRequestsActionRPC({
1207
+ response = await (window.require('WASmaxGroupsMembershipRequestsActionRPC')).sendMembershipRequestsActionRPC({
1064
1208
  iqTo: groupJid,
1065
1209
  [toApprove ? 'approveArgs' : 'rejectArgs']: participant
1066
1210
  });
@@ -1075,7 +1219,7 @@ exports.LoadUtils = () => {
1075
1219
  ? value.participant[0].membershipRequestsActionAcceptParticipantMixins?.value.error
1076
1220
  : value.participant[0].membershipRequestsActionRejectParticipantMixins?.value.error;
1077
1221
  return {
1078
- requesterId: window.Store.WidFactory.createWid(p.jid)._serialized,
1222
+ requesterId: window.require('WAWebWidFactory').createWid(p.jid)._serialized,
1079
1223
  ...(error
1080
1224
  ? { error: +error, message: membReqResCodes[error] || membReqResCodes.default }
1081
1225
  : { message: `${toApprove ? 'Approved' : 'Rejected'} successfully` })
@@ -1085,7 +1229,7 @@ exports.LoadUtils = () => {
1085
1229
  }
1086
1230
  } else {
1087
1231
  result.push({
1088
- requesterId: window.Store.JidToWid.userJidToUserWid(participant.participantArgs[0].participantJid)._serialized,
1232
+ requesterId: window.require('WAWebJidToWid').userJidToUserWid(participant.participantArgs[0].participantJid)._serialized,
1089
1233
  message: 'ServerStatusCodeError'
1090
1234
  });
1091
1235
  }
@@ -1109,9 +1253,9 @@ exports.LoadUtils = () => {
1109
1253
 
1110
1254
  try {
1111
1255
  if (action === 'Subscribe') {
1112
- await window.Store.ChannelUtils.subscribeToNewsletterAction(channel, options);
1256
+ await (window.require('WAWebNewsletterSubscribeAction')).subscribeToNewsletterAction(channel, options);
1113
1257
  } else if (action === 'Unsubscribe') {
1114
- await window.Store.ChannelUtils.unsubscribeFromNewsletterAction(channel, options);
1258
+ await (window.require('WAWebNewsletterUnsubscribeAction')).unsubscribeFromNewsletterAction(channel, options);
1115
1259
  } else return false;
1116
1260
  return true;
1117
1261
  } catch (err) {
@@ -1121,7 +1265,7 @@ exports.LoadUtils = () => {
1121
1265
  };
1122
1266
 
1123
1267
  window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
1124
- const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
1268
+ const message = (window.require('WAWebCollections')).Msg.get(msgId) || (await (window.require('WAWebCollections')).Msg.getMessagesById([msgId]))?.messages?.[0];
1125
1269
  if (!message) return false;
1126
1270
 
1127
1271
  if (typeof duration !== 'number') return false;
@@ -1129,7 +1273,7 @@ exports.LoadUtils = () => {
1129
1273
  const originalFunction = window.require('WAWebPinMsgConstants').getPinExpiryDuration;
1130
1274
  window.require('WAWebPinMsgConstants').getPinExpiryDuration = () => duration;
1131
1275
 
1132
- const response = await window.Store.PinnedMsgUtils.sendPinInChatMsg(message, action, duration);
1276
+ const response = await (window.require('WAWebSendPinMessageAction')).sendPinInChatMsg(message, action, duration);
1133
1277
 
1134
1278
  window.require('WAWebPinMsgConstants').getPinExpiryDuration = originalFunction;
1135
1279
 
@@ -1143,29 +1287,45 @@ exports.LoadUtils = () => {
1143
1287
  };
1144
1288
 
1145
1289
  window.WWebJS.getAllStatuses = () => {
1146
- const statuses = window.Store.Status.getModelsArray();
1290
+ const statuses = (window.require('WAWebCollections')).Status.getModelsArray();
1147
1291
  return statuses.map(status => window.WWebJS.getStatusModel(status));
1148
1292
  };
1149
1293
 
1150
1294
  window.WWebJS.enforceLidAndPnRetrieval = async (userId) => {
1151
- const wid = window.Store.WidFactory.createWid(userId);
1295
+ const wid = window.require('WAWebWidFactory').createWid(userId);
1152
1296
  const isLid = wid.server === 'lid';
1153
1297
 
1154
- let lid = isLid ? wid : window.Store.LidUtils.getCurrentLid(wid);
1155
- let phone = isLid ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
1298
+ let lid = isLid ? wid : window.require('WAWebApiContact').getCurrentLid(wid);
1299
+ let phone = isLid ? window.require('WAWebApiContact').getPhoneNumber(wid) : wid;
1156
1300
 
1157
1301
  if (!isLid && !lid) {
1158
- const queryResult = await window.Store.QueryExist(wid);
1302
+ const queryResult = await (window.require('WAWebQueryExistsJob').queryWidExists)(wid);
1159
1303
  if (!queryResult?.wid) return {};
1160
- lid = window.Store.LidUtils.getCurrentLid(wid);
1304
+ lid = window.require('WAWebApiContact').getCurrentLid(wid);
1161
1305
  }
1162
1306
 
1163
1307
  if (isLid && !phone) {
1164
- const queryResult = await window.Store.QueryExist(wid);
1308
+ const queryResult = await (window.require('WAWebQueryExistsJob').queryWidExists)(wid);
1165
1309
  if (!queryResult?.wid) return {};
1166
- phone = window.Store.LidUtils.getPhoneNumber(wid);
1310
+ phone = window.require('WAWebApiContact').getPhoneNumber(wid);
1167
1311
  }
1168
1312
 
1169
1313
  return { lid, phone };
1170
1314
  };
1315
+
1316
+ window.WWebJS.assertColor = (hex) => {
1317
+ let color;
1318
+ if (typeof hex === 'number') {
1319
+ color = hex > 0 ? hex : 0xffffffff + parseInt(hex) + 1;
1320
+ } else if (typeof hex === 'string') {
1321
+ let number = hex.trim().replace('#', '');
1322
+ if (number.length <= 6) {
1323
+ number = 'FF' + number.padStart(6, '0');
1324
+ }
1325
+ color = parseInt(number, 16);
1326
+ } else {
1327
+ throw 'Invalid hex color';
1328
+ }
1329
+ return color;
1330
+ };
1171
1331
  };