@open-wa/wa-automate 4.68.0 → 4.70.0
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/dist/cli/integrations/cloudflare.js +2 -2
- package/dist/cli/server.js +1 -1
- package/dist/controllers/auth.js +14 -8
- package/dist/controllers/initializer.js +2 -2
- package/dist/controllers/patch_manager.js +3 -9
- package/dist/lib/launch.js +10 -1
- package/dist/lib/wapi.js +384 -409
- package/package.json +1 -1
package/dist/lib/wapi.js
CHANGED
@@ -7,91 +7,63 @@
|
|
7
7
|
* functions and creates the Store object.
|
8
8
|
*/
|
9
9
|
|
10
|
-
if (!window.Store
|
10
|
+
if (!window.Store || !window.Store.Msg) {
|
11
11
|
(function () {
|
12
|
-
function getStore(
|
13
|
-
let foundCount = 0;
|
12
|
+
function getStore() {
|
14
13
|
let neededObjects = [
|
15
|
-
{ id: "
|
16
|
-
{ id: "
|
17
|
-
{ id: "
|
18
|
-
{ id: "
|
19
|
-
{ id: "
|
20
|
-
{ id: "
|
21
|
-
{ id: "
|
22
|
-
{ id: "
|
23
|
-
{ id: "
|
24
|
-
{ id: "
|
25
|
-
{ id: "
|
26
|
-
{ id: "
|
27
|
-
{ id: "
|
28
|
-
{ id: "
|
29
|
-
{ id: "
|
30
|
-
{ id: "
|
31
|
-
{ id: "
|
32
|
-
{ id: "
|
33
|
-
{ id: "
|
34
|
-
{ id: "
|
35
|
-
{ id: "
|
36
|
-
{ id: "
|
37
|
-
{ id: "
|
38
|
-
{ id: "
|
39
|
-
{ id: "
|
40
|
-
{ id: "
|
41
|
-
{ id: "
|
42
|
-
{ id: "Me", conditions: (module) => (module.PLATFORMS && module.Conn) ? module.default : null },
|
43
|
-
{ id: "CallUtils", conditions: (module) => (module.sendCallEnd && module.parseCall) ? module : null },
|
44
|
-
{ id: "Identity", conditions: (module) => (module.queryIdentity && module.updateIdentity) ? module : null },
|
45
|
-
{ id: "MyStatus", conditions: (module) => (module.getStatus && module.setMyStatus) ? module : null },
|
46
|
-
{ id: "ChatStates", conditions: (module) => (module.sendChatStatePaused && module.sendChatStateRecording && module.sendChatStateComposing) ? module : null },
|
47
|
-
{ id: "GroupActions", conditions: (module) => (module.sendExitGroup && module.localExitGroup) ? module : null },
|
48
|
-
{ id: "Features", conditions: (module) => (module.FEATURE_CHANGE_EVENT && module.features) ? module : null },
|
49
|
-
{ id: "MessageUtils", conditions: (module) => (module.storeMessages && module.appendMessage) ? module : null },
|
50
|
-
{ id: "WebMessageInfo", conditions: (module) => (module.WebMessageInfo && module.WebFeatures) ? module.WebMessageInfo : null },
|
51
|
-
{ id: "createMessageKey", conditions: (module) => (module.createMessageKey && module.createDeviceSentMessage) ? module.createMessageKey : null },
|
52
|
-
{ id: "Participants", conditions: (module) => (module.addParticipants && module.removeParticipants && module.promoteParticipants && module.demoteParticipants) ? module : null },
|
53
|
-
{ id: "WidFactory", conditions: (module) => (module.isWidlike && module.createWid && module.createWidFromWidLike) ? module : null },
|
54
|
-
{ id: "Base", conditions: (module) => (module.setSubProtocol && module.binSend && module.actionNode) ? module : null },
|
55
|
-
{ id: "Versions", conditions: (module) => (module.loadProtoVersions && module.default && module.default["15"] && module.default["16"] && module.default["17"]) ? module : null },
|
56
|
-
{ id: "Sticker", conditions: (module) => (module.default && module.default.Sticker) ? module.default.Sticker : null },
|
57
|
-
{ id: "MediaUpload", conditions: (module) => (module.default && module.default.mediaUpload) ? module.default : null },
|
58
|
-
{ id: "UploadUtils", conditions: (module) => (module.default && module.default.encryptAndUpload) ? module.default : null }
|
14
|
+
{ id: "MediaCollection", module: "WAWebAttachMediaCollection", conditions: (module) => (module.default && module.default.prototype && (module.default.prototype.processFiles !== undefined || module.default.prototype.processAttachments !== undefined)) ? module.default : null },
|
15
|
+
{ id: "Archive", module: "WAWebSetArchiveChatAction", conditions: (module) => (module.setArchive) ? module : null },
|
16
|
+
{ id: "Block", module: "WAWebBlockContactUtils", conditions: (module) => (module.blockContact && module.unblockContact) ? module : null },
|
17
|
+
{ id: "ChatUtil", module: "WAWebSendClearChatAction", conditions: (module) => (module.sendClear) ? module : null },
|
18
|
+
{ id: "GroupInvite", module: "WAWebGroupInviteJob", conditions: (module) => (module.queryGroupInviteCode) ? module : null },
|
19
|
+
{ id: "Wap", module: "WAWebCreateGroupAction", conditions: (module) => (module.createGroup) ? module : null },
|
20
|
+
{ id: "State", module: "WAWebSocketModel", conditions: (module) => (module.STATE && module.STREAM) ? module : null },
|
21
|
+
{ id: "_Presence", module: "WAWebContactPresenceBridge", conditions: (module) => (module.setPresenceAvailable && module.setPresenceUnavailable) ? module : null },
|
22
|
+
{ id: "WapDelete", module: "WAWebChatDeleteBridge", conditions: (module) => (module.sendConversationDelete && module.sendConversationDelete.length == 2) ? module : null },
|
23
|
+
{ id: "WapQuery", module: "WAWebQueryExistsJob", conditions: (module) => (module.queryExist) ? module : ((module.default && module.default.queryExist) ? module.default : null) },
|
24
|
+
{ id: "UserConstructor", module: "WAWebWid", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null },
|
25
|
+
{ id: "SendTextMsgToChat", module: "WAWebSendTextMsgChatAction", resolver: (module) => module.sendTextMsgToChat},
|
26
|
+
{ id: "ReadSeen", module: "WAWebUpdateUnreadChatAction", conditions: (module) => (module.sendSeen) ? module : null },
|
27
|
+
{ id: "sendDelete", module: "WAWebDeleteChatAction", conditions: (module) => (module.sendDelete) ? module.sendDelete : null },
|
28
|
+
{ id: "addAndSendMsgToChat", module: "WAWebSendMsgChatAction", conditions: (module) => (module.addAndSendMsgToChat) ? module.addAndSendMsgToChat : null },
|
29
|
+
{ id: "Catalog", module: "WAWebCatalogCollection", conditions: (module) => (module.Catalog) ? module.Catalog : null },
|
30
|
+
{ id: "MsgKey", module: "WAWebMsgKey", conditions: (module) => (module.default && module.default.toString && module.default.toString().includes('MsgKey error: obj is null/undefined')) ? module.default : null },
|
31
|
+
{ id: "Parser", module: "WAWebE2EProtoUtils", conditions: (module) => (module.convertToTextWithoutSpecialEmojis) ? module.default : null },
|
32
|
+
{ id: "Builders", module: "WAWebProtobufsE2E.pb", conditions: (module) => (module.TemplateMessage && module.HydratedFourRowTemplate) ? module : null },
|
33
|
+
{ id: "Me", module: "WAWebUserPrefsMeUser", conditions: (module) => (module.PLATFORMS && module.Conn) ? module.default : null },
|
34
|
+
{ id: "MyStatus", module: "WAWebContactStatusBridge", conditions: (module) => (module.getStatus && module.setMyStatus) ? module : null },
|
35
|
+
{ id: "ChatStates", module: "WAWebChatStateBridge", conditions: (module) => (module.sendChatStatePaused && module.sendChatStateRecording && module.sendChatStateComposing) ? module : null },
|
36
|
+
{ id: "GroupActions", module: "WAWebExitGroupAction", conditions: (module) => (module.sendExitGroup && module.localExitGroup) ? module : null },
|
37
|
+
{ id: "Participants", module: "WAWebGroupsParticipantsApi", conditions: (module) => (module.addParticipants && module.removeParticipants && module.promoteParticipants && module.demoteParticipants) ? module : null },
|
38
|
+
{ id: "WidFactory", module: "WAWebWidFactory", conditions: (module) => (module.isWidlike && module.createWid && module.createWidFromWidLike) ? module : null },
|
39
|
+
{ id: "Sticker", module: "WAWebStickerPackCollection", conditions: (module) => (module.default && module.default.Sticker) ? module.default.Sticker : null },
|
40
|
+
{ id: "UploadUtils", module: "WAWebUploadManager", conditions: (module) => (module.default && module.default.encryptAndUpload) ? module.default : null }
|
59
41
|
];
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
break;
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
let neededStore = neededObjects.find((needObj) => needObj.id === "Store");
|
78
|
-
window.Store = neededStore.foundedModule ? neededStore.foundedModule : {};
|
79
|
-
neededObjects.splice(neededObjects.indexOf(neededStore), 1);
|
42
|
+
neededObjects.map((needObj) => {
|
43
|
+
if (!needObj.module) return;
|
44
|
+
let neededModule = require(needObj.module)
|
45
|
+
needObj.foundedModule = neededModule;
|
46
|
+
});
|
47
|
+
window.Store = {...Object.values(require("WAWebLoadMainBundleFileDefinitions")).map(x=>{
|
48
|
+
const module = x();
|
49
|
+
const collectionName = module.modelClass?.prototype?.proxyName
|
50
|
+
if(!collectionName) return false;
|
51
|
+
const capName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
|
52
|
+
return [capName, module]
|
53
|
+
}).filter(x=>x).reduce((acc,curr) => {return {...acc,[curr[0]]: curr[1]}}, {}),
|
54
|
+
...(window.Store || {})}
|
80
55
|
neededObjects.forEach((needObj) => {
|
81
56
|
if (needObj.foundedModule) {
|
82
|
-
window.Store[needObj.id] = needObj.foundedModule;
|
57
|
+
window.Store[needObj.id] = needObj.resolver ? needObj.resolver(needObj.foundedModule) : needObj.foundedModule;
|
83
58
|
}
|
84
59
|
});
|
85
|
-
|
86
|
-
|
87
|
-
|
60
|
+
if (window.Store.Chat) window.Store.Chat.modelClass.prototype.sendMessage = function (e) {
|
61
|
+
window.Store.SendTextMsgToChat(this, ...arguments);
|
62
|
+
}
|
88
63
|
return window.Store;
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if (typeof webpackJsonp === 'function') webpackJsonp([], {[parasite]: (x, y, z) => getStore(z)}, [parasite]);
|
93
|
-
else webpackChunkbuild.push([[parasite], {}, function (o, e, t) {let modules = []; for (let idx in o.m) {modules.push(o(idx));} getStore(modules);}]);
|
94
|
-
})();
|
64
|
+
}
|
65
|
+
getStore()
|
66
|
+
}) ();
|
95
67
|
}
|
96
68
|
|
97
69
|
window.WAPI = {};
|
@@ -153,14 +125,14 @@ window.WAPI._serializeMessageObj = (obj) => {
|
|
153
125
|
return null;
|
154
126
|
}
|
155
127
|
const _chat = obj['chat'] ? WAPI._serializeChatObj(obj['chat']) : {};
|
156
|
-
if(obj.quotedMsg) obj.quotedMsgObj();
|
128
|
+
if (obj.quotedMsg) obj.quotedMsgObj();
|
157
129
|
return Object.assign(window.WAPI._serializeRawObj(obj), {
|
158
130
|
id: obj.id._serialized,
|
159
131
|
from: obj.from._serialized,
|
160
|
-
quotedParticipant: obj.quotedParticipant? obj.quotedParticipant._serialized ? obj.quotedParticipant._serialized : undefined : undefined,
|
161
|
-
author: obj.author? obj.author._serialized ? obj.author._serialized : undefined : undefined,
|
162
|
-
chatId: obj.chatId? obj.chatId._serialized ? obj.chatId._serialized : undefined : undefined,
|
163
|
-
to: obj.to? obj.to._serialized ? obj.to._serialized : undefined : undefined,
|
132
|
+
quotedParticipant: obj.quotedParticipant ? obj.quotedParticipant._serialized ? obj.quotedParticipant._serialized : undefined : undefined,
|
133
|
+
author: obj.author ? obj.author._serialized ? obj.author._serialized : undefined : undefined,
|
134
|
+
chatId: obj.chatId ? obj.chatId._serialized ? obj.chatId._serialized : undefined : undefined,
|
135
|
+
to: obj.to ? obj.to._serialized ? obj.to._serialized : undefined : undefined,
|
164
136
|
fromMe: obj.id.fromMe,
|
165
137
|
sender: obj["senderObj"] ? WAPI._serializeContactObj(obj["senderObj"]) : null,
|
166
138
|
timestamp: obj["t"],
|
@@ -253,7 +225,7 @@ window.WAPI.getContact = function (id) {
|
|
253
225
|
return window.WAPI._serializeContactObj(found);
|
254
226
|
};
|
255
227
|
|
256
|
-
window.WAPI.syncContacts = function() {
|
228
|
+
window.WAPI.syncContacts = function () {
|
257
229
|
Store.Contact.sync()
|
258
230
|
return true;
|
259
231
|
}
|
@@ -290,15 +262,15 @@ window.WAPI.getAllNewMessages = async function () {
|
|
290
262
|
|
291
263
|
// nnoo longer determined by x.ack==-1
|
292
264
|
window.WAPI.getAllUnreadMessages = async function () {
|
293
|
-
return Store.Chat.models.filter(chat=>chat.unreadCount&&chat.unreadCount>0).map(unreadChat=>unreadChat.msgs.models.slice(-1*unreadChat.unreadCount)).flat().map(WAPI._serializeMessageObj)
|
265
|
+
return Store.Chat.models.filter(chat => chat.unreadCount && chat.unreadCount > 0).map(unreadChat => unreadChat.msgs.models.slice(-1 * unreadChat.unreadCount)).flat().map(WAPI._serializeMessageObj)
|
294
266
|
}
|
295
267
|
|
296
268
|
window.WAPI.getIndicatedNewMessages = async function () {
|
297
|
-
return JSON.stringify(Store.Chat.models.filter(chat=>chat.unreadCount).map(chat=>{return {id:chat.id,indicatedNewMessages: chat.msgs.models.slice(Math.max(chat.msgs.length - chat.unreadCount, 0)).filter(msg
|
269
|
+
return JSON.stringify(Store.Chat.models.filter(chat => chat.unreadCount).map(chat => { return { id: chat.id, indicatedNewMessages: chat.msgs.models.slice(Math.max(chat.msgs.length - chat.unreadCount, 0)).filter(msg => !msg.id.fromMe) } }))
|
298
270
|
}
|
299
271
|
|
300
|
-
window.WAPI.getSingleProperty = function (namespace,id,property){
|
301
|
-
if(Store[namespace] && Store[namespace].get(id) && Object.keys(Store[namespace].get(id)).find(x=>x.includes(property))) return Store[namespace].get(id)[property];
|
272
|
+
window.WAPI.getSingleProperty = function (namespace, id, property) {
|
273
|
+
if (Store[namespace] && Store[namespace].get(id) && Object.keys(Store[namespace].get(id)).find(x => x.includes(property))) return Store[namespace].get(id)[property];
|
302
274
|
return 404
|
303
275
|
}
|
304
276
|
|
@@ -328,7 +300,7 @@ window.WAPI.getAllGroups = function () {
|
|
328
300
|
* returns {boolean}
|
329
301
|
*/
|
330
302
|
window.WAPI.sendChatstate = async function (state, chatId) {
|
331
|
-
switch(state) {
|
303
|
+
switch (state) {
|
332
304
|
case 0:
|
333
305
|
await window.Store.ChatStates.sendChatStateComposing(chatId);
|
334
306
|
break;
|
@@ -364,7 +336,7 @@ window.WAPI.getChat = function (id) {
|
|
364
336
|
* returns: {string,string} and string -"Hi, I am using WA"
|
365
337
|
*/
|
366
338
|
window.WAPI.getStatus = async (id) => {
|
367
|
-
return await Store.MyStatus.getStatus(id)
|
339
|
+
return await Store.MyStatus.getStatus(id)
|
368
340
|
}
|
369
341
|
|
370
342
|
window.WAPI.getChatByName = function (name) {
|
@@ -424,7 +396,7 @@ window.WAPI.sendLinkWithAutoPreview = async function (chatId, url, text) {
|
|
424
396
|
return false;
|
425
397
|
}
|
426
398
|
const linkPreview = await Store.WapQuery.queryLinkPreview(url);
|
427
|
-
return (await chatSend.sendMessage(text.includes(url) ? text : `${url}\n${text}`, {linkPreview}))=='OK'
|
399
|
+
return (await chatSend.sendMessage(text.includes(url) ? text : `${url}\n${text}`, { linkPreview })) == 'OK'
|
428
400
|
}
|
429
401
|
|
430
402
|
window.WAPI.sendMessageWithThumb = function (thumb, url, title, description, text, chatId) {
|
@@ -445,20 +417,20 @@ window.WAPI.sendMessageWithThumb = function (thumb, url, title, description, tex
|
|
445
417
|
|
446
418
|
window.WAPI.revokeGroupInviteLink = async function (chatId) {
|
447
419
|
var chat = Store.Chat.get(chatId);
|
448
|
-
if(!chat.isGroup) return false;
|
420
|
+
if (!chat.isGroup) return false;
|
449
421
|
await Store.GroupInvite.revokeGroupInvite(chat);
|
450
422
|
return true;
|
451
423
|
}
|
452
424
|
|
453
425
|
window.WAPI.getGroupInviteLink = async function (chatId) {
|
454
426
|
var chat = Store.Chat.get(chatId);
|
455
|
-
if(!chat.isGroup) return false;
|
427
|
+
if (!chat.isGroup) return false;
|
456
428
|
await Store.GroupInvite.queryGroupInviteCode(chat);
|
457
429
|
return `https://chat.whatsapp.com/${chat.inviteCode}`
|
458
430
|
}
|
459
431
|
|
460
|
-
window.WAPI.inviteInfo = async function(link){
|
461
|
-
return await Store.WapQuery.groupInviteInfo(link.split('\/').pop()).then(r=>r.status===200?WAPI.quickClean(r):r.status);
|
432
|
+
window.WAPI.inviteInfo = async function (link) {
|
433
|
+
return await Store.WapQuery.groupInviteInfo(link.split('\/').pop()).then(r => r.status === 200 ? WAPI.quickClean(r) : r.status);
|
462
434
|
}
|
463
435
|
|
464
436
|
window.WAPI.getNewId = function () {
|
@@ -542,9 +514,9 @@ window.WAPI.getUnreadMessagesInChat = function (id, includeMe, includeNotificati
|
|
542
514
|
*/
|
543
515
|
window.WAPI.loadEarlierMessages = async function (id) {
|
544
516
|
const chat = WAPI.getChat(id);
|
545
|
-
if(chat){
|
546
|
-
const someEarlierMessages = await chat.loadEarlierMsgs();
|
547
|
-
if(someEarlierMessages) return someEarlierMessages.map(WAPI._serializeMessageObj);
|
517
|
+
if (chat) {
|
518
|
+
const someEarlierMessages = await chat.loadEarlierMsgs();
|
519
|
+
if (someEarlierMessages) return someEarlierMessages.map(WAPI._serializeMessageObj);
|
548
520
|
}
|
549
521
|
return false;
|
550
522
|
};
|
@@ -645,19 +617,21 @@ window.WAPI.getGroupAdmins = async function (id) {
|
|
645
617
|
.map((admin) => admin.id._serialized);
|
646
618
|
};
|
647
619
|
|
648
|
-
WAPI.iAmAdmin = async function(){
|
649
|
-
return (await Promise.all(Store.GroupMetadata.models.map(({id})=>Store.GroupMetadata.find(id)))).filter(({participants})=>participants.iAmAdmin()||participants.iAmSuperAdmin()).map(({id})=>id._serialized);
|
620
|
+
WAPI.iAmAdmin = async function () {
|
621
|
+
return (await Promise.all(Store.GroupMetadata.models.map(({ id }) => Store.GroupMetadata.find(id)))).filter(({ participants }) => participants.iAmAdmin() || participants.iAmSuperAdmin()).map(({ id }) => id._serialized);
|
650
622
|
}
|
651
623
|
|
652
624
|
/**
|
653
625
|
* Returns an object with all of your host device details
|
654
626
|
*/
|
655
|
-
window.WAPI.getMe = function(){
|
656
|
-
return {
|
657
|
-
...
|
658
|
-
|
659
|
-
|
660
|
-
|
627
|
+
window.WAPI.getMe = function () {
|
628
|
+
return {
|
629
|
+
...WAPI.quickClean({
|
630
|
+
...Store.Contact.get(Store.Me.wid).attributes,
|
631
|
+
...Store.Me.attributes
|
632
|
+
}),
|
633
|
+
me: Store.Me.me
|
634
|
+
};
|
661
635
|
}
|
662
636
|
|
663
637
|
window.WAPI.isLoggedIn = function () {
|
@@ -668,13 +642,13 @@ window.WAPI.isLoggedIn = function () {
|
|
668
642
|
|
669
643
|
window.WAPI.isConnected = function () {
|
670
644
|
// Phone or connection Disconnected icon appears when phone or connection is disconnected
|
671
|
-
const isConnected=(document.querySelector('[data-testid="alert-phone"]') == null && document.querySelector('[data-testid="alert-computer"]') == null) ? true : false;
|
645
|
+
const isConnected = (document.querySelector('[data-testid="alert-phone"]') == null && document.querySelector('[data-testid="alert-computer"]') == null) ? true : false;
|
672
646
|
return isConnected;
|
673
647
|
};
|
674
648
|
|
675
649
|
//I dont think this will work for group chats.
|
676
650
|
window.WAPI.isChatOnline = async function (id) {
|
677
|
-
return Store.Chat.get(id)?await Store.Chat.get(id).presence.subscribe().then(_=>Store.Chat.get(id).presence.attributes.isOnline):false;
|
651
|
+
return Store.Chat.get(id) ? await Store.Chat.get(id).presence.subscribe().then(_ => Store.Chat.get(id).presence.attributes.isOnline) : false;
|
678
652
|
}
|
679
653
|
|
680
654
|
window.WAPI.processMessageObj = function (messageObj, includeMe, includeNotifications) {
|
@@ -694,8 +668,8 @@ window.WAPI.processMessageObj = function (messageObj, includeMe, includeNotifica
|
|
694
668
|
window.WAPI.getAllMessagesInChat = function (id, includeMe = false, includeNotifications = false, clean = false) {
|
695
669
|
const chat = WAPI.getChat(id);
|
696
670
|
let output = chat.msgs._models || [];
|
697
|
-
if(!includeMe) output =
|
698
|
-
if(!includeNotifications) output = output.filter(m=> !m.isNotification)
|
671
|
+
if (!includeMe) output = output.filter(m => !m.id.fromMe)
|
672
|
+
if (!includeNotifications) output = output.filter(m => !m.isNotification)
|
699
673
|
return (clean ? output.map(WAPI.quickClean) : output.map(WAPI._serializeMessageObj)) || [];
|
700
674
|
};
|
701
675
|
|
@@ -743,17 +717,17 @@ window.WAPI.getMessageById = function (id) {
|
|
743
717
|
result = WAPI.processMessageObj(msg, true, true);
|
744
718
|
}
|
745
719
|
} catch (err) { }
|
746
|
-
|
720
|
+
return result;
|
747
721
|
};
|
748
722
|
|
749
723
|
window.WAPI.sendMessageWithMentions = async function (ch, body) {
|
750
724
|
var chat = ch.id ? ch : Store.Chat.get(ch);
|
751
725
|
var chatId = chat.id._serialized;
|
752
726
|
var msgIveSent = chat.msgs.filter(msg => msg.__x_isSentByMe)[0];
|
753
|
-
if(!msgIveSent) return chat.sendMessage(body);
|
727
|
+
if (!msgIveSent) return chat.sendMessage(body);
|
754
728
|
var tempMsg = Object.create(msgIveSent);
|
755
729
|
var newId = window.WAPI.getNewMessageId(chatId);
|
756
|
-
var mentionedJidList = body.match(/@(\d*)/g).filter(x=>x.length>5).map(x=>Store.Contact.get(x.replace("@","")+"@c.us") ? new Store.WidFactory.createUserWid(x.replace("@","")) : '') || undefined;
|
730
|
+
var mentionedJidList = body.match(/@(\d*)/g).filter(x => x.length > 5).map(x => Store.Contact.get(x.replace("@", "") + "@c.us") ? new Store.WidFactory.createUserWid(x.replace("@", "")) : '') || undefined;
|
757
731
|
var extend = {
|
758
732
|
ack: 0,
|
759
733
|
id: newId,
|
@@ -764,7 +738,7 @@ window.WAPI.sendMessageWithMentions = async function (ch, body) {
|
|
764
738
|
isNewMsg: !0,
|
765
739
|
type: "chat",
|
766
740
|
body,
|
767
|
-
quotedMsg:null,
|
741
|
+
quotedMsg: null,
|
768
742
|
mentionedJidList
|
769
743
|
};
|
770
744
|
Object.assign(tempMsg, extend);
|
@@ -776,7 +750,7 @@ window.WAPI.sendMessageReturnId = async function (ch, body) {
|
|
776
750
|
var chat = ch.id ? ch : Store.Chat.get(ch);
|
777
751
|
var chatId = chat.id._serialized;
|
778
752
|
var msgIveSent = chat.msgs.filter(msg => msg.__x_isSentByMe)[0];
|
779
|
-
if(!msgIveSent) return chat.sendMessage(body);
|
753
|
+
if (!msgIveSent) return chat.sendMessage(body);
|
780
754
|
var tempMsg = Object.create(msgIveSent);
|
781
755
|
var newId = window.WAPI.getNewMessageId(chatId);
|
782
756
|
var extend = {
|
@@ -789,7 +763,7 @@ window.WAPI.sendMessageReturnId = async function (ch, body) {
|
|
789
763
|
isNewMsg: !0,
|
790
764
|
type: "chat",
|
791
765
|
body,
|
792
|
-
quotedMsg:null
|
766
|
+
quotedMsg: null
|
793
767
|
};
|
794
768
|
Object.assign(tempMsg, extend);
|
795
769
|
await Store.addAndSendMsgToChat(chat, tempMsg)
|
@@ -798,28 +772,28 @@ window.WAPI.sendMessageReturnId = async function (ch, body) {
|
|
798
772
|
|
799
773
|
|
800
774
|
window.WAPI.sendMessage = async function (id, message) {
|
801
|
-
if(id==='status@broadcast') return 'Not able to send message to broadcast';
|
775
|
+
if (id === 'status@broadcast') return 'Not able to send message to broadcast';
|
802
776
|
let chat = WAPI.getChat(id);
|
803
|
-
if((!chat && !id.includes('g') || chat.msgs.models.length == 0)) {
|
777
|
+
if ((!chat && !id.includes('g') || chat.msgs.models.length == 0)) {
|
804
778
|
var contact = WAPI.getContact(id)
|
805
|
-
if(!contact || !contact.isMyContact) return 'Not a contact';
|
779
|
+
if (!contact || !contact.isMyContact) return 'Not a contact';
|
806
780
|
await Store.Chat.find(Store.Contact.get(id).id)
|
807
781
|
chat = WAPI.getChat(id);
|
808
782
|
}
|
809
783
|
if (chat !== undefined) {
|
810
|
-
|
811
|
-
|
812
|
-
}
|
784
|
+
// return WAPI.sendMessageReturnId(chat,message).then(id=>{return id})
|
785
|
+
return await chat.sendMessage(message).then(_ => chat.lastReceivedKey._serialized);
|
786
|
+
}
|
813
787
|
return false;
|
814
|
-
|
788
|
+
};
|
815
789
|
|
816
790
|
|
817
791
|
window.WAPI.sendSeen = async function (id) {
|
818
792
|
if (!id) return false;
|
819
793
|
var chat = window.WAPI.getChat(id);
|
820
794
|
if (chat !== undefined) {
|
821
|
-
|
822
|
-
|
795
|
+
await Store.ReadSeen.sendSeen(chat, false);
|
796
|
+
return true;
|
823
797
|
}
|
824
798
|
return false;
|
825
799
|
};
|
@@ -827,8 +801,8 @@ window.WAPI.sendSeen = async function (id) {
|
|
827
801
|
window.WAPI.markAsUnread = async function (id) {
|
828
802
|
var chat = window.WAPI.getChat(id);
|
829
803
|
if (chat !== undefined) {
|
830
|
-
|
831
|
-
|
804
|
+
await Store.ReadSeen.markUnread(chat, true);
|
805
|
+
return true;
|
832
806
|
}
|
833
807
|
return false;
|
834
808
|
};
|
@@ -847,7 +821,7 @@ window.isChatMessage = function (message) {
|
|
847
821
|
}
|
848
822
|
|
849
823
|
window.WAPI.setPresence = function (available) {
|
850
|
-
if(available)Store._Presence.setPresenceAvailable();
|
824
|
+
if (available) Store._Presence.setPresenceAvailable();
|
851
825
|
else Store._Presence.setPresenceUnavailable();
|
852
826
|
}
|
853
827
|
|
@@ -943,7 +917,7 @@ window.WAPI.getProfilePicFromServer = function (id) {
|
|
943
917
|
}
|
944
918
|
|
945
919
|
window.WAPI.getProfilePicSmallFromId = async function (id) {
|
946
|
-
return await window.Store.ProfilePicThumb.find(id).then(async d=> {
|
920
|
+
return await window.Store.ProfilePicThumb.find(id).then(async d => {
|
947
921
|
if (d.img !== undefined) {
|
948
922
|
return await window.WAPI.downloadFileWithCredentials(d.img);
|
949
923
|
} else {
|
@@ -967,43 +941,43 @@ window.WAPI.getProfilePicFromId = async function (id) {
|
|
967
941
|
};
|
968
942
|
|
969
943
|
window.WAPI.downloadFileWithCredentials = async function (url) {
|
970
|
-
if(!axios || !url) return false;
|
971
|
-
const ab = (await axios.get(url,{responseType: 'arraybuffer'})).data
|
944
|
+
if (!axios || !url) return false;
|
945
|
+
const ab = (await axios.get(url, { responseType: 'arraybuffer' })).data
|
972
946
|
return btoa(new Uint8Array(ab).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
973
947
|
};
|
974
948
|
|
975
949
|
window.WAPI.downloadFile = async function (url) {
|
976
|
-
return await new Promise((resolve,reject) => {
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
950
|
+
return await new Promise((resolve, reject) => {
|
951
|
+
let xhr = new XMLHttpRequest();
|
952
|
+
xhr.onload = function () {
|
953
|
+
if (xhr.readyState == 4) {
|
954
|
+
if (xhr.status == 200) {
|
955
|
+
let reader = new FileReader();
|
956
|
+
reader.readAsDataURL(xhr.response);
|
957
|
+
reader.onload = function (e) {
|
958
|
+
resolve(reader.result.substr(reader.result.indexOf(',') + 1))
|
959
|
+
};
|
960
|
+
} else {
|
961
|
+
console.error(xhr.statusText);
|
962
|
+
}
|
986
963
|
} else {
|
987
|
-
console.
|
964
|
+
console.log(err);
|
965
|
+
resolve(false);
|
988
966
|
}
|
989
|
-
}
|
990
|
-
console.log(err);
|
991
|
-
resolve(false);
|
992
|
-
}
|
993
|
-
};
|
967
|
+
};
|
994
968
|
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
})
|
969
|
+
xhr.open("GET", url, true);
|
970
|
+
xhr.responseType = 'blob';
|
971
|
+
xhr.send(null);
|
972
|
+
})
|
999
973
|
};
|
1000
974
|
|
1001
975
|
window.WAPI.getBatteryLevel = function () {
|
1002
|
-
return
|
976
|
+
return 'DEPRECATED'
|
1003
977
|
};
|
1004
978
|
|
1005
979
|
window.WAPI.getIsPlugged = function () {
|
1006
|
-
return
|
980
|
+
return 'DEPRECATED'
|
1007
981
|
};
|
1008
982
|
|
1009
983
|
window.WAPI.deleteConversation = async function (chatId) {
|
@@ -1028,20 +1002,20 @@ window.WAPI.smartDeleteMessages = async function (chatId, messageArray, onlyLoca
|
|
1028
1002
|
messageArray = [messageArray];
|
1029
1003
|
}
|
1030
1004
|
|
1031
|
-
let messagesToDelete = messageArray.map(msgId => (typeof msgId == 'string')?window.Store.Msg.get(msgId):msgId).filter(x=>x);
|
1032
|
-
if(messagesToDelete.length==0) return true;
|
1033
|
-
let jobs = onlyLocal ? [conversation.sendDeleteMsgs(messagesToDelete,conversation)] :[
|
1034
|
-
conversation.sendRevokeMsgs(messagesToDelete.filter(msg=>msg.isSentByMe),conversation),
|
1035
|
-
conversation.sendDeleteMsgs(messagesToDelete.filter(msg
|
1005
|
+
let messagesToDelete = messageArray.map(msgId => (typeof msgId == 'string') ? window.Store.Msg.get(msgId) : msgId).filter(x => x);
|
1006
|
+
if (messagesToDelete.length == 0) return true;
|
1007
|
+
let jobs = onlyLocal ? [conversation.sendDeleteMsgs(messagesToDelete, conversation)] : [
|
1008
|
+
conversation.sendRevokeMsgs(messagesToDelete.filter(msg => msg.isSentByMe), conversation),
|
1009
|
+
conversation.sendDeleteMsgs(messagesToDelete.filter(msg => !msg.isSentByMe), conversation)
|
1036
1010
|
]
|
1037
|
-
return Promise.all(jobs).then(_=>true)
|
1011
|
+
return Promise.all(jobs).then(_ => true)
|
1038
1012
|
};
|
1039
1013
|
|
1040
1014
|
window.WAPI.deleteMessage = async function (chatId, messageArray, revoke = false) {
|
1041
1015
|
let userId = new window.Store.UserConstructor(chatId, { intentionallyUsePrivateConstructor: true });
|
1042
1016
|
let conversation = WAPI.getChat(userId);
|
1043
1017
|
|
1044
|
-
if (!conversation)return false;
|
1018
|
+
if (!conversation) return false;
|
1045
1019
|
|
1046
1020
|
if (!Array.isArray(messageArray)) {
|
1047
1021
|
messageArray = [messageArray];
|
@@ -1059,7 +1033,7 @@ window.WAPI.deleteMessage = async function (chatId, messageArray, revoke = false
|
|
1059
1033
|
};
|
1060
1034
|
|
1061
1035
|
window.WAPI.clearChat = async function (id) {
|
1062
|
-
return await Store.ChatUtil.sendClear(Store.Chat.get(id),true);
|
1036
|
+
return await Store.ChatUtil.sendClear(Store.Chat.get(id), true);
|
1063
1037
|
}
|
1064
1038
|
|
1065
1039
|
/**
|
@@ -1068,7 +1042,7 @@ window.WAPI.clearChat = async function (id) {
|
|
1068
1042
|
* @return boolean true: worked, false: didnt work (probably already in desired state)
|
1069
1043
|
*/
|
1070
1044
|
window.WAPI.archiveChat = async function (id, archive) {
|
1071
|
-
return await Store.Archive.setArchive(Store.Chat.get(id),archive).then(_=>true).catch(_=>false)
|
1045
|
+
return await Store.Archive.setArchive(Store.Chat.get(id), archive).then(_ => true).catch(_ => false)
|
1072
1046
|
}
|
1073
1047
|
|
1074
1048
|
/**
|
@@ -1084,17 +1058,17 @@ window.WAPI.archiveChat = async function (id, archive) {
|
|
1084
1058
|
* ]
|
1085
1059
|
* ``` or false if no valid vcards found
|
1086
1060
|
*/
|
1087
|
-
window.WAPI.getVCards = function(id) {
|
1061
|
+
window.WAPI.getVCards = function (id) {
|
1088
1062
|
var msg = Store.Msg.get(id);
|
1089
|
-
if(msg) {
|
1090
|
-
if(msg.type=='vcard') {
|
1063
|
+
if (msg) {
|
1064
|
+
if (msg.type == 'vcard') {
|
1091
1065
|
return [
|
1092
1066
|
{
|
1093
|
-
displayName:msg.subtype,
|
1094
|
-
vcard:msg.body
|
1067
|
+
displayName: msg.subtype,
|
1068
|
+
vcard: msg.body
|
1095
1069
|
}
|
1096
1070
|
]
|
1097
|
-
} else if (msg.type=='multi_vcard') {
|
1071
|
+
} else if (msg.type == 'multi_vcard') {
|
1098
1072
|
return msg.vcardList
|
1099
1073
|
} else return false;
|
1100
1074
|
} else {
|
@@ -1110,30 +1084,31 @@ window.WAPI.checkNumberStatus = async function (id) {
|
|
1110
1084
|
if (data.status == 200) data.numberExists = true
|
1111
1085
|
return data;
|
1112
1086
|
} catch (e) {
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1087
|
+
return window.WAPI._serializeNumberStatusObj({
|
1088
|
+
status: e,
|
1089
|
+
jid: id
|
1090
|
+
});
|
1117
1091
|
}
|
1118
1092
|
};
|
1119
1093
|
|
1120
1094
|
window.WAPI.onAnyMessage = callback => window.Store.Msg.on('add', (newMessage) => {
|
1121
1095
|
if (newMessage && newMessage.isNewMsg) {
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1096
|
+
if (!newMessage.clientUrl && (newMessage.mediaKeyTimestamp || newMessage.filehash)) {
|
1097
|
+
const cb = (msg) => {
|
1098
|
+
if (msg.id._serialized === newMessage.id._serialized && msg.clientUrl) {
|
1099
|
+
callback(WAPI.processMessageObj(msg, true, false));
|
1100
|
+
Store.Msg.off('change:isUnsentMedia', cb);
|
1101
|
+
}
|
1102
|
+
};
|
1103
|
+
Store.Msg.on('change:isUnsentMedia', cb);
|
1104
|
+
} else {
|
1105
|
+
let pm = window.WAPI.processMessageObj(newMessage, true, true);
|
1106
|
+
let message = pm ? JSON.parse(JSON.stringify(pm)) : WAPI.quickClean(newMessage.attributes);
|
1107
|
+
if (message) {
|
1108
|
+
callback(message)
|
1127
1109
|
}
|
1128
|
-
};
|
1129
|
-
Store.Msg.on('change:isUnsentMedia',cb);
|
1130
|
-
} else {
|
1131
|
-
let pm = window.WAPI.processMessageObj(newMessage, true, true);
|
1132
|
-
let message = pm? JSON.parse(JSON.stringify(pm)) : WAPI.quickClean(newMessage.attributes);
|
1133
|
-
if (message) {
|
1134
|
-
callback(message)
|
1135
1110
|
}
|
1136
|
-
}
|
1111
|
+
}
|
1137
1112
|
});
|
1138
1113
|
|
1139
1114
|
/**
|
@@ -1142,7 +1117,7 @@ window.WAPI.onAnyMessage = callback => window.Store.Msg.on('add', (newMessage) =
|
|
1142
1117
|
* @returns {boolean}
|
1143
1118
|
*/
|
1144
1119
|
window.WAPI.onStateChanged = function (callback) {
|
1145
|
-
window.Store.State.default.on('change:state', ({state})=>callback(state))
|
1120
|
+
window.Store.State.default.on('change:state', ({ state }) => callback(state))
|
1146
1121
|
return true;
|
1147
1122
|
}
|
1148
1123
|
|
@@ -1161,7 +1136,7 @@ window.WAPI.onStateChanged = function (callback) {
|
|
1161
1136
|
* "UNPAIRED"
|
1162
1137
|
* "UNPAIRED_IDLE"
|
1163
1138
|
*/
|
1164
|
-
window.WAPI.getState = function (){
|
1139
|
+
window.WAPI.getState = function () {
|
1165
1140
|
return Store.State.default.state;
|
1166
1141
|
}
|
1167
1142
|
|
@@ -1171,7 +1146,7 @@ window.WAPI.getState = function (){
|
|
1171
1146
|
* @returns {boolean}
|
1172
1147
|
*/
|
1173
1148
|
window.WAPI.onIncomingCall = function (callback) {
|
1174
|
-
window.Store.Call.on('add',callback);
|
1149
|
+
window.Store.Call.on('add', callback);
|
1175
1150
|
return true;
|
1176
1151
|
}
|
1177
1152
|
|
@@ -1182,11 +1157,11 @@ window.WAPI.onIncomingCall = function (callback) {
|
|
1182
1157
|
* @returns boolean true if it worked otherwise false
|
1183
1158
|
*/
|
1184
1159
|
window.WAPI.addOrRemoveLabels = async function (label, objectId, type) {
|
1185
|
-
var {id} = Store.Label.models.find(x=>x.id==label||x.name==label)
|
1160
|
+
var { id } = Store.Label.models.find(x => x.id == label || x.name == label)
|
1186
1161
|
var to = Store.Chat.get(objectId) || Store.Msg.get(objectId) || Store.Contact.get(objectId);
|
1187
|
-
if(!id || !to) return false;
|
1188
|
-
const {status} = await Store.Label.addOrRemoveLabels([{id,type}],[to]);
|
1189
|
-
return status===200;
|
1162
|
+
if (!id || !to) return false;
|
1163
|
+
const { status } = await Store.Label.addOrRemoveLabels([{ id, type }], [to]);
|
1164
|
+
return status === 200;
|
1190
1165
|
}
|
1191
1166
|
|
1192
1167
|
/**
|
@@ -1195,30 +1170,31 @@ window.WAPI.addOrRemoveLabels = async function (label, objectId, type) {
|
|
1195
1170
|
* @returns {boolean}
|
1196
1171
|
*/
|
1197
1172
|
window.WAPI.onAck = function (callback) {
|
1198
|
-
Store.Msg.on("change:ack", m=>callback(WAPI.quickClean(m)));
|
1173
|
+
Store.Msg.on("change:ack", m => callback(WAPI.quickClean(m)));
|
1199
1174
|
return true;
|
1200
1175
|
}
|
1201
1176
|
|
1202
1177
|
//returns an array of liveLocationChangeObjects
|
1203
1178
|
window.WAPI.forceUpdateLiveLocation = async function (chatId) {
|
1204
|
-
if(!Store.LiveLocation.get(chatId)) return false;
|
1205
|
-
return WAPI.quickClean(await Store.LiveLocation.update(chatId)).participants.map(l=>{
|
1179
|
+
if (!Store.LiveLocation.get(chatId)) return false;
|
1180
|
+
return WAPI.quickClean(await Store.LiveLocation.update(chatId)).participants.map(l => {
|
1206
1181
|
return {
|
1207
|
-
|
1208
|
-
|
1182
|
+
...l,
|
1183
|
+
msgId: l.msg.id._serialized
|
1209
1184
|
}
|
1210
|
-
|
1185
|
+
});
|
1211
1186
|
}
|
1212
1187
|
|
1213
1188
|
window.WAPI.onLiveLocation = function (chatId, callback) {
|
1214
1189
|
var lLChat = Store.LiveLocation.get(chatId);
|
1215
|
-
if(lLChat) {
|
1190
|
+
if (lLChat) {
|
1216
1191
|
var validLocs = lLChat.participants.validLocations();
|
1217
|
-
validLocs.map(x=>x.on('change:lastUpdated',(x,y,z)=>{
|
1218
|
-
const {id,lat,lng,accuracy,degrees,speed,lastUpdated}=x;
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1192
|
+
validLocs.map(x => x.on('change:lastUpdated', (x, y, z) => {
|
1193
|
+
const { id, lat, lng, accuracy, degrees, speed, lastUpdated } = x;
|
1194
|
+
const l = {
|
1195
|
+
id: id.toString(), lat, lng, accuracy, degrees, speed, lastUpdated
|
1196
|
+
};
|
1197
|
+
callback(l);
|
1222
1198
|
}));
|
1223
1199
|
return true;
|
1224
1200
|
} else {
|
@@ -1226,20 +1202,20 @@ window.WAPI.onLiveLocation = function (chatId, callback) {
|
|
1226
1202
|
}
|
1227
1203
|
}
|
1228
1204
|
|
1229
|
-
window.WAPI.onBattery = function(callback) {
|
1230
|
-
window.Store.Conn.on('change:battery', ({battery}) => callback(battery));
|
1205
|
+
window.WAPI.onBattery = function (callback) {
|
1206
|
+
// window.Store.Conn.on('change:battery', ({battery}) => callback(battery));
|
1231
1207
|
return true;
|
1232
1208
|
}
|
1233
1209
|
|
1234
|
-
window.WAPI.onPlugged = function(callback) {
|
1235
|
-
window.Store.Conn.on('change:plugged', ({plugged}) => callback(plugged));
|
1210
|
+
window.WAPI.onPlugged = function (callback) {
|
1211
|
+
// window.Store.Conn.on('change:plugged', ({plugged}) => callback(plugged));
|
1236
1212
|
return true;
|
1237
1213
|
}
|
1238
1214
|
|
1239
1215
|
/**
|
1240
1216
|
* A new approach to listening to add and remove events from groups. This takes only a callback and is prevents memory leaks
|
1241
1217
|
*/
|
1242
|
-
WAPI.onGlobalParicipantsChanged = function(callback) {
|
1218
|
+
WAPI.onGlobalParicipantsChanged = function (callback) {
|
1243
1219
|
const events = [
|
1244
1220
|
'change:isAdmin',
|
1245
1221
|
'remove',
|
@@ -1280,11 +1256,11 @@ WAPI.onGlobalParicipantsChanged = function(callback) {
|
|
1280
1256
|
*/
|
1281
1257
|
window.WAPI.onParticipantsChanged = function (groupId, callback) {
|
1282
1258
|
const subtypeEvents = [
|
1283
|
-
"invite"
|
1284
|
-
"add"
|
1285
|
-
"remove"
|
1286
|
-
"leave"
|
1287
|
-
"promote"
|
1259
|
+
"invite",
|
1260
|
+
"add",
|
1261
|
+
"remove",
|
1262
|
+
"leave",
|
1263
|
+
"promote",
|
1288
1264
|
"demote"
|
1289
1265
|
];
|
1290
1266
|
const events = [
|
@@ -1294,16 +1270,16 @@ window.WAPI.onParticipantsChanged = function (groupId, callback) {
|
|
1294
1270
|
]
|
1295
1271
|
const chat = window.Store.Chat.get(groupId);
|
1296
1272
|
chat.groupMetadata.participants.on('all', (eventName, eventData, extra) => {
|
1297
|
-
if(events.includes(eventName)) {
|
1273
|
+
if (events.includes(eventName)) {
|
1298
1274
|
let action = eventName;
|
1299
|
-
if(eventName=='change:isAdmin') {
|
1275
|
+
if (eventName == 'change:isAdmin') {
|
1300
1276
|
action = extra ? 'promote' : 'demote';
|
1301
1277
|
}
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1278
|
+
callback({
|
1279
|
+
by: undefined,
|
1280
|
+
action: action,
|
1281
|
+
who: eventData.id._serialized
|
1282
|
+
});
|
1307
1283
|
}
|
1308
1284
|
})
|
1309
1285
|
}
|
@@ -1317,11 +1293,11 @@ window.WAPI.onParticipantsChanged = function (groupId, callback) {
|
|
1317
1293
|
window.groupParticpiantsEvents = {};
|
1318
1294
|
window.WAPI._onParticipantsChanged = function (groupId, callback) {
|
1319
1295
|
const subtypeEvents = [
|
1320
|
-
"invite"
|
1321
|
-
"add"
|
1322
|
-
"remove"
|
1323
|
-
"leave"
|
1324
|
-
"promote"
|
1296
|
+
"invite",
|
1297
|
+
"add",
|
1298
|
+
"remove",
|
1299
|
+
"leave",
|
1300
|
+
"promote",
|
1325
1301
|
"demote"
|
1326
1302
|
];
|
1327
1303
|
const chat = window.Store.Chat.get(groupId);
|
@@ -1378,12 +1354,12 @@ window.WAPI._onParticipantsChanged = function (groupId, callback) {
|
|
1378
1354
|
* @param callback - function - Callback function to be called when a message acknowledgement changes. The callback returns 3 variables
|
1379
1355
|
* @returns {boolean}
|
1380
1356
|
*/
|
1381
|
-
window.WAPI.onAddedToGroup = function(callback){
|
1357
|
+
window.WAPI.onAddedToGroup = function (callback) {
|
1382
1358
|
Store.Chat.on('change:previewMessage', async event => {
|
1383
|
-
if(event.isGroup && event.previewMessage && event.previewMessage.type=='gp2' && event.previewMessage.subtype =='add' && event.previewMessage.recipients && event.previewMessage.recipients.map(x=>x._serialized).includes(Store.Me.wid._serialized)) {
|
1384
|
-
const tdiff = (Date.now()-Store.Msg.get(event.previewMessage.id._serialized).t*1000)/1000;
|
1385
|
-
if(tdiff<10.0) {
|
1386
|
-
console.log('added', tdiff,'seconds ago')
|
1359
|
+
if (event.isGroup && event.previewMessage && event.previewMessage.type == 'gp2' && event.previewMessage.subtype == 'add' && event.previewMessage.recipients && event.previewMessage.recipients.map(x => x._serialized).includes(Store.Me.wid._serialized)) {
|
1360
|
+
const tdiff = (Date.now() - Store.Msg.get(event.previewMessage.id._serialized).t * 1000) / 1000;
|
1361
|
+
if (tdiff < 10.0) {
|
1362
|
+
console.log('added', tdiff, 'seconds ago')
|
1387
1363
|
await WAPI.sendSeen(event.id);
|
1388
1364
|
callback(WAPI._serializeChatObj(Store.Chat.get(event.id)));
|
1389
1365
|
} else console.log('Not a new group add', event.id._serialized)
|
@@ -1410,42 +1386,42 @@ window.WAPI.getBufferedNewMessages = function () {
|
|
1410
1386
|
* - DHTGJUfFJAV9MxOpZO1fBZ
|
1411
1387
|
* @returns Promise<string | boolean> Either false if it didn't work, or the group id.
|
1412
1388
|
*/
|
1413
|
-
window.WAPI.joinGroupViaLink = async function(link){
|
1414
|
-
return await Store.WapQuery.acceptGroupInvite(link.split('\/').pop()).then(res=>res.status===200?res.gid._serialized:res.status);
|
1389
|
+
window.WAPI.joinGroupViaLink = async function (link) {
|
1390
|
+
return await Store.WapQuery.acceptGroupInvite(link.split('\/').pop()).then(res => res.status === 200 ? res.gid._serialized : res.status);
|
1415
1391
|
let code = link;
|
1416
1392
|
//is it a link? if not, assume it's a code, otherwise, process the link to get the code.
|
1417
|
-
if(link.includes('chat.whatsapp.com')) {
|
1418
|
-
if(!link.match(/chat.whatsapp.com\/([\w\d]*)/g).length) return false;
|
1419
|
-
code = link.match(/chat.whatsapp.com\/([\w\d]*)/g)[0].replace('chat.whatsapp.com\/','');
|
1393
|
+
if (link.includes('chat.whatsapp.com')) {
|
1394
|
+
if (!link.match(/chat.whatsapp.com\/([\w\d]*)/g).length) return false;
|
1395
|
+
code = link.match(/chat.whatsapp.com\/([\w\d]*)/g)[0].replace('chat.whatsapp.com\/', '');
|
1420
1396
|
}
|
1421
1397
|
const group = await Store.GroupInvite.joinGroupViaInvite(code);
|
1422
|
-
if(!group.id) return false;
|
1398
|
+
if (!group.id) return false;
|
1423
1399
|
return group.id._serialized
|
1424
1400
|
}
|
1425
1401
|
|
1426
1402
|
window.WAPI.sendImage = async function (imgBase64, chatid, filename, caption, quotedMsg, waitForKey, ptt) {
|
1427
|
-
if(!chatid.includes('@g')
|
1403
|
+
if (!chatid.includes('@g') && !chatid.includes('@c')) return false;
|
1428
1404
|
let extras = {};
|
1429
|
-
if(quotedMsg){
|
1405
|
+
if (quotedMsg) {
|
1430
1406
|
if (typeof quotedMsg !== "object") quotedMsg = Store.Msg.get(quotedMsg);
|
1431
1407
|
extras = {
|
1432
1408
|
quotedMsg,
|
1433
1409
|
quotedParticipant: quotedMsg.author || quotedMsg.from,
|
1434
|
-
quotedStanzaID:quotedMsg.id.id
|
1410
|
+
quotedStanzaID: quotedMsg.id.id
|
1435
1411
|
};
|
1436
1412
|
}
|
1437
1413
|
return await Store.Chat.find(chatid).then(async (chat) => {
|
1438
1414
|
var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename);
|
1439
|
-
return await window.WAPI.procFiles(chat,mediaBlob).then(async mc => {
|
1415
|
+
return await window.WAPI.procFiles(chat, mediaBlob).then(async mc => {
|
1440
1416
|
var media = mc.models[0];
|
1441
|
-
if(ptt) media.mediaPrep._mediaData.type = 'ptt';
|
1442
|
-
await media.sendToChat(chat, { caption
|
1443
|
-
return waitForKey ? await new Promise(async (resolve,reject) => {
|
1444
|
-
const cb = msg=>{
|
1445
|
-
if(media.attributes.file.size === msg.size) resolve(msg.id._serialized);
|
1446
|
-
Store.Msg.off('change:clientUrl',cb);
|
1417
|
+
if (ptt) media.mediaPrep._mediaData.type = 'ptt';
|
1418
|
+
await media.sendToChat(chat, { caption, ...extras });
|
1419
|
+
return waitForKey ? await new Promise(async (resolve, reject) => {
|
1420
|
+
const cb = msg => {
|
1421
|
+
if (media.attributes.file.size === msg.size) resolve(msg.id._serialized);
|
1422
|
+
Store.Msg.off('change:clientUrl', cb);
|
1447
1423
|
};
|
1448
|
-
Store.Msg.on('change:clientUrl',cb);
|
1424
|
+
Store.Msg.on('change:clientUrl', cb);
|
1449
1425
|
}) : true
|
1450
1426
|
});
|
1451
1427
|
});
|
@@ -1459,8 +1435,7 @@ window.WAPI.sendImage = async function (imgBase64, chatid, filename, caption, qu
|
|
1459
1435
|
* @param newName - string the new name to set as profile name
|
1460
1436
|
*/
|
1461
1437
|
window.WAPI.setMyName = async function (newName) {
|
1462
|
-
|
1463
|
-
return (await Store.Versions.default[12].setPushname(newName)).status===200;
|
1438
|
+
return require("WAWebSetPushnameConnAction").setPushname(newName)
|
1464
1439
|
}
|
1465
1440
|
|
1466
1441
|
/** Change the icon for the group chat
|
@@ -1468,9 +1443,9 @@ window.WAPI.setMyName = async function (newName) {
|
|
1468
1443
|
* @param imgData 'data:image/jpeg;base64,...` The base 64 data uri
|
1469
1444
|
* @returns boolean true if it was set, false if it didn't work. It usually doesn't work if the image file is too big.
|
1470
1445
|
*/
|
1471
|
-
window.WAPI.setGroupIcon = async function(groupId, imgData) {
|
1472
|
-
const {status} = await Store.WapQuery.sendSetPicture(groupId,imgData,imgData);
|
1473
|
-
return status==200;
|
1446
|
+
window.WAPI.setGroupIcon = async function (groupId, imgData) {
|
1447
|
+
const { status } = await Store.WapQuery.sendSetPicture(groupId, imgData, imgData);
|
1448
|
+
return status == 200;
|
1474
1449
|
}
|
1475
1450
|
|
1476
1451
|
/**
|
@@ -1483,35 +1458,35 @@ window.WAPI.setMyStatus = function (newStatus) {
|
|
1483
1458
|
|
1484
1459
|
window.WAPI.sendVideoAsGif = async function (imgBase64, chatid, filename, caption, quotedMsg) {
|
1485
1460
|
let extras = {};
|
1486
|
-
if(quotedMsg){
|
1461
|
+
if (quotedMsg) {
|
1487
1462
|
if (typeof quotedMsg !== "object") quotedMsg = Store.Msg.get(quotedMsg);
|
1488
1463
|
extras = {
|
1489
1464
|
quotedMsg,
|
1490
1465
|
quotedParticipant: quotedMsg.author || quotedMsg.from,
|
1491
|
-
quotedStanzaID:quotedMsg.id.id
|
1466
|
+
quotedStanzaID: quotedMsg.id.id
|
1492
1467
|
};
|
1493
1468
|
}
|
1494
1469
|
// create new chat
|
1495
1470
|
return await Store.Chat.find(chatid).then(async (chat) => {
|
1496
1471
|
var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename);
|
1497
1472
|
var mc = new Store.MediaCollection(chat);
|
1498
|
-
return await window.WAPI.procFiles(chat,mediaBlob).then(async mc => {
|
1473
|
+
return await window.WAPI.procFiles(chat, mediaBlob).then(async mc => {
|
1499
1474
|
var media = mc.models[0];
|
1500
1475
|
media.mediaPrep._mediaData.isGif = true;
|
1501
1476
|
media.mediaPrep._mediaData.gifAttribution = 1;
|
1502
|
-
await media.mediaPrep.sendToChat(chat, { caption
|
1477
|
+
await media.mediaPrep.sendToChat(chat, { caption, ...extras });
|
1503
1478
|
return chat.lastReceivedKey._serialized;
|
1504
1479
|
});
|
1505
1480
|
});
|
1506
1481
|
}
|
1507
1482
|
|
1508
|
-
window.WAPI.refreshBusinessProfileProducts = async function (){
|
1509
|
-
await Promise.all(Store.BusinessProfile.models.map(async x=>{
|
1510
|
-
try{
|
1511
|
-
|
1512
|
-
} catch(error){}
|
1513
|
-
|
1514
|
-
|
1483
|
+
window.WAPI.refreshBusinessProfileProducts = async function () {
|
1484
|
+
await Promise.all(Store.BusinessProfile.models.map(async x => {
|
1485
|
+
try {
|
1486
|
+
await Store.Catalog.findCarouselCatalog(x.id._serialized)
|
1487
|
+
} catch (error) { }
|
1488
|
+
}));
|
1489
|
+
return true;
|
1515
1490
|
}
|
1516
1491
|
|
1517
1492
|
/**
|
@@ -1521,24 +1496,24 @@ window.WAPI.refreshBusinessProfileProducts = async function (){
|
|
1521
1496
|
* @returns None
|
1522
1497
|
*/
|
1523
1498
|
window.WAPI.getBusinessProfilesProducts = async function (id) {
|
1524
|
-
try{
|
1525
|
-
if(!Store.Catalog.get(id)) await Store.Catalog.findCarouselCatalog(id)
|
1499
|
+
try {
|
1500
|
+
if (!Store.Catalog.get(id)) await Store.Catalog.findCarouselCatalog(id)
|
1526
1501
|
const catalog = Store.Catalog.get(id);
|
1527
1502
|
if (catalog.productCollection && catalog.productCollection._models.length)
|
1528
|
-
|
1503
|
+
return JSON.parse(JSON.stringify(catalog.productCollection._models));
|
1529
1504
|
else return [];
|
1530
|
-
} catch(error){
|
1505
|
+
} catch (error) {
|
1531
1506
|
return false;
|
1532
1507
|
}
|
1533
1508
|
};
|
1534
1509
|
|
1535
1510
|
|
1536
|
-
window.WAPI.procFiles= async function(chat, blobs) {
|
1511
|
+
window.WAPI.procFiles = async function (chat, blobs) {
|
1537
1512
|
if (!Array.isArray(blobs)) {
|
1538
1513
|
blobs = [blobs];
|
1539
1514
|
}
|
1540
1515
|
var mc = new Store.MediaCollection(chat);
|
1541
|
-
await mc.processFiles((Debug.VERSION === '0.4.613')?blobs:blobs.map(blob=>{return{file:blob}})
|
1516
|
+
await mc.processFiles((Debug.VERSION === '0.4.613') ? blobs : blobs.map(blob => { return { file: blob } }), chat, 1);
|
1542
1517
|
return mc
|
1543
1518
|
}
|
1544
1519
|
/**
|
@@ -1578,7 +1553,7 @@ window.WAPI.sendImageWithProduct = async function (imgBase64, chatid, caption, b
|
|
1578
1553
|
var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, "filename.jpg");
|
1579
1554
|
// var mc = new Store.MediaCollection(chat);
|
1580
1555
|
// mc.processFiles([mediaBlob], chat, 1)
|
1581
|
-
return await window.WAPI.procFiles(chat,mediaBlob).then(async mc => {
|
1556
|
+
return await window.WAPI.procFiles(chat, mediaBlob).then(async mc => {
|
1582
1557
|
var media = mc.models[0];
|
1583
1558
|
Object.entries(temp.productMsgOptions).map(([k, v]) => media.mediaPrep._mediaData[k] = v)
|
1584
1559
|
await media.mediaPrep.sendToChat(chat, temp);
|
@@ -1627,10 +1602,10 @@ window.WAPI.sendContact = function (to, contact) {
|
|
1627
1602
|
/**
|
1628
1603
|
* Ghost forwarding is like a normal forward but as if it were sent from the host phone.
|
1629
1604
|
*/
|
1630
|
-
window.WAPI.ghostForward = async function(chatId, messageId) {
|
1631
|
-
if(!chatId.includes('@g')
|
1605
|
+
window.WAPI.ghostForward = async function (chatId, messageId) {
|
1606
|
+
if (!chatId.includes('@g') && !chatId.includes('@c')) return false;
|
1632
1607
|
var chat = Store.Chat.get(chatId);
|
1633
|
-
if(!Store.Msg.get(messageId)) return false;
|
1608
|
+
if (!Store.Msg.get(messageId)) return false;
|
1634
1609
|
var tempMsg = Object.create(Store.Msg.get(messageId));
|
1635
1610
|
var newId = window.WAPI.getNewMessageId(chatId);
|
1636
1611
|
var extend = {
|
@@ -1646,7 +1621,7 @@ window.WAPI.ghostForward = async function(chatId, messageId) {
|
|
1646
1621
|
};
|
1647
1622
|
Object.assign(tempMsg, extend);
|
1648
1623
|
const res = await Promise.all(Store.addAndSendMsgToChat(chat, extend))
|
1649
|
-
return res[1]=='success';
|
1624
|
+
return res[1] == 'success';
|
1650
1625
|
}
|
1651
1626
|
|
1652
1627
|
|
@@ -1716,7 +1691,7 @@ window.WAPI.simulateTyping = async function (chatId, on) {
|
|
1716
1691
|
window.WAPI.sendLocation = async function (chatId, lat, lng, loc) {
|
1717
1692
|
loc = loc || '';
|
1718
1693
|
var chat = Store.Chat.get(chatId);
|
1719
|
-
if(!chat) return false;
|
1694
|
+
if (!chat) return false;
|
1720
1695
|
var tempMsg = Object.create(Store.Msg.models.filter(msg => msg.__x_isSentByMe && !msg.quotedMsg)[0]);
|
1721
1696
|
var newId = window.WAPI.getNewMessageId(chatId);
|
1722
1697
|
var extend = {
|
@@ -1731,24 +1706,24 @@ window.WAPI.sendLocation = async function (chatId, lat, lng, loc) {
|
|
1731
1706
|
lat,
|
1732
1707
|
lng,
|
1733
1708
|
loc,
|
1734
|
-
clientUrl:undefined,
|
1735
|
-
directPath:undefined,
|
1736
|
-
filehash:undefined,
|
1737
|
-
uploadhash:undefined,
|
1738
|
-
mediaKey:undefined,
|
1739
|
-
isQuotedMsgAvailable:false,
|
1740
|
-
invis:false,
|
1741
|
-
mediaKeyTimestamp:undefined,
|
1742
|
-
mimetype:undefined,
|
1743
|
-
height:undefined,
|
1744
|
-
width:undefined,
|
1745
|
-
ephemeralStartTimestamp:undefined,
|
1746
|
-
body:undefined,
|
1747
|
-
mediaData:undefined,
|
1709
|
+
clientUrl: undefined,
|
1710
|
+
directPath: undefined,
|
1711
|
+
filehash: undefined,
|
1712
|
+
uploadhash: undefined,
|
1713
|
+
mediaKey: undefined,
|
1714
|
+
isQuotedMsgAvailable: false,
|
1715
|
+
invis: false,
|
1716
|
+
mediaKeyTimestamp: undefined,
|
1717
|
+
mimetype: undefined,
|
1718
|
+
height: undefined,
|
1719
|
+
width: undefined,
|
1720
|
+
ephemeralStartTimestamp: undefined,
|
1721
|
+
body: undefined,
|
1722
|
+
mediaData: undefined,
|
1748
1723
|
isQuotedMsgAvailable: false
|
1749
1724
|
};
|
1750
1725
|
Object.assign(tempMsg, extend);
|
1751
|
-
return (await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1]==='success' ? newId._serialized : false;
|
1726
|
+
return (await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1] === 'success' ? newId._serialized : false;
|
1752
1727
|
};
|
1753
1728
|
|
1754
1729
|
/**
|
@@ -1772,38 +1747,38 @@ window.WAPI.sendVCard = async function (chatId, vcard, contactName, contactNumbe
|
|
1772
1747
|
to: chatId,
|
1773
1748
|
isNewMsg: !0,
|
1774
1749
|
type: "vcard",
|
1775
|
-
clientUrl:undefined,
|
1776
|
-
directPath:undefined,
|
1777
|
-
filehash:undefined,
|
1778
|
-
uploadhash:undefined,
|
1779
|
-
mediaKey:undefined,
|
1780
|
-
isQuotedMsgAvailable:false,
|
1781
|
-
invis:false,
|
1782
|
-
mediaKeyTimestamp:undefined,
|
1783
|
-
mimetype:undefined,
|
1784
|
-
height:undefined,
|
1785
|
-
width:undefined,
|
1786
|
-
ephemeralStartTimestamp:undefined,
|
1787
|
-
body:contactNumber?vcard.replace('TEL;TYPE=WORK,VOICE:'
|
1788
|
-
mediaData:undefined,
|
1750
|
+
clientUrl: undefined,
|
1751
|
+
directPath: undefined,
|
1752
|
+
filehash: undefined,
|
1753
|
+
uploadhash: undefined,
|
1754
|
+
mediaKey: undefined,
|
1755
|
+
isQuotedMsgAvailable: false,
|
1756
|
+
invis: false,
|
1757
|
+
mediaKeyTimestamp: undefined,
|
1758
|
+
mimetype: undefined,
|
1759
|
+
height: undefined,
|
1760
|
+
width: undefined,
|
1761
|
+
ephemeralStartTimestamp: undefined,
|
1762
|
+
body: contactNumber ? vcard.replace('TEL;TYPE=WORK,VOICE:', `TEL;TYPE=WORK,VOICE;waid=${contactNumber}:`) : vcard,
|
1763
|
+
mediaData: undefined,
|
1789
1764
|
isQuotedMsgAvailable: false,
|
1790
1765
|
subtype: contactName
|
1791
1766
|
};
|
1792
1767
|
Object.assign(tempMsg, extend);
|
1793
|
-
return (await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1]=="success"
|
1768
|
+
return (await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1] == "success"
|
1794
1769
|
};
|
1795
1770
|
|
1796
1771
|
window.WAPI.reply = async function (chatId, body, quotedMsg) {
|
1797
1772
|
if (typeof quotedMsg !== "object") quotedMsg = Store.Msg.get(quotedMsg)
|
1798
1773
|
var chat = Store.Chat.get(chatId);
|
1799
|
-
if(!chat) return false;
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1774
|
+
if (!chat) return false;
|
1775
|
+
let extras = {};
|
1776
|
+
if (quotedMsg) {
|
1777
|
+
extras = {
|
1778
|
+
quotedParticipant: quotedMsg.author || quotedMsg.from,
|
1779
|
+
quotedStanzaID: quotedMsg.id.id
|
1780
|
+
};
|
1781
|
+
}
|
1807
1782
|
var tempMsg = Object.create(Store.Msg.models.filter(msg => msg.__x_isSentByMe && !msg.quotedMsg)[0]);
|
1808
1783
|
var newId = window.WAPI.getNewMessageId(chatId);
|
1809
1784
|
var extend = {
|
@@ -1812,7 +1787,7 @@ window.WAPI.reply = async function (chatId, body, quotedMsg) {
|
|
1812
1787
|
local: !0,
|
1813
1788
|
self: "out",
|
1814
1789
|
t: parseInt(new Date().getTime() / 1000),
|
1815
|
-
to:
|
1790
|
+
to: new Store.WidFactory.createWid(chatId),
|
1816
1791
|
isNewMsg: !0,
|
1817
1792
|
type: "chat",
|
1818
1793
|
quotedMsg,
|
@@ -1821,7 +1796,7 @@ window.WAPI.reply = async function (chatId, body, quotedMsg) {
|
|
1821
1796
|
};
|
1822
1797
|
Object.assign(tempMsg, extend);
|
1823
1798
|
const res = await Promise.all(await Store.addAndSendMsgToChat(chat, tempMsg));
|
1824
|
-
if(res[1]!='success') return false;
|
1799
|
+
if (res[1] != 'success') return false;
|
1825
1800
|
return res[0].id._serialized
|
1826
1801
|
};
|
1827
1802
|
|
@@ -1878,7 +1853,7 @@ window.WAPI._sendVCard = function (chatId, vcard) {
|
|
1878
1853
|
t: parseInt(new Date().getTime() / 1000),
|
1879
1854
|
to: chatId,
|
1880
1855
|
isNewMsg: !0,
|
1881
|
-
isQuotedMsgAvailable:false,
|
1856
|
+
isQuotedMsgAvailable: false,
|
1882
1857
|
};
|
1883
1858
|
|
1884
1859
|
if (Array.isArray(vcard)) {
|
@@ -1976,7 +1951,7 @@ window.WAPI.demoteParticipant = async function (idGroup, idParticipant) {
|
|
1976
1951
|
const demote = chat.groupMetadata.participants.get(idParticipant);
|
1977
1952
|
await window.Store.Participants.demoteParticipants(chat, [demote])
|
1978
1953
|
return true
|
1979
|
-
|
1954
|
+
|
1980
1955
|
}
|
1981
1956
|
|
1982
1957
|
/**
|
@@ -1988,33 +1963,33 @@ window.WAPI.demoteParticipant = async function (idGroup, idParticipant) {
|
|
1988
1963
|
*/
|
1989
1964
|
window.WAPI._sendSticker = async function (sticker, chatId, metadata) {
|
1990
1965
|
var chat = Store.Chat.get(chatId)
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
1966
|
+
let stick = new window.Store.Sticker.modelClass();
|
1967
|
+
stick.__x_clientUrl = sticker.clientUrl;
|
1968
|
+
stick.__x_filehash = sticker.filehash;
|
1969
|
+
stick.__x_id = sticker.filehash;
|
1970
|
+
stick.__x_uploadhash = sticker.uploadhash;
|
1971
|
+
stick.__x_mediaKey = sticker.mediaKey;
|
1972
|
+
stick.__x_initialized = false;
|
1973
|
+
stick.__x_mediaData.mediaStage = 'INIT';
|
1974
|
+
stick.mimetype = 'image/webp';
|
1975
|
+
stick.height = (metadata && metadata.height) ? metadata.height : 512;
|
1976
|
+
stick.width = (metadata && metadata.width) ? metadata.width : 512;
|
1977
|
+
await stick.initialize();
|
1978
|
+
return await stick.sendToChat(chat);
|
2004
1979
|
};
|
2005
1980
|
|
2006
1981
|
window.WAPI.getFileHash = async (data) => {
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
1982
|
+
let buffer = await data.arrayBuffer();
|
1983
|
+
var sha = new jsSHA("SHA-256", "ARRAYBUFFER");
|
1984
|
+
sha.update(buffer);
|
1985
|
+
return sha.getHash("B64");
|
2011
1986
|
};
|
2012
1987
|
|
2013
1988
|
window.WAPI.generateMediaKey = async (length) => {
|
2014
1989
|
var result = '';
|
2015
1990
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
2016
1991
|
var charactersLength = characters.length;
|
2017
|
-
for (
|
1992
|
+
for (var i = 0; i < length; i++) {
|
2018
1993
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
2019
1994
|
}
|
2020
1995
|
return result;
|
@@ -2024,8 +1999,8 @@ window.WAPI.generateMediaKey = async (length) => {
|
|
2024
1999
|
* @param type: The type of file. {'audio' | 'sticker' | 'video' | 'product' | 'document' | 'gif' | 'image' | 'ptt' | 'template' | 'history' | 'ppic'}
|
2025
2000
|
* @param blob: file
|
2026
2001
|
*/
|
2027
|
-
window.WAPI.encryptAndUploadFile = async function (type, blob) {
|
2028
|
-
let filehash = await window.WAPI.getFileHash(blob);
|
2002
|
+
window.WAPI.encryptAndUploadFile = async function (type, blob) {
|
2003
|
+
let filehash = await window.WAPI.getFileHash(blob);
|
2029
2004
|
let mediaKey = await window.WAPI.generateMediaKey(32);
|
2030
2005
|
let controller = new AbortController();
|
2031
2006
|
let signal = controller.signal;
|
@@ -2050,9 +2025,9 @@ window.WAPI.encryptAndUploadFile = async function (type, blob) {
|
|
2050
2025
|
* @param {*} chatId '000000000000@c.us'
|
2051
2026
|
* @param metadata about the image. Based on [sharp metadata](https://sharp.pixelplumbing.com/api-input#metadata)
|
2052
2027
|
*/
|
2053
|
-
window.WAPI.sendImageAsSticker = async function (imageBase64,chatId, metadata) {
|
2028
|
+
window.WAPI.sendImageAsSticker = async function (imageBase64, chatId, metadata) {
|
2054
2029
|
let mediaBlob = await window.WAPI.base64ImageToFile(
|
2055
|
-
'data:image/webp;base64,'+imageBase64,
|
2030
|
+
'data:image/webp;base64,' + imageBase64,
|
2056
2031
|
'file.webp'
|
2057
2032
|
);
|
2058
2033
|
let encrypted = await window.WAPI.encryptAndUploadFile("sticker", mediaBlob);
|
@@ -2064,87 +2039,87 @@ This will dump all possible stickers into the chat. ONLY FOR TESTING. THIS IS RE
|
|
2064
2039
|
*/
|
2065
2040
|
window.WAPI._STICKERDUMP = async function (chatId) {
|
2066
2041
|
var chat = Store.Chat.get(chatId);
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
return await Promise.race(Store.StickerPack.models.forEach(pack=>pack.stickers.fetch().then(_=>pack.stickers.models.forEach(stkr => stkr.sendToChat(chat))))).catch(e=>{})
|
2042
|
+
let prIdx = await Store.StickerPack.pageWithIndex(0);
|
2043
|
+
await Store.StickerPack.fetchAt(0);
|
2044
|
+
await Store.StickerPack._pageFetchPromises[prIdx];
|
2045
|
+
return await Promise.race(Store.StickerPack.models.forEach(pack => pack.stickers.fetch().then(_ => pack.stickers.models.forEach(stkr => stkr.sendToChat(chat))))).catch(e => { })
|
2071
2046
|
}
|
2072
2047
|
|
2073
2048
|
|
2074
2049
|
window.WAPI.getLastSeen = async function (id) {
|
2075
|
-
if(!Store.Chat.get(id)) return false;
|
2076
|
-
let {presence} = Store.Chat.get(id)
|
2050
|
+
if (!Store.Chat.get(id)) return false;
|
2051
|
+
let { presence } = Store.Chat.get(id)
|
2077
2052
|
await presence.subscribe();
|
2078
2053
|
return presence.chatstate.t;
|
2079
|
-
|
2080
|
-
|
2081
|
-
window.WAPI.getUseHereString = async function() {
|
2082
|
-
if (!window.l10n.localeStrings['en']){
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2054
|
+
}
|
2055
|
+
|
2056
|
+
window.WAPI.getUseHereString = async function () {
|
2057
|
+
if (!window.l10n.localeStrings['en']) {
|
2058
|
+
const originalLocale = window.l10n.getLocale();
|
2059
|
+
await window.l10n.init('en');
|
2060
|
+
await window.l10n.init(originalLocale)
|
2061
|
+
}
|
2062
|
+
return window.l10n.localeStrings[window.l10n.getLocale()][0][window.l10n.localeStrings.en[0].findIndex(x => x.toLowerCase() === 'use here')]
|
2063
|
+
}
|
2064
|
+
|
2065
|
+
window.WAPI.getAmountOfLoadedMessages = function () {
|
2091
2066
|
return Store.Msg.models.length;
|
2092
2067
|
}
|
2093
2068
|
|
2094
|
-
WAPI.getChatWithNonContacts = async function(){
|
2095
|
-
return Store.Chat.models.map(chat=>chat.contact && !chat.contact.isMyContact ?chat.contact :null).filter(x=>x && !x.isGroup).map(WAPI._serializeContactObj)
|
2069
|
+
WAPI.getChatWithNonContacts = async function () {
|
2070
|
+
return Store.Chat.models.map(chat => chat.contact && !chat.contact.isMyContact ? chat.contact : null).filter(x => x && !x.isGroup).map(WAPI._serializeContactObj)
|
2096
2071
|
}
|
2097
2072
|
|
2098
|
-
window.WAPI.cutMsgCache = function (){
|
2099
|
-
Store.Msg.models.map(msg=>Store.Msg.remove(msg));
|
2073
|
+
window.WAPI.cutMsgCache = function () {
|
2074
|
+
Store.Msg.models.map(msg => Store.Msg.remove(msg));
|
2100
2075
|
return true;
|
2101
2076
|
}
|
2102
2077
|
|
2103
|
-
window.WAPI.getHostNumber = function() {
|
2078
|
+
window.WAPI.getHostNumber = function () {
|
2104
2079
|
return WAPI.getMe().me.user;
|
2105
2080
|
}
|
2106
2081
|
|
2107
2082
|
//All of the following features can be unlocked using a license key: https://github.com/open-wa/wa-automate-nodejs#license-key
|
2108
|
-
window.WAPI.getStoryStatusByTimeStamp = function(){return false;}
|
2109
|
-
window.WAPI.deleteAllStatus = function(){return false;}
|
2110
|
-
window.WAPI.getMyStatusArray = function(){return false;}
|
2111
|
-
window.WAPI.deleteStatus = function(){return false;}
|
2112
|
-
window.WAPI.setGroupToAdminsOnly = function(){return false;}
|
2113
|
-
window.WAPI.setGroupEditToAdminsOnly = function(){return false;}
|
2114
|
-
window.WAPI.postTextStatus = function(){return false;}
|
2115
|
-
window.WAPI.postImageStatus = function(){return false;}
|
2116
|
-
window.WAPI.postVideoStatus = function(){return false;}
|
2117
|
-
window.WAPI.onRemovedFromGroup = function(){return false;}
|
2118
|
-
window.WAPI.onContactAdded = function(){return false;}
|
2119
|
-
window.WAPI.sendReplyWithMentions = function(){return false;}
|
2120
|
-
window.WAPI.clearAllChats = function(){return false;}
|
2121
|
-
window.WAPI.getCommonGroups = function(){return false;}
|
2122
|
-
window.WAPI.setChatBackgroundColourHex = function(){return false;}
|
2123
|
-
window.WAPI.darkMode = function(){return false;}
|
2124
|
-
window.WAPI.onChatOpened = function(){return false;}
|
2125
|
-
window.WAPI.onStory = function(){return false;}
|
2126
|
-
window.WAPI.getStoryViewers = function(){return false;}
|
2127
|
-
window.WAPI.onChatState = function(){return false;}
|
2128
|
-
window.WAPI.getStickerDecryptable = function(){return false;}
|
2129
|
-
window.WAPI.forceStaleMediaUpdate = function(){return false;}
|
2130
|
-
window.WAPI.setProfilePic = function(){return false;}
|
2131
|
-
window.WAPI.setGroupDescription = function(){return false;}
|
2132
|
-
window.WAPI.setGroupTitle = function(){return false;}
|
2133
|
-
window.WAPI.tagEveryone = function(){return false;}
|
2083
|
+
window.WAPI.getStoryStatusByTimeStamp = function () { return false; }
|
2084
|
+
window.WAPI.deleteAllStatus = function () { return false; }
|
2085
|
+
window.WAPI.getMyStatusArray = function () { return false; }
|
2086
|
+
window.WAPI.deleteStatus = function () { return false; }
|
2087
|
+
window.WAPI.setGroupToAdminsOnly = function () { return false; }
|
2088
|
+
window.WAPI.setGroupEditToAdminsOnly = function () { return false; }
|
2089
|
+
window.WAPI.postTextStatus = function () { return false; }
|
2090
|
+
window.WAPI.postImageStatus = function () { return false; }
|
2091
|
+
window.WAPI.postVideoStatus = function () { return false; }
|
2092
|
+
window.WAPI.onRemovedFromGroup = function () { return false; }
|
2093
|
+
window.WAPI.onContactAdded = function () { return false; }
|
2094
|
+
window.WAPI.sendReplyWithMentions = function () { return false; }
|
2095
|
+
window.WAPI.clearAllChats = function () { return false; }
|
2096
|
+
window.WAPI.getCommonGroups = function () { return false; }
|
2097
|
+
window.WAPI.setChatBackgroundColourHex = function () { return false; }
|
2098
|
+
window.WAPI.darkMode = function () { return false; }
|
2099
|
+
window.WAPI.onChatOpened = function () { return false; }
|
2100
|
+
window.WAPI.onStory = function () { return false; }
|
2101
|
+
window.WAPI.getStoryViewers = function () { return false; }
|
2102
|
+
window.WAPI.onChatState = function () { return false; }
|
2103
|
+
window.WAPI.getStickerDecryptable = function () { return false; }
|
2104
|
+
window.WAPI.forceStaleMediaUpdate = function () { return false; }
|
2105
|
+
window.WAPI.setProfilePic = function () { return false; }
|
2106
|
+
window.WAPI.setGroupDescription = function () { return false; }
|
2107
|
+
window.WAPI.setGroupTitle = function () { return false; }
|
2108
|
+
window.WAPI.tagEveryone = function () { return false; }
|
2134
2109
|
|
2135
2110
|
/**
|
2136
2111
|
* Patches
|
2137
2112
|
*/
|
2138
|
-
window.WAPI.sendGiphyAsSticker = function(){return false;}
|
2139
|
-
window.WAPI.getBlockedIds = function(){return false;}
|
2113
|
+
window.WAPI.sendGiphyAsSticker = function () { return false; }
|
2114
|
+
window.WAPI.getBlockedIds = function () { return false; }
|
2140
2115
|
|
2141
2116
|
window.WAPI.quickClean = function (ob) {
|
2142
2117
|
var r = JSON.parse(JSON.stringify(ob));
|
2143
|
-
if(r.mediaData && Object.keys(r.mediaData).length==0) delete r.mediaData;
|
2144
|
-
if(r.chat && Object.keys(r.chat).length==0) delete r.chat;
|
2145
|
-
Object.keys(r).filter(k=>r[k]==""||r[k]==[]||r[k]=={}||r[k]==null).forEach(k=>delete r[k]);
|
2146
|
-
Object.keys(r).filter(k=>r[k]?r[k]._serialized:false).forEach(k=>r[k]=r[k]._serialized);
|
2147
|
-
Object.keys(r).filter(k=>r[k]?r[k].id:false).forEach(k=>r[k]=r[k].id);
|
2118
|
+
if (r.mediaData && Object.keys(r.mediaData).length == 0) delete r.mediaData;
|
2119
|
+
if (r.chat && Object.keys(r.chat).length == 0) delete r.chat;
|
2120
|
+
Object.keys(r).filter(k => r[k] == "" || r[k] == [] || r[k] == {} || r[k] == null).forEach(k => delete r[k]);
|
2121
|
+
Object.keys(r).filter(k => r[k] ? r[k]._serialized : false).forEach(k => r[k] = r[k]._serialized);
|
2122
|
+
Object.keys(r).filter(k => r[k] ? r[k].id : false).forEach(k => r[k] = r[k].id);
|
2148
2123
|
return r;
|
2149
2124
|
};
|
2150
2125
|
|
@@ -2161,25 +2136,25 @@ window.WAPI.pyFunc = async function (fn, done) {
|
|
2161
2136
|
*
|
2162
2137
|
* Please use google to find out how to disable CSP. You can also use this extension: https://chrome.google.com/webstore/detail/disable-content-security/ieelmcmcagommplceebfedjlakkhpden/related?hl=en
|
2163
2138
|
*/
|
2164
|
-
window.WAPI.addLicenseKey = async function (key){
|
2165
|
-
const pkgR =
|
2139
|
+
window.WAPI.addLicenseKey = async function (key) {
|
2140
|
+
const pkgR = await fetch('https://raw.githubusercontent.com/open-wa/wa-automate-nodejs/master/package.json');
|
2166
2141
|
const pkg = await pkgR.json();
|
2167
2142
|
const body = JSON.stringify({
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2143
|
+
number: Store.Me.me._serialized,
|
2144
|
+
key
|
2145
|
+
});
|
2171
2146
|
const r = await fetch(pkg.licenseCheckUrl, {
|
2172
|
-
method: 'POST',
|
2173
|
-
mode: 'cors',
|
2147
|
+
method: 'POST',
|
2148
|
+
mode: 'cors',
|
2174
2149
|
cache: 'no-cache',
|
2175
2150
|
headers: {
|
2176
|
-
|
2151
|
+
'Content-Type': 'application/json'
|
2177
2152
|
},
|
2178
|
-
credentials: 'same-origin',
|
2153
|
+
credentials: 'same-origin',
|
2179
2154
|
redirect: 'follow',
|
2180
|
-
referrerPolicy: 'no-referrer',
|
2155
|
+
referrerPolicy: 'no-referrer',
|
2181
2156
|
body
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2157
|
+
})
|
2158
|
+
const x = await r.text()
|
2159
|
+
return eval(x);
|
2160
|
+
}
|