@another-trial/whatsapp-web.js 1.34.1 → 1.34.5-alpha.3
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.
- package/.env.example +2 -2
- package/CODE_OF_CONDUCT.md +133 -133
- package/LICENSE +201 -201
- package/README.md +155 -185
- package/example.js +706 -690
- package/index.d.ts +2259 -2202
- package/index.js +35 -35
- package/package.json +59 -59
- package/shell.js +36 -36
- package/src/Client.js +2533 -2361
- package/src/authStrategies/BaseAuthStrategy.js +26 -26
- package/src/authStrategies/LocalAuth.js +58 -58
- package/src/authStrategies/NoAuth.js +11 -11
- package/src/authStrategies/RemoteAuth.js +210 -210
- package/src/factories/ChatFactory.js +21 -21
- package/src/factories/ContactFactory.js +15 -15
- package/src/structures/Base.js +21 -21
- package/src/structures/Broadcast.js +69 -69
- package/src/structures/BusinessContact.js +20 -20
- package/src/structures/Buttons.js +81 -81
- package/src/structures/Call.js +75 -75
- package/src/structures/Channel.js +382 -382
- package/src/structures/Chat.js +329 -299
- package/src/structures/ClientInfo.js +70 -70
- package/src/structures/Contact.js +215 -208
- package/src/structures/GroupChat.js +485 -485
- package/src/structures/GroupNotification.js +104 -104
- package/src/structures/Label.js +49 -49
- package/src/structures/List.js +79 -79
- package/src/structures/Location.js +61 -61
- package/src/structures/Message.js +787 -747
- package/src/structures/MessageMedia.js +111 -111
- package/src/structures/Order.js +51 -51
- package/src/structures/Payment.js +79 -79
- package/src/structures/Poll.js +44 -44
- package/src/structures/PollVote.js +75 -75
- package/src/structures/PrivateChat.js +12 -12
- package/src/structures/PrivateContact.js +12 -12
- package/src/structures/Product.js +67 -67
- package/src/structures/ProductMetadata.js +24 -24
- package/src/structures/Reaction.js +68 -68
- package/src/structures/ScheduledEvent.js +71 -71
- package/src/structures/index.js +27 -27
- package/src/util/Constants.js +186 -183
- package/src/util/Injected/AuthStore/AuthStore.js +16 -16
- package/src/util/Injected/AuthStore/LegacyAuthStore.js +21 -21
- package/src/util/Injected/LegacyStore.js +145 -145
- package/src/util/Injected/Store.js +263 -233
- package/src/util/Injected/Utils.js +1221 -1169
- package/src/util/InterfaceController.js +126 -126
- package/src/util/Puppeteer.js +23 -23
- package/src/util/Util.js +186 -186
- package/src/webCache/LocalWebCache.js +40 -40
- package/src/webCache/RemoteWebCache.js +39 -39
- package/src/webCache/WebCache.js +13 -13
- package/src/webCache/WebCacheFactory.js +19 -19
|
@@ -1,1169 +1,1221 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.LoadUtils = () => {
|
|
4
|
-
window.WWebJS = {};
|
|
5
|
-
|
|
6
|
-
window.WWebJS.forwardMessage = async (chatId, msgId) => {
|
|
7
|
-
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
8
|
-
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
9
|
-
return window.Store.ForwardUtils.forwardMessages(chat, [msg], true, true);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
window.WWebJS.sendSeen = async (chatId) => {
|
|
13
|
-
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
14
|
-
if (chat) {
|
|
15
|
-
window.Store.WAWebStreamModel.Stream.markAvailable();
|
|
16
|
-
await window.Store.SendSeen.sendSeen(chat);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
options.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
participant = window.Store.WidFactory.asUserWidOrThrow(from);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const newMsgKey = new window.Store.MsgKey({
|
|
256
|
-
from: from,
|
|
257
|
-
to: chat.id,
|
|
258
|
-
id: newId,
|
|
259
|
-
participant: participant,
|
|
260
|
-
selfDir: 'out',
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
const extraOptions = options.extraOptions || {};
|
|
264
|
-
delete options.extraOptions;
|
|
265
|
-
|
|
266
|
-
const ephemeralFields = window.Store.EphemeralFields.getEphemeralFields(chat);
|
|
267
|
-
|
|
268
|
-
const message = {
|
|
269
|
-
...options,
|
|
270
|
-
id: newMsgKey,
|
|
271
|
-
ack: 0,
|
|
272
|
-
body: content,
|
|
273
|
-
from:
|
|
274
|
-
to: chat.id,
|
|
275
|
-
local: true,
|
|
276
|
-
self: 'out',
|
|
277
|
-
t: parseInt(new Date().getTime() / 1000),
|
|
278
|
-
isNewMsg: true,
|
|
279
|
-
type: 'chat',
|
|
280
|
-
...ephemeralFields,
|
|
281
|
-
...mediaOptions,
|
|
282
|
-
...(mediaOptions.toJSON ? mediaOptions.toJSON() : {}),
|
|
283
|
-
...quotedMsgOptions,
|
|
284
|
-
...locationOptions,
|
|
285
|
-
...
|
|
286
|
-
...eventOptions,
|
|
287
|
-
...vcardOptions,
|
|
288
|
-
...buttonOptions,
|
|
289
|
-
...listOptions,
|
|
290
|
-
...botOptions,
|
|
291
|
-
...extraOptions
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
// Bot's won't reply if canonicalUrl is set (linking)
|
|
295
|
-
if (botOptions) {
|
|
296
|
-
delete message.canonicalUrl;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (isChannel) {
|
|
300
|
-
const msg = new window.Store.Msg.modelClass(message);
|
|
301
|
-
const msgDataFromMsgModel = window.Store.SendChannelMessage.msgDataFromMsgModel(msg);
|
|
302
|
-
const isMedia = Object.keys(mediaOptions).length > 0;
|
|
303
|
-
await window.Store.SendChannelMessage.addNewsletterMsgsRecords([msgDataFromMsgModel]);
|
|
304
|
-
chat.msgs.add(msg);
|
|
305
|
-
chat.t = msg.t;
|
|
306
|
-
|
|
307
|
-
const sendChannelMsgResponse = await window.Store.SendChannelMessage.sendNewsletterMessageJob({
|
|
308
|
-
msg: msg,
|
|
309
|
-
type: message.type === 'chat' ? 'text' : isMedia ? 'media' : 'pollCreation',
|
|
310
|
-
newsletterJid: chat.id.toJid(),
|
|
311
|
-
...(isMedia
|
|
312
|
-
? {
|
|
313
|
-
mediaMetadata: msg.avParams(),
|
|
314
|
-
mediaHandle: isMedia ? mediaOptions.mediaHandle : null,
|
|
315
|
-
}
|
|
316
|
-
: {}
|
|
317
|
-
)
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
if (sendChannelMsgResponse.success) {
|
|
321
|
-
msg.t = sendChannelMsgResponse.ack.t;
|
|
322
|
-
msg.serverId = sendChannelMsgResponse.serverId;
|
|
323
|
-
}
|
|
324
|
-
msg.updateAck(1, true);
|
|
325
|
-
await window.Store.SendChannelMessage.updateNewsletterMsgRecord(msg);
|
|
326
|
-
return msg;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
let
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
return
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
window.WWebJS.
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
if (
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.LoadUtils = () => {
|
|
4
|
+
window.WWebJS = {};
|
|
5
|
+
|
|
6
|
+
window.WWebJS.forwardMessage = async (chatId, msgId) => {
|
|
7
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
8
|
+
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});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
window.WWebJS.sendSeen = async (chatId) => {
|
|
13
|
+
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
14
|
+
if (chat) {
|
|
15
|
+
window.Store.WAWebStreamModel.Stream.markAvailable();
|
|
16
|
+
await window.Store.SendSeen.sendSeen(chat);
|
|
17
|
+
window.Store.WAWebStreamModel.Stream.markUnavailable();
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
|
24
|
+
const isChannel = window.Store.ChatGetters.getIsNewsletter(chat);
|
|
25
|
+
const isStatus = window.Store.ChatGetters.getIsBroadcast(chat);
|
|
26
|
+
|
|
27
|
+
let mediaOptions = {};
|
|
28
|
+
if (options.media) {
|
|
29
|
+
mediaOptions = options.sendMediaAsSticker && !isChannel && !isStatus
|
|
30
|
+
? await window.WWebJS.processStickerData(options.media)
|
|
31
|
+
: await window.WWebJS.processMediaData(options.media, {
|
|
32
|
+
forceSticker: options.sendMediaAsSticker,
|
|
33
|
+
forceGif: options.sendVideoAsGif,
|
|
34
|
+
forceVoice: options.sendAudioAsVoice,
|
|
35
|
+
forceDocument: options.sendMediaAsDocument,
|
|
36
|
+
forceMediaHd: options.sendMediaAsHd,
|
|
37
|
+
sendToChannel: isChannel,
|
|
38
|
+
sendToStatus: isStatus
|
|
39
|
+
});
|
|
40
|
+
mediaOptions.caption = options.caption;
|
|
41
|
+
content = options.sendMediaAsSticker ? undefined : mediaOptions.preview;
|
|
42
|
+
mediaOptions.isViewOnce = options.isViewOnce;
|
|
43
|
+
delete options.media;
|
|
44
|
+
delete options.sendMediaAsSticker;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let quotedMsgOptions = {};
|
|
48
|
+
if (options.quotedMessageId) {
|
|
49
|
+
let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
|
|
50
|
+
!quotedMessage && (quotedMessage = (await window.Store.Msg.getMessagesById([options.quotedMessageId]))?.messages?.[0]);
|
|
51
|
+
if (quotedMessage) {
|
|
52
|
+
|
|
53
|
+
const canReply = window.Store.ReplyUtils
|
|
54
|
+
? window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe())
|
|
55
|
+
: quotedMessage.canReply();
|
|
56
|
+
|
|
57
|
+
if (canReply) {
|
|
58
|
+
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
if (!options.ignoreQuoteErrors) {
|
|
62
|
+
throw new Error('Could not get the quoted message.');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
delete options.ignoreQuoteErrors;
|
|
67
|
+
delete options.quotedMessageId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (options.mentionedJidList) {
|
|
71
|
+
options.mentionedJidList = options.mentionedJidList.map((id) => window.Store.WidFactory.createWid(id));
|
|
72
|
+
options.mentionedJidList = options.mentionedJidList.filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (options.groupMentions) {
|
|
76
|
+
options.groupMentions = options.groupMentions.map((e) => ({
|
|
77
|
+
groupSubject: e.subject,
|
|
78
|
+
groupJid: window.Store.WidFactory.createWid(e.id)
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let locationOptions = {};
|
|
83
|
+
if (options.location) {
|
|
84
|
+
let { latitude, longitude, description, url } = options.location;
|
|
85
|
+
url = window.Store.Validators.findLink(url)?.href;
|
|
86
|
+
url && !description && (description = url);
|
|
87
|
+
locationOptions = {
|
|
88
|
+
type: 'location',
|
|
89
|
+
loc: description,
|
|
90
|
+
lat: latitude,
|
|
91
|
+
lng: longitude,
|
|
92
|
+
clientUrl: url
|
|
93
|
+
};
|
|
94
|
+
delete options.location;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let pollOptions = {};
|
|
98
|
+
if (options.poll) {
|
|
99
|
+
const { pollName, pollOptions: _pollOptions } = options.poll;
|
|
100
|
+
const { allowMultipleAnswers, messageSecret } = options.poll.options;
|
|
101
|
+
pollOptions = {
|
|
102
|
+
kind: 'pollCreation',
|
|
103
|
+
type: 'poll_creation',
|
|
104
|
+
pollName: pollName,
|
|
105
|
+
pollOptions: _pollOptions,
|
|
106
|
+
pollSelectableOptionsCount: allowMultipleAnswers ? 0 : 1,
|
|
107
|
+
messageSecret:
|
|
108
|
+
Array.isArray(messageSecret) && messageSecret.length === 32
|
|
109
|
+
? new Uint8Array(messageSecret)
|
|
110
|
+
: window.crypto.getRandomValues(new Uint8Array(32))
|
|
111
|
+
};
|
|
112
|
+
delete options.poll;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let eventOptions = {};
|
|
116
|
+
if (options.event) {
|
|
117
|
+
const { name, startTimeTs, eventSendOptions } = options.event;
|
|
118
|
+
const { messageSecret } = eventSendOptions;
|
|
119
|
+
eventOptions = {
|
|
120
|
+
type: 'event_creation',
|
|
121
|
+
eventName: name,
|
|
122
|
+
eventDescription: eventSendOptions.description,
|
|
123
|
+
eventStartTime: startTimeTs,
|
|
124
|
+
eventEndTime: eventSendOptions.endTimeTs,
|
|
125
|
+
eventLocation: eventSendOptions.location && {
|
|
126
|
+
degreesLatitude: 0,
|
|
127
|
+
degreesLongitude: 0,
|
|
128
|
+
name: eventSendOptions.location
|
|
129
|
+
},
|
|
130
|
+
eventJoinLink: eventSendOptions.callType === 'none' ? null : await window.Store.ScheduledEventMsgUtils.createEventCallLink(
|
|
131
|
+
startTimeTs,
|
|
132
|
+
eventSendOptions.callType
|
|
133
|
+
),
|
|
134
|
+
isEventCanceled: eventSendOptions.isEventCanceled,
|
|
135
|
+
messageSecret:
|
|
136
|
+
Array.isArray(messageSecret) && messageSecret.length === 32
|
|
137
|
+
? new Uint8Array(messageSecret)
|
|
138
|
+
: window.crypto.getRandomValues(new Uint8Array(32)),
|
|
139
|
+
};
|
|
140
|
+
delete options.event;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let vcardOptions = {};
|
|
144
|
+
if (options.contactCard) {
|
|
145
|
+
let contact = window.Store.Contact.get(options.contactCard);
|
|
146
|
+
vcardOptions = {
|
|
147
|
+
body: window.Store.VCard.vcardFromContactModel(contact).vcard,
|
|
148
|
+
type: 'vcard',
|
|
149
|
+
vcardFormattedName: contact.formattedName
|
|
150
|
+
};
|
|
151
|
+
delete options.contactCard;
|
|
152
|
+
} else if (options.contactCardList) {
|
|
153
|
+
let contacts = options.contactCardList.map(c => window.Store.Contact.get(c));
|
|
154
|
+
let vcards = contacts.map(c => window.Store.VCard.vcardFromContactModel(c));
|
|
155
|
+
vcardOptions = {
|
|
156
|
+
type: 'multi_vcard',
|
|
157
|
+
vcardList: vcards,
|
|
158
|
+
body: null
|
|
159
|
+
};
|
|
160
|
+
delete options.contactCardList;
|
|
161
|
+
} else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
|
|
162
|
+
delete options.parseVCards;
|
|
163
|
+
delete options.linkPreview;
|
|
164
|
+
try {
|
|
165
|
+
const parsed = window.Store.VCard.parseVcard(content);
|
|
166
|
+
if (parsed) {
|
|
167
|
+
vcardOptions = {
|
|
168
|
+
type: 'vcard',
|
|
169
|
+
vcardFormattedName: window.Store.VCard.vcardGetNameFromParsed(parsed)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
} catch (_) {
|
|
173
|
+
// not a vcard
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (options.linkPreview) {
|
|
178
|
+
delete options.linkPreview;
|
|
179
|
+
const link = window.Store.Validators.findLink(content);
|
|
180
|
+
if (link) {
|
|
181
|
+
let preview = await window.Store.LinkPreview.getLinkPreview(link);
|
|
182
|
+
if (preview && preview.data) {
|
|
183
|
+
preview = preview.data;
|
|
184
|
+
preview.preview = true;
|
|
185
|
+
preview.subtype = 'url';
|
|
186
|
+
options = {...options, ...preview};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let buttonOptions = {};
|
|
192
|
+
if (options.buttons) {
|
|
193
|
+
let caption;
|
|
194
|
+
if (options.buttons.type === 'chat') {
|
|
195
|
+
content = options.buttons.body;
|
|
196
|
+
caption = content;
|
|
197
|
+
} else {
|
|
198
|
+
caption = options.caption ? options.caption : ' '; //Caption can't be empty
|
|
199
|
+
}
|
|
200
|
+
buttonOptions = {
|
|
201
|
+
productHeaderImageRejected: false,
|
|
202
|
+
isFromTemplate: false,
|
|
203
|
+
isDynamicReplyButtonsMsg: true,
|
|
204
|
+
title: options.buttons.title ? options.buttons.title : undefined,
|
|
205
|
+
footer: options.buttons.footer ? options.buttons.footer : undefined,
|
|
206
|
+
dynamicReplyButtons: options.buttons.buttons,
|
|
207
|
+
replyButtons: options.buttons.buttons,
|
|
208
|
+
caption: caption
|
|
209
|
+
};
|
|
210
|
+
delete options.buttons;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let listOptions = {};
|
|
214
|
+
if (options.list) {
|
|
215
|
+
if (window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi') {
|
|
216
|
+
throw '[LT01] Whatsapp business can\'t send this yet';
|
|
217
|
+
}
|
|
218
|
+
listOptions = {
|
|
219
|
+
type: 'list',
|
|
220
|
+
footer: options.list.footer,
|
|
221
|
+
list: {
|
|
222
|
+
...options.list,
|
|
223
|
+
listType: 1
|
|
224
|
+
},
|
|
225
|
+
body: options.list.description
|
|
226
|
+
};
|
|
227
|
+
delete options.list;
|
|
228
|
+
delete listOptions.list.footer;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const botOptions = {};
|
|
232
|
+
if (options.invokedBotWid) {
|
|
233
|
+
botOptions.messageSecret = window.crypto.getRandomValues(new Uint8Array(32));
|
|
234
|
+
botOptions.botMessageSecret = await window.Store.BotSecret.genBotMsgSecretFromMsgSecret(botOptions.messageSecret);
|
|
235
|
+
botOptions.invokedBotWid = window.Store.WidFactory.createWid(options.invokedBotWid);
|
|
236
|
+
botOptions.botPersonaId = window.Store.BotProfiles.BotProfileCollection.get(options.invokedBotWid).personaId;
|
|
237
|
+
delete options.invokedBotWid;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const lidUser = window.Store.User.getMaybeMeLidUser();
|
|
241
|
+
const meUser = window.Store.User.getMaybeMePnUser();
|
|
242
|
+
const newId = await window.Store.MsgKey.newId();
|
|
243
|
+
let from = chat.id.isLid() ? lidUser : meUser;
|
|
244
|
+
let participant;
|
|
245
|
+
|
|
246
|
+
if (typeof chat.id?.isGroup === 'function' && chat.id.isGroup()) {
|
|
247
|
+
from = chat.groupMetadata && chat.groupMetadata.isLidAddressingMode ? lidUser : meUser;
|
|
248
|
+
participant = window.Store.WidFactory.asUserWidOrThrow(from);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (typeof chat.id?.isStatus === 'function' && chat.id.isStatus()) {
|
|
252
|
+
participant = window.Store.WidFactory.asUserWidOrThrow(from);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const newMsgKey = new window.Store.MsgKey({
|
|
256
|
+
from: from,
|
|
257
|
+
to: chat.id,
|
|
258
|
+
id: newId,
|
|
259
|
+
participant: participant,
|
|
260
|
+
selfDir: 'out',
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const extraOptions = options.extraOptions || {};
|
|
264
|
+
delete options.extraOptions;
|
|
265
|
+
|
|
266
|
+
const ephemeralFields = window.Store.EphemeralFields.getEphemeralFields(chat);
|
|
267
|
+
|
|
268
|
+
const message = {
|
|
269
|
+
...options,
|
|
270
|
+
id: newMsgKey,
|
|
271
|
+
ack: 0,
|
|
272
|
+
body: content,
|
|
273
|
+
from: from,
|
|
274
|
+
to: chat.id,
|
|
275
|
+
local: true,
|
|
276
|
+
self: 'out',
|
|
277
|
+
t: parseInt(new Date().getTime() / 1000),
|
|
278
|
+
isNewMsg: true,
|
|
279
|
+
type: 'chat',
|
|
280
|
+
...ephemeralFields,
|
|
281
|
+
...mediaOptions,
|
|
282
|
+
...(mediaOptions.toJSON ? mediaOptions.toJSON() : {}),
|
|
283
|
+
...quotedMsgOptions,
|
|
284
|
+
...locationOptions,
|
|
285
|
+
...pollOptions,
|
|
286
|
+
...eventOptions,
|
|
287
|
+
...vcardOptions,
|
|
288
|
+
...buttonOptions,
|
|
289
|
+
...listOptions,
|
|
290
|
+
...botOptions,
|
|
291
|
+
...extraOptions
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// Bot's won't reply if canonicalUrl is set (linking)
|
|
295
|
+
if (botOptions) {
|
|
296
|
+
delete message.canonicalUrl;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (isChannel) {
|
|
300
|
+
const msg = new window.Store.Msg.modelClass(message);
|
|
301
|
+
const msgDataFromMsgModel = window.Store.SendChannelMessage.msgDataFromMsgModel(msg);
|
|
302
|
+
const isMedia = Object.keys(mediaOptions).length > 0;
|
|
303
|
+
await window.Store.SendChannelMessage.addNewsletterMsgsRecords([msgDataFromMsgModel]);
|
|
304
|
+
chat.msgs.add(msg);
|
|
305
|
+
chat.t = msg.t;
|
|
306
|
+
|
|
307
|
+
const sendChannelMsgResponse = await window.Store.SendChannelMessage.sendNewsletterMessageJob({
|
|
308
|
+
msg: msg,
|
|
309
|
+
type: message.type === 'chat' ? 'text' : isMedia ? 'media' : 'pollCreation',
|
|
310
|
+
newsletterJid: chat.id.toJid(),
|
|
311
|
+
...(isMedia
|
|
312
|
+
? {
|
|
313
|
+
mediaMetadata: msg.avParams(),
|
|
314
|
+
mediaHandle: isMedia ? mediaOptions.mediaHandle : null,
|
|
315
|
+
}
|
|
316
|
+
: {}
|
|
317
|
+
)
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
if (sendChannelMsgResponse.success) {
|
|
321
|
+
msg.t = sendChannelMsgResponse.ack.t;
|
|
322
|
+
msg.serverId = sendChannelMsgResponse.serverId;
|
|
323
|
+
}
|
|
324
|
+
msg.updateAck(1, true);
|
|
325
|
+
await window.Store.SendChannelMessage.updateNewsletterMsgRecord(msg);
|
|
326
|
+
return msg;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (isStatus) {
|
|
330
|
+
const { backgroundColor, fontStyle } = extraOptions;
|
|
331
|
+
const isMedia = Object.keys(mediaOptions).length > 0;
|
|
332
|
+
const mediaUpdate = data => window.Store.MediaUpdate(data, mediaOptions);
|
|
333
|
+
const msg = new window.Store.Msg.modelClass({
|
|
334
|
+
...message,
|
|
335
|
+
author: participant ? participant : null,
|
|
336
|
+
messageSecret: window.crypto.getRandomValues(new Uint8Array(32)),
|
|
337
|
+
cannotBeRanked: window.Store.StatusUtils.canCheckStatusRankingPosterGating()
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// for text only
|
|
341
|
+
const statusOptions = {
|
|
342
|
+
color: backgroundColor && window.WWebJS.assertColor(backgroundColor) || 0xff7acca5,
|
|
343
|
+
font: fontStyle >= 0 && fontStyle <= 7 && fontStyle || 0,
|
|
344
|
+
text: msg.body
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
await window.Store.StatusUtils[
|
|
348
|
+
isMedia ?
|
|
349
|
+
'sendStatusMediaMsgAction' : 'sendStatusTextMsgAction'
|
|
350
|
+
](
|
|
351
|
+
...(
|
|
352
|
+
isMedia ?
|
|
353
|
+
[msg, mediaUpdate] : [statusOptions]
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
return msg;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const [msgPromise, sendMsgResultPromise] = window.Store.SendMessage.addAndSendMsgToChat(chat, message);
|
|
361
|
+
await msgPromise;
|
|
362
|
+
|
|
363
|
+
if (options.waitUntilMsgSent) await sendMsgResultPromise;
|
|
364
|
+
|
|
365
|
+
return window.Store.Msg.get(newMsgKey._serialized);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
window.WWebJS.editMessage = async (msg, content, options = {}) => {
|
|
369
|
+
const extraOptions = options.extraOptions || {};
|
|
370
|
+
delete options.extraOptions;
|
|
371
|
+
|
|
372
|
+
if (options.mentionedJidList) {
|
|
373
|
+
options.mentionedJidList = options.mentionedJidList.map((id) => window.Store.WidFactory.createWid(id));
|
|
374
|
+
options.mentionedJidList = options.mentionedJidList.filter(Boolean);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (options.groupMentions) {
|
|
378
|
+
options.groupMentions = options.groupMentions.map((e) => ({
|
|
379
|
+
groupSubject: e.subject,
|
|
380
|
+
groupJid: window.Store.WidFactory.createWid(e.id)
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (options.linkPreview) {
|
|
385
|
+
delete options.linkPreview;
|
|
386
|
+
const link = window.Store.Validators.findLink(content);
|
|
387
|
+
if (link) {
|
|
388
|
+
const preview = await window.Store.LinkPreview.getLinkPreview(link);
|
|
389
|
+
preview.preview = true;
|
|
390
|
+
preview.subtype = 'url';
|
|
391
|
+
options = { ...options, ...preview };
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
const internalOptions = {
|
|
397
|
+
...options,
|
|
398
|
+
...extraOptions
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
await window.Store.EditMessage.sendMessageEdit(msg, content, internalOptions);
|
|
402
|
+
return window.Store.Msg.get(msg.id._serialized);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
window.WWebJS.toStickerData = async (mediaInfo) => {
|
|
406
|
+
if (mediaInfo.mimetype == 'image/webp') return mediaInfo;
|
|
407
|
+
|
|
408
|
+
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
|
409
|
+
const webpSticker = await window.Store.StickerTools.toWebpSticker(file);
|
|
410
|
+
const webpBuffer = await webpSticker.arrayBuffer();
|
|
411
|
+
const data = window.WWebJS.arrayBufferToBase64(webpBuffer);
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
mimetype: 'image/webp',
|
|
415
|
+
data
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
window.WWebJS.processStickerData = async (mediaInfo) => {
|
|
420
|
+
if (mediaInfo.mimetype !== 'image/webp') throw new Error('Invalid media type');
|
|
421
|
+
|
|
422
|
+
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
|
423
|
+
let filehash = await window.WWebJS.getFileHash(file);
|
|
424
|
+
let mediaKey = await window.WWebJS.generateHash(32);
|
|
425
|
+
|
|
426
|
+
const controller = new AbortController();
|
|
427
|
+
const uploadedInfo = await window.Store.UploadUtils.encryptAndUpload({
|
|
428
|
+
blob: file,
|
|
429
|
+
type: 'sticker',
|
|
430
|
+
signal: controller.signal,
|
|
431
|
+
mediaKey
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const stickerInfo = {
|
|
435
|
+
...uploadedInfo,
|
|
436
|
+
clientUrl: uploadedInfo.url,
|
|
437
|
+
deprecatedMms3Url: uploadedInfo.url,
|
|
438
|
+
uploadhash: uploadedInfo.encFilehash,
|
|
439
|
+
size: file.size,
|
|
440
|
+
type: 'sticker',
|
|
441
|
+
filehash
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
return stickerInfo;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel, sendToStatus }) => {
|
|
448
|
+
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
|
449
|
+
const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);
|
|
450
|
+
const mediaParams = {
|
|
451
|
+
asSticker: forceSticker,
|
|
452
|
+
asGif: forceGif,
|
|
453
|
+
isPtt: forceVoice,
|
|
454
|
+
asDocument: forceDocument
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
if (forceMediaHd && file.type.indexOf('image/') === 0) {
|
|
458
|
+
mediaParams.maxDimension = 2560;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const mediaPrep = window.Store.MediaPrep.prepRawMedia(opaqueData, mediaParams);
|
|
462
|
+
const mediaData = await mediaPrep.waitForPrep();
|
|
463
|
+
const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
|
|
464
|
+
const mediaType = window.Store.MediaTypes.msgToMediaType({
|
|
465
|
+
type: mediaData.type,
|
|
466
|
+
isGif: mediaData.isGif,
|
|
467
|
+
isNewsletter: sendToChannel,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
if (!mediaData.filehash) {
|
|
471
|
+
throw new Error('media-fault: sendToChat filehash undefined');
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if ((forceVoice && mediaData.type === 'ptt') || (sendToStatus && mediaData.type === 'audio')) {
|
|
475
|
+
const waveform = mediaObject.contentInfo.waveform;
|
|
476
|
+
mediaData.waveform =
|
|
477
|
+
waveform || await window.WWebJS.generateWaveform(file);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (!(mediaData.mediaBlob instanceof window.Store.OpaqueData)) {
|
|
481
|
+
mediaData.mediaBlob = await window.Store.OpaqueData.createFromData(
|
|
482
|
+
mediaData.mediaBlob,
|
|
483
|
+
mediaData.mediaBlob.type
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
mediaData.renderableUrl = mediaData.mediaBlob.url();
|
|
488
|
+
mediaObject.consolidate(mediaData.toJSON());
|
|
489
|
+
|
|
490
|
+
mediaData.mediaBlob.autorelease();
|
|
491
|
+
const shouldUseMediaCache = window.Store.MediaDataUtils.shouldUseMediaCache(
|
|
492
|
+
window.Store.MediaTypes.castToV4(mediaObject.type)
|
|
493
|
+
);
|
|
494
|
+
if (shouldUseMediaCache && mediaData.mediaBlob instanceof window.Store.OpaqueData) {
|
|
495
|
+
const formData = mediaData.mediaBlob.formData();
|
|
496
|
+
window.Store.BlobCache.InMemoryMediaBlobCache.put(mediaObject.filehash, formData);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const dataToUpload = {
|
|
500
|
+
mimetype: mediaData.mimetype,
|
|
501
|
+
mediaObject,
|
|
502
|
+
mediaType,
|
|
503
|
+
...(sendToChannel ? { calculateToken: window.Store.SendChannelMessage.getRandomFilehash() } : {})
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
const uploadedMedia = !sendToChannel
|
|
507
|
+
? await window.Store.MediaUpload.uploadMedia(dataToUpload)
|
|
508
|
+
: await window.Store.MediaUpload.uploadUnencryptedMedia(dataToUpload);
|
|
509
|
+
|
|
510
|
+
const mediaEntry = uploadedMedia.mediaEntry;
|
|
511
|
+
if (!mediaEntry) {
|
|
512
|
+
throw new Error('upload failed: media entry was not created');
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
mediaData.set({
|
|
516
|
+
clientUrl: mediaEntry.mmsUrl,
|
|
517
|
+
deprecatedMms3Url: mediaEntry.deprecatedMms3Url,
|
|
518
|
+
directPath: mediaEntry.directPath,
|
|
519
|
+
mediaKey: mediaEntry.mediaKey,
|
|
520
|
+
mediaKeyTimestamp: mediaEntry.mediaKeyTimestamp,
|
|
521
|
+
filehash: mediaObject.filehash,
|
|
522
|
+
encFilehash: mediaEntry.encFilehash,
|
|
523
|
+
uploadhash: mediaEntry.uploadHash,
|
|
524
|
+
size: mediaObject.size,
|
|
525
|
+
streamingSidecar: mediaEntry.sidecar,
|
|
526
|
+
firstFrameSidecar: mediaEntry.firstFrameSidecar,
|
|
527
|
+
mediaHandle: sendToChannel ? mediaEntry.handle : null,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
return mediaData;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
window.WWebJS.getMessageModel = (message) => {
|
|
534
|
+
const msg = message.serialize();
|
|
535
|
+
|
|
536
|
+
msg.isEphemeral = message.isEphemeral;
|
|
537
|
+
msg.isStatusV3 = message.isStatusV3;
|
|
538
|
+
msg.links = (window.Store.Validators.findLinks(message.mediaObject ? message.caption : message.body)).map((link) => ({
|
|
539
|
+
link: link.href,
|
|
540
|
+
isSuspicious: Boolean(link.suspiciousCharacters && link.suspiciousCharacters.size)
|
|
541
|
+
}));
|
|
542
|
+
|
|
543
|
+
if (msg.buttons) {
|
|
544
|
+
msg.buttons = msg.buttons.serialize();
|
|
545
|
+
}
|
|
546
|
+
if (msg.dynamicReplyButtons) {
|
|
547
|
+
msg.dynamicReplyButtons = JSON.parse(JSON.stringify(msg.dynamicReplyButtons));
|
|
548
|
+
}
|
|
549
|
+
if (msg.replyButtons) {
|
|
550
|
+
msg.replyButtons = JSON.parse(JSON.stringify(msg.replyButtons));
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (typeof msg.id.remote === 'object') {
|
|
554
|
+
msg.id = Object.assign({}, msg.id, { remote: msg.id.remote._serialized });
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
delete msg.pendingAckUpdate;
|
|
558
|
+
|
|
559
|
+
return msg;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
window.WWebJS.getChat = async (chatId, { getAsModel = true } = {}) => {
|
|
563
|
+
const isChannel = /@\w*newsletter\b/.test(chatId);
|
|
564
|
+
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
565
|
+
let chat;
|
|
566
|
+
|
|
567
|
+
if (isChannel) {
|
|
568
|
+
try {
|
|
569
|
+
chat = window.Store.NewsletterCollection.get(chatId);
|
|
570
|
+
if (!chat) {
|
|
571
|
+
await window.Store.ChannelUtils.loadNewsletterPreviewChat(chatId);
|
|
572
|
+
chat = await window.Store.NewsletterCollection.find(chatWid);
|
|
573
|
+
}
|
|
574
|
+
} catch (err) {
|
|
575
|
+
chat = null;
|
|
576
|
+
}
|
|
577
|
+
} else {
|
|
578
|
+
chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return getAsModel && chat
|
|
582
|
+
? await window.WWebJS.getChatModel(chat, { isChannel: isChannel })
|
|
583
|
+
: chat;
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
window.WWebJS.getChannelMetadata = async (inviteCode) => {
|
|
587
|
+
const response =
|
|
588
|
+
await window.Store.ChannelUtils.queryNewsletterMetadataByInviteCode(
|
|
589
|
+
inviteCode,
|
|
590
|
+
window.Store.ChannelUtils.getRoleByIdentifier(inviteCode)
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
const picUrl = response.newsletterPictureMetadataMixin?.picture[0]?.queryPictureDirectPathOrEmptyResponseMixinGroup.value.directPath;
|
|
594
|
+
|
|
595
|
+
return {
|
|
596
|
+
id: response.idJid,
|
|
597
|
+
createdAtTs: response.newsletterCreationTimeMetadataMixin.creationTimeValue,
|
|
598
|
+
titleMetadata: {
|
|
599
|
+
title: response.newsletterNameMetadataMixin.nameElementValue,
|
|
600
|
+
updatedAtTs: response.newsletterNameMetadataMixin.nameUpdateTime
|
|
601
|
+
},
|
|
602
|
+
descriptionMetadata: {
|
|
603
|
+
description: response.newsletterDescriptionMetadataMixin.descriptionQueryDescriptionResponseMixin.elementValue,
|
|
604
|
+
updatedAtTs: response.newsletterDescriptionMetadataMixin.descriptionQueryDescriptionResponseMixin.updateTime
|
|
605
|
+
},
|
|
606
|
+
inviteLink: `https://whatsapp.com/channel/${response.newsletterInviteLinkMetadataMixin.inviteCode}`,
|
|
607
|
+
membershipType: window.Store.ChannelUtils.getRoleByIdentifier(inviteCode),
|
|
608
|
+
stateType: response.newsletterStateMetadataMixin.stateType,
|
|
609
|
+
pictureUrl: picUrl ? `https://pps.whatsapp.net${picUrl}` : null,
|
|
610
|
+
subscribersCount: response.newsletterSubscribersMetadataMixin.subscribersCount,
|
|
611
|
+
isVerified: response.newsletterVerificationMetadataMixin.verificationState === 'verified'
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
window.WWebJS.getChats = async () => {
|
|
616
|
+
const chats = window.Store.Chat.getModelsArray();
|
|
617
|
+
const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat));
|
|
618
|
+
return await Promise.all(chatPromises);
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
window.WWebJS.getChannels = async () => {
|
|
622
|
+
const channels = window.Store.NewsletterCollection.getModelsArray();
|
|
623
|
+
const channelPromises = channels?.map((channel) => window.WWebJS.getChatModel(channel, { isChannel: true }));
|
|
624
|
+
return await Promise.all(channelPromises);
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
window.WWebJS.getChatModel = async (chat, { isChannel = false } = {}) => {
|
|
628
|
+
if (!chat) return null;
|
|
629
|
+
|
|
630
|
+
const model = chat.serialize();
|
|
631
|
+
model.isGroup = false;
|
|
632
|
+
model.isMuted = chat.mute?.expiration !== 0;
|
|
633
|
+
if (isChannel) {
|
|
634
|
+
model.isChannel = window.Store.ChatGetters.getIsNewsletter(chat);
|
|
635
|
+
} else {
|
|
636
|
+
model.formattedTitle = chat.formattedTitle;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (chat.groupMetadata) {
|
|
640
|
+
model.isGroup = true;
|
|
641
|
+
const chatWid = window.Store.WidFactory.createWid(chat.id._serialized);
|
|
642
|
+
await window.Store.GroupMetadata.update(chatWid);
|
|
643
|
+
chat.groupMetadata.participants._models
|
|
644
|
+
.filter(x => x.id?._serialized?.endsWith('@lid'))
|
|
645
|
+
.forEach(x => x.contact?.phoneNumber && (x.id = x.contact.phoneNumber));
|
|
646
|
+
model.groupMetadata = chat.groupMetadata.serialize();
|
|
647
|
+
model.isReadOnly = chat.groupMetadata.announce;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (chat.newsletterMetadata) {
|
|
651
|
+
await window.Store.NewsletterMetadataCollection.update(chat.id);
|
|
652
|
+
model.channelMetadata = chat.newsletterMetadata.serialize();
|
|
653
|
+
model.channelMetadata.createdAtTs = chat.newsletterMetadata.creationTime;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
model.lastMessage = null;
|
|
657
|
+
if (model.msgs && model.msgs.length) {
|
|
658
|
+
const lastMessage = chat.lastReceivedKey
|
|
659
|
+
? window.Store.Msg.get(chat.lastReceivedKey._serialized) || (await window.Store.Msg.getMessagesById([chat.lastReceivedKey._serialized]))?.messages?.[0]
|
|
660
|
+
: null;
|
|
661
|
+
lastMessage && (model.lastMessage = window.WWebJS.getMessageModel(lastMessage));
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
delete model.msgs;
|
|
665
|
+
delete model.msgUnsyncedButtonReplyMsgs;
|
|
666
|
+
delete model.unsyncedButtonReplies;
|
|
667
|
+
|
|
668
|
+
return model;
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
window.WWebJS.getContactModel = contact => {
|
|
672
|
+
let res = contact.serialize();
|
|
673
|
+
res.isBusiness = contact.isBusiness === undefined ? false : contact.isBusiness;
|
|
674
|
+
|
|
675
|
+
if (contact.businessProfile) {
|
|
676
|
+
res.businessProfile = contact.businessProfile.serialize();
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
res.isMe = window.Store.ContactMethods.getIsMe(contact);
|
|
680
|
+
res.isUser = window.Store.ContactMethods.getIsUser(contact);
|
|
681
|
+
res.isGroup = window.Store.ContactMethods.getIsGroup(contact);
|
|
682
|
+
res.isWAContact = window.Store.ContactMethods.getIsWAContact(contact);
|
|
683
|
+
res.isMyContact = window.Store.ContactMethods.getIsMyContact(contact);
|
|
684
|
+
res.isBlocked = contact.isContactBlocked;
|
|
685
|
+
res.userid = window.Store.ContactMethods.getUserid(contact);
|
|
686
|
+
res.isEnterprise = window.Store.ContactMethods.getIsEnterprise(contact);
|
|
687
|
+
res.verifiedName = window.Store.ContactMethods.getVerifiedName(contact);
|
|
688
|
+
res.verifiedLevel = window.Store.ContactMethods.getVerifiedLevel(contact);
|
|
689
|
+
res.statusMute = window.Store.ContactMethods.getStatusMute(contact);
|
|
690
|
+
res.name = window.Store.ContactMethods.getName(contact);
|
|
691
|
+
res.shortName = window.Store.ContactMethods.getShortName(contact);
|
|
692
|
+
res.pushname = window.Store.ContactMethods.getPushname(contact);
|
|
693
|
+
|
|
694
|
+
return res;
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
window.WWebJS.getContact = async contactId => {
|
|
698
|
+
const wid = window.Store.WidFactory.createWid(contactId);
|
|
699
|
+
let contact = await window.Store.Contact.find(wid);
|
|
700
|
+
if (contact.id._serialized.endsWith('@lid')) {
|
|
701
|
+
contact.id = contact.phoneNumber;
|
|
702
|
+
}
|
|
703
|
+
const bizProfile = await window.Store.BusinessProfile.fetchBizProfile(wid);
|
|
704
|
+
bizProfile.profileOptions && (contact.businessProfile = bizProfile);
|
|
705
|
+
return window.WWebJS.getContactModel(contact);
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
window.WWebJS.getContacts = () => {
|
|
709
|
+
const contacts = window.Store.Contact.getModelsArray();
|
|
710
|
+
return contacts.map(contact => window.WWebJS.getContactModel(contact));
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
window.WWebJS.mediaInfoToFile = ({ data, mimetype, filename }) => {
|
|
714
|
+
const binaryData = window.atob(data);
|
|
715
|
+
|
|
716
|
+
const buffer = new ArrayBuffer(binaryData.length);
|
|
717
|
+
const view = new Uint8Array(buffer);
|
|
718
|
+
for (let i = 0; i < binaryData.length; i++) {
|
|
719
|
+
view[i] = binaryData.charCodeAt(i);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const blob = new Blob([buffer], { type: mimetype });
|
|
723
|
+
return new File([blob], filename, {
|
|
724
|
+
type: mimetype,
|
|
725
|
+
lastModified: Date.now()
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
window.WWebJS.arrayBufferToBase64 = (arrayBuffer) => {
|
|
730
|
+
let binary = '';
|
|
731
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
732
|
+
const len = bytes.byteLength;
|
|
733
|
+
for (let i = 0; i < len; i++) {
|
|
734
|
+
binary += String.fromCharCode(bytes[i]);
|
|
735
|
+
}
|
|
736
|
+
return window.btoa(binary);
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
window.WWebJS.arrayBufferToBase64Async = (arrayBuffer) =>
|
|
740
|
+
new Promise((resolve, reject) => {
|
|
741
|
+
const blob = new Blob([arrayBuffer], {
|
|
742
|
+
type: 'application/octet-stream',
|
|
743
|
+
});
|
|
744
|
+
const fileReader = new FileReader();
|
|
745
|
+
fileReader.onload = () => {
|
|
746
|
+
const [, data] = fileReader.result.split(',');
|
|
747
|
+
resolve(data);
|
|
748
|
+
};
|
|
749
|
+
fileReader.onerror = (e) => reject(e);
|
|
750
|
+
fileReader.readAsDataURL(blob);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
window.WWebJS.getFileHash = async (data) => {
|
|
754
|
+
let buffer = await data.arrayBuffer();
|
|
755
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
|
756
|
+
return btoa(String.fromCharCode(...new Uint8Array(hashBuffer)));
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
window.WWebJS.generateHash = async (length) => {
|
|
760
|
+
var result = '';
|
|
761
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
762
|
+
var charactersLength = characters.length;
|
|
763
|
+
for (var i = 0; i < length; i++) {
|
|
764
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
765
|
+
}
|
|
766
|
+
return result;
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
window.WWebJS.generateWaveform = async (audioFile) => {
|
|
770
|
+
try {
|
|
771
|
+
const audioData = await audioFile.arrayBuffer();
|
|
772
|
+
const audioContext = new AudioContext();
|
|
773
|
+
const audioBuffer = await audioContext.decodeAudioData(audioData);
|
|
774
|
+
|
|
775
|
+
const rawData = audioBuffer.getChannelData(0);
|
|
776
|
+
const samples = 64;
|
|
777
|
+
const blockSize = Math.floor(rawData.length / samples);
|
|
778
|
+
const filteredData = [];
|
|
779
|
+
for (let i = 0; i < samples; i++) {
|
|
780
|
+
const blockStart = blockSize * i;
|
|
781
|
+
let sum = 0;
|
|
782
|
+
for (let j = 0; j < blockSize; j++) {
|
|
783
|
+
sum = sum + Math.abs(rawData[blockStart + j]);
|
|
784
|
+
}
|
|
785
|
+
filteredData.push(sum / blockSize);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
789
|
+
const normalizedData = filteredData.map((n) => n * multiplier);
|
|
790
|
+
|
|
791
|
+
const waveform = new Uint8Array(
|
|
792
|
+
normalizedData.map((n) => Math.floor(100 * n))
|
|
793
|
+
);
|
|
794
|
+
|
|
795
|
+
return waveform;
|
|
796
|
+
} catch (e) {
|
|
797
|
+
return undefined;
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
window.WWebJS.sendClearChat = async (chatId) => {
|
|
802
|
+
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
803
|
+
if (chat !== undefined) {
|
|
804
|
+
await window.Store.SendClear.sendClear(chat, false);
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
return false;
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
window.WWebJS.sendDeleteChat = async (chatId) => {
|
|
811
|
+
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
812
|
+
if (chat !== undefined) {
|
|
813
|
+
await window.Store.SendDelete.sendDelete(chat);
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
return false;
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
window.WWebJS.sendChatstate = async (state, chatId) => {
|
|
820
|
+
chatId = window.Store.WidFactory.createWid(chatId);
|
|
821
|
+
|
|
822
|
+
switch (state) {
|
|
823
|
+
case 'typing':
|
|
824
|
+
await window.Store.ChatState.sendChatStateComposing(chatId);
|
|
825
|
+
break;
|
|
826
|
+
case 'recording':
|
|
827
|
+
await window.Store.ChatState.sendChatStateRecording(chatId);
|
|
828
|
+
break;
|
|
829
|
+
case 'stop':
|
|
830
|
+
await window.Store.ChatState.sendChatStatePaused(chatId);
|
|
831
|
+
break;
|
|
832
|
+
default:
|
|
833
|
+
throw 'Invalid chatstate';
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
return true;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
window.WWebJS.getLabelModel = label => {
|
|
840
|
+
let res = label.serialize();
|
|
841
|
+
res.hexColor = label.hexColor;
|
|
842
|
+
|
|
843
|
+
return res;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
window.WWebJS.getLabels = () => {
|
|
847
|
+
const labels = window.Store.Label.getModelsArray();
|
|
848
|
+
return labels.map(label => window.WWebJS.getLabelModel(label));
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
window.WWebJS.getLabel = (labelId) => {
|
|
852
|
+
const label = window.Store.Label.get(labelId);
|
|
853
|
+
return window.WWebJS.getLabelModel(label);
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
window.WWebJS.getChatLabels = async (chatId) => {
|
|
857
|
+
const chat = await window.WWebJS.getChat(chatId);
|
|
858
|
+
return (chat.labels || []).map(id => window.WWebJS.getLabel(id));
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
window.WWebJS.getOrderDetail = async (orderId, token, chatId) => {
|
|
862
|
+
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
863
|
+
return window.Store.QueryOrder.queryOrder(chatWid, orderId, 80, 80, token);
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
window.WWebJS.getProductMetadata = async (productId) => {
|
|
867
|
+
let sellerId = window.Store.Conn.wid;
|
|
868
|
+
let product = await window.Store.QueryProduct.queryProduct(sellerId, productId);
|
|
869
|
+
if (product && product.data) {
|
|
870
|
+
return product.data;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return undefined;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
window.WWebJS.rejectCall = async (peerJid, id) => {
|
|
877
|
+
let userId = window.Store.User.getMaybeMePnUser()._serialized;
|
|
878
|
+
|
|
879
|
+
const stanza = window.Store.SocketWap.wap('call', {
|
|
880
|
+
id: window.Store.SocketWap.generateId(),
|
|
881
|
+
from: userId,
|
|
882
|
+
to: peerJid,
|
|
883
|
+
}, [
|
|
884
|
+
window.Store.SocketWap.wap('reject', {
|
|
885
|
+
'call-id': id,
|
|
886
|
+
'call-creator': peerJid,
|
|
887
|
+
count: '0',
|
|
888
|
+
})
|
|
889
|
+
]);
|
|
890
|
+
await window.Store.Socket.deprecatedCastStanza(stanza);
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
window.WWebJS.cropAndResizeImage = async (media, options = {}) => {
|
|
894
|
+
if (!media.mimetype.includes('image'))
|
|
895
|
+
throw new Error('Media is not an image');
|
|
896
|
+
|
|
897
|
+
if (options.mimetype && !options.mimetype.includes('image'))
|
|
898
|
+
delete options.mimetype;
|
|
899
|
+
|
|
900
|
+
options = Object.assign({ size: 640, mimetype: media.mimetype, quality: .75, asDataUrl: false }, options);
|
|
901
|
+
|
|
902
|
+
const img = await new Promise ((resolve, reject) => {
|
|
903
|
+
const img = new Image();
|
|
904
|
+
img.onload = () => resolve(img);
|
|
905
|
+
img.onerror = reject;
|
|
906
|
+
img.src = `data:${media.mimetype};base64,${media.data}`;
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
const sl = Math.min(img.width, img.height);
|
|
910
|
+
const sx = Math.floor((img.width - sl) / 2);
|
|
911
|
+
const sy = Math.floor((img.height - sl) / 2);
|
|
912
|
+
|
|
913
|
+
const canvas = document.createElement('canvas');
|
|
914
|
+
canvas.width = options.size;
|
|
915
|
+
canvas.height = options.size;
|
|
916
|
+
|
|
917
|
+
const ctx = canvas.getContext('2d');
|
|
918
|
+
ctx.drawImage(img, sx, sy, sl, sl, 0, 0, options.size, options.size);
|
|
919
|
+
|
|
920
|
+
const dataUrl = canvas.toDataURL(options.mimetype, options.quality);
|
|
921
|
+
|
|
922
|
+
if (options.asDataUrl)
|
|
923
|
+
return dataUrl;
|
|
924
|
+
|
|
925
|
+
return Object.assign(media, {
|
|
926
|
+
mimetype: options.mimetype,
|
|
927
|
+
data: dataUrl.replace(`data:${options.mimetype};base64,`, '')
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
window.WWebJS.setPicture = async (chatId, media) => {
|
|
932
|
+
const thumbnail = await window.WWebJS.cropAndResizeImage(media, { asDataUrl: true, mimetype: 'image/jpeg', size: 96 });
|
|
933
|
+
const profilePic = await window.WWebJS.cropAndResizeImage(media, { asDataUrl: true, mimetype: 'image/jpeg', size: 640 });
|
|
934
|
+
|
|
935
|
+
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
936
|
+
try {
|
|
937
|
+
const collection = window.Store.ProfilePicThumb.get(chatId) || await window.Store.ProfilePicThumb.find(chatId);
|
|
938
|
+
if (!collection?.canSet()) return false;
|
|
939
|
+
|
|
940
|
+
const res = await window.Store.GroupUtils.sendSetPicture(chatWid, thumbnail, profilePic);
|
|
941
|
+
return res ? res.status === 200 : false;
|
|
942
|
+
} catch (err) {
|
|
943
|
+
if (err.name === 'ServerStatusCodeError') return false;
|
|
944
|
+
throw err;
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
window.WWebJS.deletePicture = async (chatid) => {
|
|
949
|
+
const chatWid = window.Store.WidFactory.createWid(chatid);
|
|
950
|
+
try {
|
|
951
|
+
const collection = window.Store.ProfilePicThumb.get(chatid);
|
|
952
|
+
if (!collection.canDelete()) return;
|
|
953
|
+
|
|
954
|
+
const res = await window.Store.GroupUtils.requestDeletePicture(chatWid);
|
|
955
|
+
return res ? res.status === 200 : false;
|
|
956
|
+
} catch (err) {
|
|
957
|
+
if(err.name === 'ServerStatusCodeError') return false;
|
|
958
|
+
throw err;
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
window.WWebJS.getProfilePicThumbToBase64 = async (chatWid) => {
|
|
963
|
+
const profilePicCollection = await window.Store.ProfilePicThumb.find(chatWid);
|
|
964
|
+
|
|
965
|
+
const _readImageAsBase64 = (imageBlob) => {
|
|
966
|
+
return new Promise((resolve) => {
|
|
967
|
+
const reader = new FileReader();
|
|
968
|
+
reader.onloadend = function () {
|
|
969
|
+
const base64Image = reader.result;
|
|
970
|
+
if (base64Image == null) {
|
|
971
|
+
resolve(undefined);
|
|
972
|
+
} else {
|
|
973
|
+
const base64Data = base64Image.toString().split(',')[1];
|
|
974
|
+
resolve(base64Data);
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
reader.readAsDataURL(imageBlob);
|
|
978
|
+
});
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
if (profilePicCollection?.img) {
|
|
982
|
+
try {
|
|
983
|
+
const response = await fetch(profilePicCollection.img);
|
|
984
|
+
if (response.ok) {
|
|
985
|
+
const imageBlob = await response.blob();
|
|
986
|
+
if (imageBlob) {
|
|
987
|
+
const base64Image = await _readImageAsBase64(imageBlob);
|
|
988
|
+
return base64Image;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
} catch (error) { /* empty */ }
|
|
992
|
+
}
|
|
993
|
+
return undefined;
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
window.WWebJS.getAddParticipantsRpcResult = async (groupWid, participantWid) => {
|
|
997
|
+
const iqTo = window.Store.WidToJid.widToGroupJid(groupWid);
|
|
998
|
+
|
|
999
|
+
const participantArgs = [{
|
|
1000
|
+
participantJid: window.Store.WidToJid.widToUserJid(participantWid)
|
|
1001
|
+
}];
|
|
1002
|
+
|
|
1003
|
+
let rpcResult, resultArgs;
|
|
1004
|
+
const data = {
|
|
1005
|
+
name: undefined,
|
|
1006
|
+
code: undefined,
|
|
1007
|
+
inviteV4Code: undefined,
|
|
1008
|
+
inviteV4CodeExp: undefined
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
try {
|
|
1012
|
+
rpcResult = await window.Store.GroupParticipants.sendAddParticipantsRPC({ participantArgs, iqTo });
|
|
1013
|
+
resultArgs = rpcResult.value.addParticipant[0]
|
|
1014
|
+
.addParticipantsParticipantAddedOrNonRegisteredWaUserParticipantErrorLidResponseMixinGroup
|
|
1015
|
+
.value
|
|
1016
|
+
.addParticipantsParticipantMixins;
|
|
1017
|
+
} catch (err) {
|
|
1018
|
+
data.code = 400;
|
|
1019
|
+
return data;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (rpcResult.name === 'AddParticipantsResponseSuccess') {
|
|
1023
|
+
const code = resultArgs?.value.error || '200';
|
|
1024
|
+
data.name = resultArgs?.name;
|
|
1025
|
+
data.code = +code;
|
|
1026
|
+
data.inviteV4Code = resultArgs?.value.addRequestCode;
|
|
1027
|
+
data.inviteV4CodeExp = resultArgs?.value.addRequestExpiration?.toString();
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
else if (rpcResult.name === 'AddParticipantsResponseClientError') {
|
|
1031
|
+
const { code: code } = rpcResult.value.errorAddParticipantsClientErrors.value;
|
|
1032
|
+
data.code = +code;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
else if (rpcResult.name === 'AddParticipantsResponseServerError') {
|
|
1036
|
+
const { code: code } = rpcResult.value.errorServerErrors.value;
|
|
1037
|
+
data.code = +code;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
return data;
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
window.WWebJS.membershipRequestAction = async (groupId, action, requesterIds, sleep) => {
|
|
1044
|
+
const groupWid = window.Store.WidFactory.createWid(groupId);
|
|
1045
|
+
const group = await window.Store.Chat.find(groupWid);
|
|
1046
|
+
const toApprove = action === 'Approve';
|
|
1047
|
+
let membershipRequests;
|
|
1048
|
+
let response;
|
|
1049
|
+
let result = [];
|
|
1050
|
+
|
|
1051
|
+
await window.Store.GroupQueryAndUpdate({ id: groupId });
|
|
1052
|
+
|
|
1053
|
+
if (!requesterIds?.length) {
|
|
1054
|
+
membershipRequests = group.groupMetadata.membershipApprovalRequests._models.map(({ id }) => id);
|
|
1055
|
+
} else {
|
|
1056
|
+
!Array.isArray(requesterIds) && (requesterIds = [requesterIds]);
|
|
1057
|
+
membershipRequests = requesterIds.map(r => window.Store.WidFactory.createWid(r));
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (!membershipRequests.length) return [];
|
|
1061
|
+
|
|
1062
|
+
const participantArgs = membershipRequests.map(m => ({
|
|
1063
|
+
participantArgs: [
|
|
1064
|
+
{
|
|
1065
|
+
participantJid: window.Store.WidToJid.widToUserJid(m)
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
1068
|
+
}));
|
|
1069
|
+
|
|
1070
|
+
const groupJid = window.Store.WidToJid.widToGroupJid(groupWid);
|
|
1071
|
+
|
|
1072
|
+
const _getSleepTime = (sleep) => {
|
|
1073
|
+
if (!Array.isArray(sleep) || (sleep.length === 2 && sleep[0] === sleep[1])) {
|
|
1074
|
+
return sleep;
|
|
1075
|
+
}
|
|
1076
|
+
if (sleep.length === 1) {
|
|
1077
|
+
return sleep[0];
|
|
1078
|
+
}
|
|
1079
|
+
sleep[1] - sleep[0] < 100 && (sleep[0] = sleep[1]) && (sleep[1] += 100);
|
|
1080
|
+
return Math.floor(Math.random() * (sleep[1] - sleep[0] + 1)) + sleep[0];
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
const membReqResCodes = {
|
|
1084
|
+
default: `An unknown error occupied while ${toApprove ? 'approving' : 'rejecting'} the participant membership request`,
|
|
1085
|
+
400: 'ParticipantNotFoundError',
|
|
1086
|
+
401: 'ParticipantNotAuthorizedError',
|
|
1087
|
+
403: 'ParticipantForbiddenError',
|
|
1088
|
+
404: 'ParticipantRequestNotFoundError',
|
|
1089
|
+
408: 'ParticipantTemporarilyBlockedError',
|
|
1090
|
+
409: 'ParticipantConflictError',
|
|
1091
|
+
412: 'ParticipantParentLinkedGroupsResourceConstraintError',
|
|
1092
|
+
500: 'ParticipantResourceConstraintError'
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
try {
|
|
1096
|
+
for (const participant of participantArgs) {
|
|
1097
|
+
response = await window.Store.MembershipRequestUtils.sendMembershipRequestsActionRPC({
|
|
1098
|
+
iqTo: groupJid,
|
|
1099
|
+
[toApprove ? 'approveArgs' : 'rejectArgs']: participant
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
if (response.name === 'MembershipRequestsActionResponseSuccess') {
|
|
1103
|
+
const value = toApprove
|
|
1104
|
+
? response.value.membershipRequestsActionApprove
|
|
1105
|
+
: response.value.membershipRequestsActionReject;
|
|
1106
|
+
if (value?.participant) {
|
|
1107
|
+
const [_] = value.participant.map(p => {
|
|
1108
|
+
const error = toApprove
|
|
1109
|
+
? value.participant[0].membershipRequestsActionAcceptParticipantMixins?.value.error
|
|
1110
|
+
: value.participant[0].membershipRequestsActionRejectParticipantMixins?.value.error;
|
|
1111
|
+
return {
|
|
1112
|
+
requesterId: window.Store.WidFactory.createWid(p.jid)._serialized,
|
|
1113
|
+
...(error
|
|
1114
|
+
? { error: +error, message: membReqResCodes[error] || membReqResCodes.default }
|
|
1115
|
+
: { message: `${toApprove ? 'Approved' : 'Rejected'} successfully` })
|
|
1116
|
+
};
|
|
1117
|
+
});
|
|
1118
|
+
_ && result.push(_);
|
|
1119
|
+
}
|
|
1120
|
+
} else {
|
|
1121
|
+
result.push({
|
|
1122
|
+
requesterId: window.Store.JidToWid.userJidToUserWid(participant.participantArgs[0].participantJid)._serialized,
|
|
1123
|
+
message: 'ServerStatusCodeError'
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
sleep &&
|
|
1128
|
+
participantArgs.length > 1 &&
|
|
1129
|
+
participantArgs.indexOf(participant) !== participantArgs.length - 1 &&
|
|
1130
|
+
(await new Promise((resolve) => setTimeout(resolve, _getSleepTime(sleep))));
|
|
1131
|
+
}
|
|
1132
|
+
return result;
|
|
1133
|
+
} catch (err) {
|
|
1134
|
+
return [];
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
window.WWebJS.subscribeToUnsubscribeFromChannel = async (channelId, action, options = {}) => {
|
|
1139
|
+
const channel = await window.WWebJS.getChat(channelId, { getAsModel: false });
|
|
1140
|
+
|
|
1141
|
+
if (!channel || channel.newsletterMetadata.membershipType === 'owner') return false;
|
|
1142
|
+
options = { eventSurface: 3, deleteLocalModels: options.deleteLocalModels ?? true };
|
|
1143
|
+
|
|
1144
|
+
try {
|
|
1145
|
+
if (action === 'Subscribe') {
|
|
1146
|
+
await window.Store.ChannelUtils.subscribeToNewsletterAction(channel, options);
|
|
1147
|
+
} else if (action === 'Unsubscribe') {
|
|
1148
|
+
await window.Store.ChannelUtils.unsubscribeFromNewsletterAction(channel, options);
|
|
1149
|
+
} else return false;
|
|
1150
|
+
return true;
|
|
1151
|
+
} catch (err) {
|
|
1152
|
+
if (err.name === 'ServerStatusCodeError') return false;
|
|
1153
|
+
throw err;
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
|
|
1158
|
+
const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
1159
|
+
if (!message) return false;
|
|
1160
|
+
|
|
1161
|
+
if (typeof duration !== 'number') return false;
|
|
1162
|
+
|
|
1163
|
+
const originalFunction = window.require('WAWebPinMsgConstants').getPinExpiryDuration;
|
|
1164
|
+
window.require('WAWebPinMsgConstants').getPinExpiryDuration = () => duration;
|
|
1165
|
+
|
|
1166
|
+
const response = await window.Store.PinnedMsgUtils.sendPinInChatMsg(message, action, duration);
|
|
1167
|
+
|
|
1168
|
+
window.require('WAWebPinMsgConstants').getPinExpiryDuration = originalFunction;
|
|
1169
|
+
|
|
1170
|
+
return response.messageSendResult === 'OK';
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
window.WWebJS.getStatusModel = status => {
|
|
1174
|
+
const res = status.serialize();
|
|
1175
|
+
delete res._msgs;
|
|
1176
|
+
return res;
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
window.WWebJS.getAllStatuses = () => {
|
|
1180
|
+
const statuses = window.Store.Status.getModelsArray();
|
|
1181
|
+
return statuses.map(status => window.WWebJS.getStatusModel(status));
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
window.WWebJS.enforceLidAndPnRetrieval = async (userId) => {
|
|
1185
|
+
const wid = window.Store.WidFactory.createWid(userId);
|
|
1186
|
+
const isLid = wid.server === 'lid';
|
|
1187
|
+
|
|
1188
|
+
let lid = isLid ? wid : window.Store.LidUtils.getCurrentLid(wid);
|
|
1189
|
+
let phone = isLid ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
|
|
1190
|
+
|
|
1191
|
+
if (!isLid && !lid) {
|
|
1192
|
+
const queryResult = await window.Store.QueryExist(wid);
|
|
1193
|
+
if (!queryResult?.wid) return {};
|
|
1194
|
+
lid = window.Store.LidUtils.getCurrentLid(wid);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (isLid && !phone) {
|
|
1198
|
+
const queryResult = await window.Store.QueryExist(wid);
|
|
1199
|
+
if (!queryResult?.wid) return {};
|
|
1200
|
+
phone = window.Store.LidUtils.getPhoneNumber(wid);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
return { lid, phone };
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
window.WWebJS.assertColor = (hex) => {
|
|
1207
|
+
let color;
|
|
1208
|
+
if (typeof hex === 'number') {
|
|
1209
|
+
color = hex > 0 ? hex : 0xffffffff + parseInt(hex) + 1;
|
|
1210
|
+
} else if (typeof hex === 'string') {
|
|
1211
|
+
let number = hex.trim().replace('#', '');
|
|
1212
|
+
if (number.length <= 6) {
|
|
1213
|
+
number = 'FF' + number.padStart(6, '0');
|
|
1214
|
+
}
|
|
1215
|
+
color = parseInt(number, 16);
|
|
1216
|
+
} else {
|
|
1217
|
+
throw 'Invalid hex color';
|
|
1218
|
+
}
|
|
1219
|
+
return color;
|
|
1220
|
+
};
|
|
1221
|
+
};
|