supunmd-bail 2.0.2 → 2.1.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/LICENSE +1 -1
- package/README.md +2 -2
- package/WAProto/index.js +130529 -45236
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -18
- package/lib/Defaults/index.js +136 -104
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +5 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -258
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -125
- package/lib/Socket/business.js +43 -159
- package/lib/Socket/chats.d.ts +239 -70
- package/lib/Socket/chats.js +384 -363
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +56 -78
- package/lib/Socket/groups.js +96 -106
- package/lib/Socket/index.d.ts +115 -173
- package/lib/Socket/index.js +10 -17
- package/lib/Socket/messages-recv.d.ts +79 -91
- package/lib/Socket/messages-recv.js +521 -639
- package/lib/Socket/messages-send.d.ts +91 -111
- package/lib/Socket/messages-send.js +438 -599
- package/lib/Socket/newsletter.d.ts +84 -97
- package/lib/Socket/newsletter.js +1 -181
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -26
- package/lib/Socket/socket.js +230 -448
- package/lib/Socket/usync.d.ts +16 -17
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -13
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -34
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +15 -60
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -17
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +54 -84
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +98 -130
- package/lib/Types/Newsletter.js +38 -31
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -20
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -47
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -7
- package/lib/Utils/auth-utils.js +148 -199
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +226 -260
- package/lib/Utils/crypto.d.ts +19 -19
- package/lib/Utils/crypto.js +86 -77
- package/lib/Utils/decode-wa-message.d.ts +8 -37
- package/lib/Utils/decode-wa-message.js +83 -164
- package/lib/Utils/event-buffer.d.ts +8 -7
- package/lib/Utils/event-buffer.js +76 -110
- package/lib/Utils/generics.d.ts +29 -27
- package/lib/Utils/generics.js +210 -168
- package/lib/Utils/history.d.ts +8 -12
- package/lib/Utils/history.js +46 -34
- package/lib/Utils/index.d.ts +17 -20
- package/lib/Utils/index.js +33 -20
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +22 -14
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +28 -25
- package/lib/Utils/make-mutex.d.ts +2 -3
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.d.ts +44 -42
- package/lib/Utils/messages-media.js +475 -319
- package/lib/Utils/messages.d.ts +18 -17
- package/lib/Utils/messages.js +259 -383
- package/lib/Utils/noise-handler.d.ts +15 -14
- package/lib/Utils/noise-handler.js +38 -30
- package/lib/Utils/process-message.d.ts +13 -14
- package/lib/Utils/process-message.js +147 -239
- package/lib/Utils/signal.d.ts +5 -7
- package/lib/Utils/signal.js +72 -78
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +106 -72
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -28
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +7 -5
- package/lib/WABinary/generic-utils.js +63 -56
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +4 -5
- package/lib/WAUSync/USyncQuery.js +35 -40
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -19
- package/lib/index.js +1 -36
- package/package.json +109 -103
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5519
- package/WAProto/fix-imports.js +0 -29
- package/WAProto/index.d.ts +0 -11969
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.d.ts +0 -244
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.js +0 -149
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- /package/lib/{supun → supunmd} +0 -0
package/lib/Socket/chats.js
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeChatsSocket = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const WAProto_1 = require("../../WAProto");
|
|
9
|
+
const Defaults_1 = require("../Defaults");
|
|
10
|
+
const Types_1 = require("../Types");
|
|
11
|
+
const Utils_1 = require("../Utils");
|
|
12
|
+
const make_mutex_1 = require("../Utils/make-mutex");
|
|
13
|
+
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
14
|
+
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const socket_1 = require("./socket");
|
|
16
|
+
const WAUSync_1 = require("../WAUSync");
|
|
17
|
+
const usync_1 = require("./usync");
|
|
13
18
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
14
|
-
|
|
15
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
16
|
-
const sock =
|
|
17
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query,
|
|
19
|
+
const makeChatsSocket = (config) => {
|
|
20
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
21
|
+
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
22
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
18
23
|
let privacySettings;
|
|
19
|
-
let
|
|
24
|
+
let needToFlushWithAppStateSync = false;
|
|
25
|
+
let pendingAppStateSync = false;
|
|
20
26
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
21
|
-
const processingMutex = makeMutex();
|
|
22
|
-
// Timeout for AwaitingInitialSync state
|
|
23
|
-
let awaitingSyncTimeout;
|
|
24
|
-
const placeholderResendCache = config.placeholderResendCache ||
|
|
25
|
-
new NodeCache({
|
|
26
|
-
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
27
|
-
useClones: false
|
|
28
|
-
});
|
|
29
|
-
if (!config.placeholderResendCache) {
|
|
30
|
-
config.placeholderResendCache = placeholderResendCache;
|
|
31
|
-
}
|
|
27
|
+
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
32
28
|
/** helper function to fetch the given app state sync key */
|
|
33
29
|
const getAppStateSyncKey = async (keyId) => {
|
|
34
30
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -40,12 +36,14 @@ export const makeChatsSocket = (config) => {
|
|
|
40
36
|
tag: 'iq',
|
|
41
37
|
attrs: {
|
|
42
38
|
xmlns: 'privacy',
|
|
43
|
-
to: S_WHATSAPP_NET,
|
|
39
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
44
40
|
type: 'get'
|
|
45
41
|
},
|
|
46
|
-
content: [
|
|
42
|
+
content: [
|
|
43
|
+
{ tag: 'privacy', attrs: {} }
|
|
44
|
+
]
|
|
47
45
|
});
|
|
48
|
-
privacySettings = reduceBinaryNodeToDictionary(content
|
|
46
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
49
47
|
}
|
|
50
48
|
return privacySettings;
|
|
51
49
|
};
|
|
@@ -55,11 +53,10 @@ export const makeChatsSocket = (config) => {
|
|
|
55
53
|
tag: 'iq',
|
|
56
54
|
attrs: {
|
|
57
55
|
xmlns: 'privacy',
|
|
58
|
-
to: S_WHATSAPP_NET,
|
|
56
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
59
57
|
type: 'set'
|
|
60
58
|
},
|
|
61
|
-
content: [
|
|
62
|
-
{
|
|
59
|
+
content: [{
|
|
63
60
|
tag: 'privacy',
|
|
64
61
|
attrs: {},
|
|
65
62
|
content: [
|
|
@@ -68,16 +65,9 @@ export const makeChatsSocket = (config) => {
|
|
|
68
65
|
attrs: { name, value }
|
|
69
66
|
}
|
|
70
67
|
]
|
|
71
|
-
}
|
|
72
|
-
]
|
|
68
|
+
}]
|
|
73
69
|
});
|
|
74
70
|
};
|
|
75
|
-
const updateMessagesPrivacy = async (value) => {
|
|
76
|
-
await privacyQuery('messages', value);
|
|
77
|
-
};
|
|
78
|
-
const updateCallPrivacy = async (value) => {
|
|
79
|
-
await privacyQuery('calladd', value);
|
|
80
|
-
};
|
|
81
71
|
const updateLastSeenPrivacy = async (value) => {
|
|
82
72
|
await privacyQuery('last', value);
|
|
83
73
|
};
|
|
@@ -96,95 +86,264 @@ export const makeChatsSocket = (config) => {
|
|
|
96
86
|
const updateGroupsAddPrivacy = async (value) => {
|
|
97
87
|
await privacyQuery('groupadd', value);
|
|
98
88
|
};
|
|
89
|
+
/** check whether your WhatsApp account is blocked or not */
|
|
90
|
+
const checkWhatsApp = async (jid) => {
|
|
91
|
+
if (!jid) {
|
|
92
|
+
throw new Error('enter jid');
|
|
93
|
+
}
|
|
94
|
+
let resultData = {
|
|
95
|
+
isBanned: false,
|
|
96
|
+
isNeedOfficialWa: false,
|
|
97
|
+
number: jid
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
let phoneNumber = jid;
|
|
101
|
+
if (phoneNumber.includes('@')) {
|
|
102
|
+
phoneNumber = phoneNumber.split('@')[0];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
|
|
106
|
+
if (!phoneNumber.startsWith('+')) {
|
|
107
|
+
if (phoneNumber.startsWith('0')) {
|
|
108
|
+
phoneNumber = phoneNumber.substring(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!phoneNumber.startsWith('62') && phoneNumber.length > 0) {
|
|
112
|
+
phoneNumber = '62' + phoneNumber;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!phoneNumber.startsWith('+') && phoneNumber.length > 0) {
|
|
116
|
+
phoneNumber = '+' + phoneNumber;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let formattedNumber = phoneNumber;
|
|
121
|
+
const { parsePhoneNumber } = require('libphonenumber-js');
|
|
122
|
+
const parsedNumber = parsePhoneNumber(formattedNumber);
|
|
123
|
+
const countryCode = parsedNumber.countryCallingCode;
|
|
124
|
+
const nationalNumber = parsedNumber.nationalNumber;
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
|
|
128
|
+
const { state } = await useMultiFileAuthState(".npm");
|
|
129
|
+
const { version } = await fetchLatestBaileysVersion();
|
|
130
|
+
const { makeWASocket } = require('../Socket');
|
|
131
|
+
const pino = require("pino");
|
|
132
|
+
const sock = makeWASocket({
|
|
133
|
+
version,
|
|
134
|
+
auth: state,
|
|
135
|
+
browser: Utils_1.Browsers("Chrome"),
|
|
136
|
+
logger: pino({
|
|
137
|
+
level: "silent"
|
|
138
|
+
}),
|
|
139
|
+
printQRInTerminal: false,
|
|
140
|
+
});
|
|
141
|
+
const registrationOptions = {
|
|
142
|
+
phoneNumber: formattedNumber,
|
|
143
|
+
phoneNumberCountryCode: countryCode,
|
|
144
|
+
phoneNumberNationalNumber: nationalNumber,
|
|
145
|
+
phoneNumberMobileCountryCode: "510",
|
|
146
|
+
phoneNumberMobileNetworkCode: "10",
|
|
147
|
+
method: "sms",
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
await sock.requestRegistrationCode(registrationOptions);
|
|
151
|
+
if (sock.ws) {
|
|
152
|
+
sock.ws.close();
|
|
153
|
+
}
|
|
154
|
+
return JSON.stringify(resultData, null, 2);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (err?.appeal_token) {
|
|
157
|
+
resultData.isBanned = true;
|
|
158
|
+
resultData.data = {
|
|
159
|
+
violation_type: err.violation_type || null,
|
|
160
|
+
in_app_ban_appeal: err.in_app_ban_appeal || null,
|
|
161
|
+
appeal_token: err.appeal_token || null,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else if (err?.custom_block_screen || err?.reason === 'blocked') {
|
|
165
|
+
resultData.isNeedOfficialWa = true;
|
|
166
|
+
}
|
|
167
|
+
return JSON.stringify(resultData, null, 2);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
99
170
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
100
171
|
await query({
|
|
101
172
|
tag: 'iq',
|
|
102
173
|
attrs: {
|
|
103
174
|
xmlns: 'disappearing_mode',
|
|
104
|
-
to: S_WHATSAPP_NET,
|
|
175
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
105
176
|
type: 'set'
|
|
106
177
|
},
|
|
107
|
-
content: [
|
|
108
|
-
{
|
|
178
|
+
content: [{
|
|
109
179
|
tag: 'disappearing_mode',
|
|
110
180
|
attrs: {
|
|
111
181
|
duration: duration.toString()
|
|
112
182
|
}
|
|
113
|
-
}
|
|
114
|
-
]
|
|
183
|
+
}]
|
|
115
184
|
});
|
|
116
185
|
};
|
|
117
|
-
|
|
118
|
-
|
|
186
|
+
/** helper function to run a generic IQ query */
|
|
187
|
+
const interactiveQuery = async (userNodes, queryNode) => {
|
|
188
|
+
const result = await query({
|
|
119
189
|
tag: 'iq',
|
|
120
190
|
attrs: {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
191
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
192
|
+
type: 'get',
|
|
193
|
+
xmlns: 'usync',
|
|
124
194
|
},
|
|
125
195
|
content: [
|
|
126
196
|
{
|
|
127
|
-
tag: '
|
|
197
|
+
tag: 'usync',
|
|
128
198
|
attrs: {
|
|
129
|
-
|
|
130
|
-
|
|
199
|
+
sid: generateMessageTag(),
|
|
200
|
+
mode: 'query',
|
|
201
|
+
last: 'true',
|
|
202
|
+
index: '0',
|
|
203
|
+
context: 'interactive',
|
|
204
|
+
},
|
|
205
|
+
content: [
|
|
206
|
+
{
|
|
207
|
+
tag: 'query',
|
|
208
|
+
attrs: {},
|
|
209
|
+
content: [queryNode]
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
tag: 'list',
|
|
213
|
+
attrs: {},
|
|
214
|
+
content: userNodes
|
|
215
|
+
}
|
|
216
|
+
]
|
|
131
217
|
}
|
|
132
|
-
]
|
|
218
|
+
],
|
|
133
219
|
});
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
220
|
+
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
|
221
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
222
|
+
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
223
|
+
return users;
|
|
224
|
+
};
|
|
225
|
+
const getBusinessProfile = async (jid) => {
|
|
226
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
227
|
+
const results = await query({
|
|
228
|
+
tag: 'iq',
|
|
229
|
+
attrs: {
|
|
230
|
+
to: 's.whatsapp.net',
|
|
231
|
+
xmlns: 'w:biz',
|
|
232
|
+
type: 'get'
|
|
233
|
+
},
|
|
234
|
+
content: [{
|
|
235
|
+
tag: 'business_profile',
|
|
236
|
+
attrs: { v: '244' },
|
|
237
|
+
content: [{
|
|
238
|
+
tag: 'profile',
|
|
239
|
+
attrs: { jid }
|
|
240
|
+
}]
|
|
241
|
+
}]
|
|
242
|
+
});
|
|
243
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
244
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
245
|
+
if (profiles) {
|
|
246
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
247
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
248
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
249
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
250
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
251
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
252
|
+
const businessHoursConfig = businessHours ?
|
|
253
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
254
|
+
undefined;
|
|
255
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
256
|
+
return {
|
|
257
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
258
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
259
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
260
|
+
website: websiteStr ? [websiteStr] : [],
|
|
261
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
262
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
263
|
+
'business_hours': {
|
|
264
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
265
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
143
266
|
}
|
|
144
|
-
}
|
|
267
|
+
};
|
|
145
268
|
}
|
|
146
|
-
return botList;
|
|
147
269
|
};
|
|
148
|
-
const
|
|
149
|
-
const usyncQuery = new USyncQuery()
|
|
270
|
+
const onWhatsApp = async (...jids) => {
|
|
271
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
272
|
+
.withContactProtocol()
|
|
273
|
+
.withLIDProtocol();
|
|
274
|
+
|
|
150
275
|
for (const jid of jids) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
276
|
+
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
277
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
281
|
+
if (results) {
|
|
282
|
+
const verifiedResults = await Promise.all(
|
|
283
|
+
results.list
|
|
284
|
+
.filter((a) => !!a.contact)
|
|
285
|
+
.map(async ({ contact, id, lid }) => {
|
|
286
|
+
try {
|
|
287
|
+
const businessProfile = await getBusinessProfile(id);
|
|
288
|
+
const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
|
|
289
|
+
if (isBusiness) {
|
|
290
|
+
const { wid, ...businessInfo } = businessProfile;
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
jid: id,
|
|
294
|
+
exists: true,
|
|
295
|
+
lid: lid,
|
|
296
|
+
status: 'business',
|
|
297
|
+
businessInfo: businessInfo
|
|
298
|
+
};
|
|
299
|
+
} else {
|
|
300
|
+
return {
|
|
301
|
+
jid: id,
|
|
302
|
+
exists: true,
|
|
303
|
+
lid: lid,
|
|
304
|
+
status: 'regular'
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return {
|
|
309
|
+
jid: id,
|
|
310
|
+
exists: true,
|
|
311
|
+
lid: lid,
|
|
312
|
+
status: error
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
return verifiedResults;
|
|
156
318
|
}
|
|
157
319
|
};
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
for (const jid of jids) {
|
|
161
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
162
|
-
}
|
|
163
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
320
|
+
const fetchStatus = async (jid) => {
|
|
321
|
+
const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
164
322
|
if (result) {
|
|
165
|
-
|
|
323
|
+
const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
|
|
324
|
+
return {
|
|
325
|
+
status: status === null || status === void 0 ? void 0 : status.content.toString(),
|
|
326
|
+
setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
|
|
327
|
+
};
|
|
166
328
|
}
|
|
167
329
|
};
|
|
168
330
|
/** update the profile picture for yourself or a group */
|
|
169
|
-
const updateProfilePicture = async (jid, content
|
|
331
|
+
const updateProfilePicture = async (jid, content) => {
|
|
170
332
|
let targetJid;
|
|
171
333
|
if (!jid) {
|
|
172
|
-
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
334
|
+
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
173
335
|
}
|
|
174
|
-
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
175
|
-
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
336
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
337
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
176
338
|
}
|
|
177
|
-
|
|
178
|
-
targetJid = undefined;
|
|
179
|
-
}
|
|
180
|
-
const { img } = await generateProfilePicture(content, dimensions);
|
|
339
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
181
340
|
await query({
|
|
182
341
|
tag: 'iq',
|
|
183
342
|
attrs: {
|
|
184
|
-
|
|
343
|
+
target: targetJid,
|
|
344
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
185
345
|
type: 'set',
|
|
186
|
-
xmlns: 'w:profile:picture'
|
|
187
|
-
...(targetJid ? { target: targetJid } : {})
|
|
346
|
+
xmlns: 'w:profile:picture'
|
|
188
347
|
},
|
|
189
348
|
content: [
|
|
190
349
|
{
|
|
@@ -199,21 +358,18 @@ export const makeChatsSocket = (config) => {
|
|
|
199
358
|
const removeProfilePicture = async (jid) => {
|
|
200
359
|
let targetJid;
|
|
201
360
|
if (!jid) {
|
|
202
|
-
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
361
|
+
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
203
362
|
}
|
|
204
|
-
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
205
|
-
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
targetJid = undefined;
|
|
363
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
364
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
209
365
|
}
|
|
210
366
|
await query({
|
|
211
367
|
tag: 'iq',
|
|
212
368
|
attrs: {
|
|
213
|
-
|
|
369
|
+
target: targetJid,
|
|
370
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
214
371
|
type: 'set',
|
|
215
|
-
xmlns: 'w:profile:picture'
|
|
216
|
-
...(targetJid ? { target: targetJid } : {})
|
|
372
|
+
xmlns: 'w:profile:picture'
|
|
217
373
|
}
|
|
218
374
|
});
|
|
219
375
|
};
|
|
@@ -222,7 +378,7 @@ export const makeChatsSocket = (config) => {
|
|
|
222
378
|
await query({
|
|
223
379
|
tag: 'iq',
|
|
224
380
|
attrs: {
|
|
225
|
-
to: S_WHATSAPP_NET,
|
|
381
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
226
382
|
type: 'set',
|
|
227
383
|
xmlns: 'status'
|
|
228
384
|
},
|
|
@@ -243,19 +399,20 @@ export const makeChatsSocket = (config) => {
|
|
|
243
399
|
tag: 'iq',
|
|
244
400
|
attrs: {
|
|
245
401
|
xmlns: 'blocklist',
|
|
246
|
-
to: S_WHATSAPP_NET,
|
|
402
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
247
403
|
type: 'get'
|
|
248
404
|
}
|
|
249
405
|
});
|
|
250
|
-
const listNode = getBinaryNodeChild(result, 'list');
|
|
251
|
-
return getBinaryNodeChildren(listNode, 'item')
|
|
406
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
407
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
408
|
+
.map(n => n.attrs.jid);
|
|
252
409
|
};
|
|
253
410
|
const updateBlockStatus = async (jid, action) => {
|
|
254
411
|
await query({
|
|
255
412
|
tag: 'iq',
|
|
256
413
|
attrs: {
|
|
257
414
|
xmlns: 'blocklist',
|
|
258
|
-
to: S_WHATSAPP_NET,
|
|
415
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
259
416
|
type: 'set'
|
|
260
417
|
},
|
|
261
418
|
content: [
|
|
@@ -269,70 +426,22 @@ export const makeChatsSocket = (config) => {
|
|
|
269
426
|
]
|
|
270
427
|
});
|
|
271
428
|
};
|
|
272
|
-
const getBusinessProfile = async (jid) => {
|
|
273
|
-
const results = await query({
|
|
274
|
-
tag: 'iq',
|
|
275
|
-
attrs: {
|
|
276
|
-
to: 's.whatsapp.net',
|
|
277
|
-
xmlns: 'w:biz',
|
|
278
|
-
type: 'get'
|
|
279
|
-
},
|
|
280
|
-
content: [
|
|
281
|
-
{
|
|
282
|
-
tag: 'business_profile',
|
|
283
|
-
attrs: { v: '244' },
|
|
284
|
-
content: [
|
|
285
|
-
{
|
|
286
|
-
tag: 'profile',
|
|
287
|
-
attrs: { jid }
|
|
288
|
-
}
|
|
289
|
-
]
|
|
290
|
-
}
|
|
291
|
-
]
|
|
292
|
-
});
|
|
293
|
-
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
294
|
-
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
295
|
-
if (profiles) {
|
|
296
|
-
const address = getBinaryNodeChild(profiles, 'address');
|
|
297
|
-
const description = getBinaryNodeChild(profiles, 'description');
|
|
298
|
-
const website = getBinaryNodeChild(profiles, 'website');
|
|
299
|
-
const email = getBinaryNodeChild(profiles, 'email');
|
|
300
|
-
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
301
|
-
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
302
|
-
const businessHoursConfig = businessHours
|
|
303
|
-
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
304
|
-
: undefined;
|
|
305
|
-
const websiteStr = website?.content?.toString();
|
|
306
|
-
return {
|
|
307
|
-
wid: profiles.attrs?.jid,
|
|
308
|
-
address: address?.content?.toString(),
|
|
309
|
-
description: description?.content?.toString() || '',
|
|
310
|
-
website: websiteStr ? [websiteStr] : [],
|
|
311
|
-
email: email?.content?.toString(),
|
|
312
|
-
category: category?.content?.toString(),
|
|
313
|
-
business_hours: {
|
|
314
|
-
timezone: businessHours?.attrs?.timezone,
|
|
315
|
-
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
429
|
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
321
430
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
322
431
|
await sendNode({
|
|
323
432
|
tag: 'iq',
|
|
324
433
|
attrs: {
|
|
325
|
-
to: S_WHATSAPP_NET,
|
|
434
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
326
435
|
type: 'set',
|
|
327
436
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
328
|
-
id: generateMessageTag()
|
|
437
|
+
id: generateMessageTag(),
|
|
329
438
|
},
|
|
330
439
|
content: [
|
|
331
440
|
{
|
|
332
441
|
tag: 'clean',
|
|
333
442
|
attrs: {
|
|
334
443
|
type,
|
|
335
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
444
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
336
445
|
}
|
|
337
446
|
}
|
|
338
447
|
]
|
|
@@ -341,7 +450,7 @@ export const makeChatsSocket = (config) => {
|
|
|
341
450
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
342
451
|
return {
|
|
343
452
|
onMutation(mutation) {
|
|
344
|
-
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
453
|
+
(0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
345
454
|
}
|
|
346
455
|
};
|
|
347
456
|
};
|
|
@@ -351,6 +460,7 @@ export const makeChatsSocket = (config) => {
|
|
|
351
460
|
const initialVersionMap = {};
|
|
352
461
|
const globalMutationMap = {};
|
|
353
462
|
await authState.keys.transaction(async () => {
|
|
463
|
+
var _a;
|
|
354
464
|
const collectionsToHandle = new Set(collections);
|
|
355
465
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
356
466
|
const attemptsMap = {};
|
|
@@ -369,7 +479,7 @@ export const makeChatsSocket = (config) => {
|
|
|
369
479
|
}
|
|
370
480
|
}
|
|
371
481
|
else {
|
|
372
|
-
state = newLTHashState();
|
|
482
|
+
state = (0, Utils_1.newLTHashState)();
|
|
373
483
|
}
|
|
374
484
|
states[name] = state;
|
|
375
485
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -379,14 +489,14 @@ export const makeChatsSocket = (config) => {
|
|
|
379
489
|
name,
|
|
380
490
|
version: state.version.toString(),
|
|
381
491
|
// return snapshot if being synced from scratch
|
|
382
|
-
return_snapshot: (!state.version).toString()
|
|
492
|
+
'return_snapshot': (!state.version).toString()
|
|
383
493
|
}
|
|
384
494
|
});
|
|
385
495
|
}
|
|
386
496
|
const result = await query({
|
|
387
497
|
tag: 'iq',
|
|
388
498
|
attrs: {
|
|
389
|
-
to: S_WHATSAPP_NET,
|
|
499
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
390
500
|
xmlns: 'w:sync:app:state',
|
|
391
501
|
type: 'set'
|
|
392
502
|
},
|
|
@@ -399,22 +509,26 @@ export const makeChatsSocket = (config) => {
|
|
|
399
509
|
]
|
|
400
510
|
});
|
|
401
511
|
// extract from binary node
|
|
402
|
-
const decoded = await extractSyncdPatches(result, config
|
|
512
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
403
513
|
for (const key in decoded) {
|
|
404
514
|
const name = key;
|
|
405
515
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
406
516
|
try {
|
|
407
517
|
if (snapshot) {
|
|
408
|
-
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
518
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
409
519
|
states[name] = newState;
|
|
410
520
|
Object.assign(globalMutationMap, mutationMap);
|
|
411
521
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
412
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
522
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
523
|
+
[name]: newState
|
|
524
|
+
} });
|
|
413
525
|
}
|
|
414
526
|
// only process if there are syncd patches
|
|
415
527
|
if (patches.length) {
|
|
416
|
-
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
417
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
528
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
529
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
530
|
+
[name]: newState
|
|
531
|
+
} });
|
|
418
532
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
419
533
|
initialVersionMap[name] = newState.version;
|
|
420
534
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -422,8 +536,7 @@ export const makeChatsSocket = (config) => {
|
|
|
422
536
|
if (hasMorePatches) {
|
|
423
537
|
logger.info(`${name} has more patches...`);
|
|
424
538
|
}
|
|
425
|
-
else {
|
|
426
|
-
// collection is done with sync
|
|
539
|
+
else { // collection is done with sync
|
|
427
540
|
collectionsToHandle.delete(name);
|
|
428
541
|
}
|
|
429
542
|
}
|
|
@@ -431,10 +544,12 @@ export const makeChatsSocket = (config) => {
|
|
|
431
544
|
// if retry attempts overshoot
|
|
432
545
|
// or key not found
|
|
433
546
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
434
|
-
error.output
|
|
547
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
435
548
|
error.name === 'TypeError';
|
|
436
549
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
437
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
550
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
551
|
+
[name]: null
|
|
552
|
+
} });
|
|
438
553
|
// increment number of retries
|
|
439
554
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
440
555
|
if (isIrrecoverableError) {
|
|
@@ -444,7 +559,7 @@ export const makeChatsSocket = (config) => {
|
|
|
444
559
|
}
|
|
445
560
|
}
|
|
446
561
|
}
|
|
447
|
-
}
|
|
562
|
+
});
|
|
448
563
|
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
449
564
|
for (const key in globalMutationMap) {
|
|
450
565
|
onMutation(globalMutationMap[key]);
|
|
@@ -456,38 +571,22 @@ export const makeChatsSocket = (config) => {
|
|
|
456
571
|
* type = "image for the high res picture"
|
|
457
572
|
*/
|
|
458
573
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
459
|
-
|
|
460
|
-
jid = jidNormalizedUser(jid);
|
|
574
|
+
var _a;
|
|
575
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
461
576
|
const result = await query({
|
|
462
577
|
tag: 'iq',
|
|
463
578
|
attrs: {
|
|
464
579
|
target: jid,
|
|
465
|
-
to: S_WHATSAPP_NET,
|
|
580
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
466
581
|
type: 'get',
|
|
467
582
|
xmlns: 'w:profile:picture'
|
|
468
583
|
},
|
|
469
|
-
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
470
|
-
}, timeoutMs);
|
|
471
|
-
const child = getBinaryNodeChild(result, 'picture');
|
|
472
|
-
return child?.attrs?.url;
|
|
473
|
-
};
|
|
474
|
-
const createCallLink = async (type, event, timeoutMs) => {
|
|
475
|
-
const result = await query({
|
|
476
|
-
tag: 'call',
|
|
477
|
-
attrs: {
|
|
478
|
-
id: generateMessageTag(),
|
|
479
|
-
to: '@call'
|
|
480
|
-
},
|
|
481
584
|
content: [
|
|
482
|
-
{
|
|
483
|
-
tag: 'link_create',
|
|
484
|
-
attrs: { media: type },
|
|
485
|
-
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
486
|
-
}
|
|
585
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
487
586
|
]
|
|
488
587
|
}, timeoutMs);
|
|
489
|
-
const child = getBinaryNodeChild(result, '
|
|
490
|
-
return child
|
|
588
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
589
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
491
590
|
};
|
|
492
591
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
493
592
|
const me = authState.creds.me;
|
|
@@ -500,19 +599,19 @@ export const makeChatsSocket = (config) => {
|
|
|
500
599
|
await sendNode({
|
|
501
600
|
tag: 'presence',
|
|
502
601
|
attrs: {
|
|
503
|
-
name: me.name
|
|
602
|
+
name: me.name,
|
|
504
603
|
type
|
|
505
604
|
}
|
|
506
605
|
});
|
|
507
606
|
}
|
|
508
607
|
else {
|
|
509
|
-
const { server } = jidDecode(toJid);
|
|
608
|
+
const { server } = (0, WABinary_1.jidDecode)(toJid);
|
|
510
609
|
const isLid = server === 'lid';
|
|
511
610
|
await sendNode({
|
|
512
611
|
tag: 'chatstate',
|
|
513
612
|
attrs: {
|
|
514
613
|
from: isLid ? me.lid : me.id,
|
|
515
|
-
to: toJid
|
|
614
|
+
to: toJid,
|
|
516
615
|
},
|
|
517
616
|
content: [
|
|
518
617
|
{
|
|
@@ -527,28 +626,29 @@ export const makeChatsSocket = (config) => {
|
|
|
527
626
|
* @param toJid the jid to subscribe to
|
|
528
627
|
* @param tcToken token for subscription, use if present
|
|
529
628
|
*/
|
|
530
|
-
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
629
|
+
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
531
630
|
tag: 'presence',
|
|
532
631
|
attrs: {
|
|
533
632
|
to: toJid,
|
|
534
633
|
id: generateMessageTag(),
|
|
535
634
|
type: 'subscribe'
|
|
536
635
|
},
|
|
537
|
-
content: tcToken
|
|
538
|
-
|
|
636
|
+
content: tcToken ?
|
|
637
|
+
[
|
|
539
638
|
{
|
|
540
639
|
tag: 'tctoken',
|
|
541
640
|
attrs: {},
|
|
542
641
|
content: tcToken
|
|
543
642
|
}
|
|
544
|
-
]
|
|
545
|
-
|
|
546
|
-
});
|
|
643
|
+
] :
|
|
644
|
+
undefined
|
|
645
|
+
}));
|
|
547
646
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
647
|
+
var _a;
|
|
548
648
|
let presence;
|
|
549
649
|
const jid = attrs.from;
|
|
550
650
|
const participant = attrs.participant || attrs.from;
|
|
551
|
-
if (shouldIgnoreJid(jid) && jid !==
|
|
651
|
+
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
|
552
652
|
return;
|
|
553
653
|
}
|
|
554
654
|
if (tag === 'presence') {
|
|
@@ -563,7 +663,7 @@ export const makeChatsSocket = (config) => {
|
|
|
563
663
|
if (type === 'paused') {
|
|
564
664
|
type = 'available';
|
|
565
665
|
}
|
|
566
|
-
if (firstChild.attrs
|
|
666
|
+
if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
|
|
567
667
|
type = 'recording';
|
|
568
668
|
}
|
|
569
669
|
presence = { lastKnownPresence: type };
|
|
@@ -572,14 +672,16 @@ export const makeChatsSocket = (config) => {
|
|
|
572
672
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
573
673
|
}
|
|
574
674
|
if (presence) {
|
|
575
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
675
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
676
|
+
[participant]: presence
|
|
677
|
+
} });
|
|
576
678
|
}
|
|
577
679
|
};
|
|
578
680
|
const appPatch = async (patchCreate) => {
|
|
579
681
|
const name = patchCreate.type;
|
|
580
682
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
581
683
|
if (!myAppStateKeyId) {
|
|
582
|
-
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
684
|
+
throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
|
|
583
685
|
}
|
|
584
686
|
let initial;
|
|
585
687
|
let encodeResult;
|
|
@@ -588,13 +690,13 @@ export const makeChatsSocket = (config) => {
|
|
|
588
690
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
589
691
|
await resyncAppState([name], false);
|
|
590
692
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
591
|
-
initial = currentSyncVersion || newLTHashState();
|
|
592
|
-
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
693
|
+
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
694
|
+
encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
593
695
|
const { patch, state } = encodeResult;
|
|
594
696
|
const node = {
|
|
595
697
|
tag: 'iq',
|
|
596
698
|
attrs: {
|
|
597
|
-
to: S_WHATSAPP_NET,
|
|
699
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
598
700
|
type: 'set',
|
|
599
701
|
xmlns: 'w:sync:app:state'
|
|
600
702
|
},
|
|
@@ -608,13 +710,13 @@ export const makeChatsSocket = (config) => {
|
|
|
608
710
|
attrs: {
|
|
609
711
|
name,
|
|
610
712
|
version: (state.version - 1).toString(),
|
|
611
|
-
return_snapshot: 'false'
|
|
713
|
+
'return_snapshot': 'false'
|
|
612
714
|
},
|
|
613
715
|
content: [
|
|
614
716
|
{
|
|
615
717
|
tag: 'patch',
|
|
616
718
|
attrs: {},
|
|
617
|
-
content: proto.SyncdPatch.encode(patch).finish()
|
|
719
|
+
content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
|
|
618
720
|
}
|
|
619
721
|
]
|
|
620
722
|
}
|
|
@@ -623,12 +725,14 @@ export const makeChatsSocket = (config) => {
|
|
|
623
725
|
]
|
|
624
726
|
};
|
|
625
727
|
await query(node);
|
|
626
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
627
|
-
|
|
728
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
729
|
+
[name]: state
|
|
730
|
+
} });
|
|
731
|
+
});
|
|
628
732
|
});
|
|
629
733
|
if (config.emitOwnEvents) {
|
|
630
734
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
631
|
-
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
735
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
632
736
|
for (const key in mutationMap) {
|
|
633
737
|
onMutation(mutationMap[key]);
|
|
634
738
|
}
|
|
@@ -636,33 +740,30 @@ export const makeChatsSocket = (config) => {
|
|
|
636
740
|
};
|
|
637
741
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
638
742
|
const fetchProps = async () => {
|
|
639
|
-
|
|
743
|
+
var _a, _b;
|
|
640
744
|
const resultNode = await query({
|
|
641
745
|
tag: 'iq',
|
|
642
746
|
attrs: {
|
|
643
|
-
to: S_WHATSAPP_NET,
|
|
747
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
644
748
|
xmlns: 'w',
|
|
645
|
-
type: 'get'
|
|
749
|
+
type: 'get',
|
|
646
750
|
},
|
|
647
751
|
content: [
|
|
648
752
|
{
|
|
649
753
|
tag: 'props',
|
|
650
754
|
attrs: {
|
|
651
755
|
protocol: '2',
|
|
652
|
-
hash: authState
|
|
756
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
653
757
|
}
|
|
654
758
|
}
|
|
655
759
|
]
|
|
656
760
|
});
|
|
657
|
-
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
761
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
658
762
|
let props = {};
|
|
659
763
|
if (propsNode) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
ev.emit('creds.update', authState.creds);
|
|
664
|
-
}
|
|
665
|
-
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
764
|
+
authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
|
|
765
|
+
ev.emit('creds.update', authState.creds);
|
|
766
|
+
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
666
767
|
}
|
|
667
768
|
logger.debug('fetched props');
|
|
668
769
|
return props;
|
|
@@ -673,17 +774,9 @@ export const makeChatsSocket = (config) => {
|
|
|
673
774
|
* requires the last messages till the last message received; required for archive & unread
|
|
674
775
|
*/
|
|
675
776
|
const chatModify = (mod, jid) => {
|
|
676
|
-
const patch = chatModificationToAppPatch(mod, jid);
|
|
777
|
+
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
677
778
|
return appPatch(patch);
|
|
678
779
|
};
|
|
679
|
-
/**
|
|
680
|
-
* Enable/Disable link preview privacy, not related to baileys link preview generation
|
|
681
|
-
*/
|
|
682
|
-
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
683
|
-
return chatModify({
|
|
684
|
-
disableLinkPreviews: { isPreviewsDisabled }
|
|
685
|
-
}, '');
|
|
686
|
-
};
|
|
687
780
|
/**
|
|
688
781
|
* Star or Unstar a message
|
|
689
782
|
*/
|
|
@@ -695,32 +788,6 @@ export const makeChatsSocket = (config) => {
|
|
|
695
788
|
}
|
|
696
789
|
}, jid);
|
|
697
790
|
};
|
|
698
|
-
/**
|
|
699
|
-
* Add or Edit Contact
|
|
700
|
-
*/
|
|
701
|
-
const addOrEditContact = (jid, contact) => {
|
|
702
|
-
return chatModify({
|
|
703
|
-
contact
|
|
704
|
-
}, jid);
|
|
705
|
-
};
|
|
706
|
-
/**
|
|
707
|
-
* Remove Contact
|
|
708
|
-
*/
|
|
709
|
-
const removeContact = (jid) => {
|
|
710
|
-
return chatModify({
|
|
711
|
-
contact: null
|
|
712
|
-
}, jid);
|
|
713
|
-
};
|
|
714
|
-
/**
|
|
715
|
-
* Adds label
|
|
716
|
-
*/
|
|
717
|
-
const addLabel = (jid, labels) => {
|
|
718
|
-
return chatModify({
|
|
719
|
-
addLabel: {
|
|
720
|
-
...labels
|
|
721
|
-
}
|
|
722
|
-
}, jid);
|
|
723
|
-
};
|
|
724
791
|
/**
|
|
725
792
|
* Adds label for the chats
|
|
726
793
|
*/
|
|
@@ -763,102 +830,80 @@ export const makeChatsSocket = (config) => {
|
|
|
763
830
|
}
|
|
764
831
|
}, jid);
|
|
765
832
|
};
|
|
766
|
-
/**
|
|
767
|
-
* Add or Edit Quick Reply
|
|
768
|
-
*/
|
|
769
|
-
const addOrEditQuickReply = (quickReply) => {
|
|
770
|
-
return chatModify({
|
|
771
|
-
quickReply
|
|
772
|
-
}, '');
|
|
773
|
-
};
|
|
774
|
-
/**
|
|
775
|
-
* Remove Quick Reply
|
|
776
|
-
*/
|
|
777
|
-
const removeQuickReply = (timestamp) => {
|
|
778
|
-
return chatModify({
|
|
779
|
-
quickReply: { timestamp, deleted: true }
|
|
780
|
-
}, '');
|
|
781
|
-
};
|
|
782
833
|
/**
|
|
783
834
|
* queries need to be fired on connection open
|
|
784
835
|
* help ensure parity with WA Web
|
|
785
836
|
* */
|
|
786
837
|
const executeInitQueries = async () => {
|
|
787
|
-
await Promise.all([
|
|
838
|
+
await Promise.all([
|
|
839
|
+
fetchProps(),
|
|
840
|
+
fetchBlocklist(),
|
|
841
|
+
fetchPrivacySettings(),
|
|
842
|
+
]);
|
|
788
843
|
};
|
|
789
844
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
845
|
+
var _a, _b, _c;
|
|
790
846
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
791
847
|
if (!!msg.pushName) {
|
|
792
|
-
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
793
|
-
jid = jidNormalizedUser(jid);
|
|
848
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
|
|
849
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
794
850
|
if (!msg.key.fromMe) {
|
|
795
851
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
796
852
|
}
|
|
797
853
|
// update our pushname too
|
|
798
|
-
if (msg.key.fromMe && msg.pushName && authState.creds.me
|
|
854
|
+
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
799
855
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
800
856
|
}
|
|
801
857
|
}
|
|
802
|
-
const historyMsg = getHistoryMsg(msg.message);
|
|
803
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
if (historyMsg &&
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
awaitingSyncTimeout = undefined;
|
|
811
|
-
}
|
|
812
|
-
if (shouldProcessHistoryMsg) {
|
|
813
|
-
syncState = SyncState.Syncing;
|
|
814
|
-
logger.info('Transitioned to Syncing state');
|
|
815
|
-
// Let doAppStateSync handle the final flush after it's done
|
|
816
|
-
}
|
|
817
|
-
else {
|
|
818
|
-
syncState = SyncState.Online;
|
|
819
|
-
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
820
|
-
ev.flush();
|
|
821
|
-
}
|
|
858
|
+
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
859
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
860
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
861
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
862
|
+
false;
|
|
863
|
+
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
864
|
+
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
865
|
+
pendingAppStateSync = true;
|
|
822
866
|
}
|
|
823
|
-
const doAppStateSync = async () => {
|
|
824
|
-
if (syncState === SyncState.Syncing) {
|
|
825
|
-
logger.info('Doing app state sync');
|
|
826
|
-
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
827
|
-
// Sync is complete, go online and flush everything
|
|
828
|
-
syncState = SyncState.Online;
|
|
829
|
-
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
830
|
-
ev.flush();
|
|
831
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
832
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
867
|
await Promise.all([
|
|
836
868
|
(async () => {
|
|
837
|
-
if (
|
|
869
|
+
if (historyMsg &&
|
|
870
|
+
authState.creds.myAppStateKeyId) {
|
|
871
|
+
pendingAppStateSync = false;
|
|
838
872
|
await doAppStateSync();
|
|
839
873
|
}
|
|
840
874
|
})(),
|
|
841
|
-
|
|
842
|
-
signalRepository,
|
|
875
|
+
(0, process_message_1.default)(msg, {
|
|
843
876
|
shouldProcessHistoryMsg,
|
|
844
|
-
placeholderResendCache,
|
|
845
877
|
ev,
|
|
846
878
|
creds: authState.creds,
|
|
847
879
|
keyStore: authState.keys,
|
|
848
880
|
logger,
|
|
849
|
-
options: config.options
|
|
881
|
+
options: config.options,
|
|
882
|
+
getMessage: config.getMessage,
|
|
850
883
|
})
|
|
851
884
|
]);
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
logger.info('App state sync key arrived, triggering app state sync');
|
|
885
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
886
|
+
pendingAppStateSync) {
|
|
855
887
|
await doAppStateSync();
|
|
888
|
+
pendingAppStateSync = false;
|
|
889
|
+
}
|
|
890
|
+
async function doAppStateSync() {
|
|
891
|
+
if (!authState.creds.accountSyncCounter) {
|
|
892
|
+
logger.info('doing initial app state sync');
|
|
893
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
894
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
895
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
896
|
+
if (needToFlushWithAppStateSync) {
|
|
897
|
+
logger.debug('flushing with app state sync');
|
|
898
|
+
ev.flush();
|
|
899
|
+
}
|
|
900
|
+
}
|
|
856
901
|
}
|
|
857
902
|
});
|
|
858
903
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
859
904
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
860
905
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
861
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
906
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
862
907
|
const type = attrs.type;
|
|
863
908
|
switch (type) {
|
|
864
909
|
case 'account_sync':
|
|
@@ -880,44 +925,27 @@ export const makeChatsSocket = (config) => {
|
|
|
880
925
|
}
|
|
881
926
|
});
|
|
882
927
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
928
|
+
var _a;
|
|
883
929
|
if (connection === 'open') {
|
|
884
930
|
if (fireInitQueries) {
|
|
885
|
-
executeInitQueries()
|
|
931
|
+
executeInitQueries()
|
|
932
|
+
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
886
933
|
}
|
|
887
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}));
|
|
898
|
-
if (!willSyncHistory) {
|
|
899
|
-
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
900
|
-
syncState = SyncState.Online;
|
|
901
|
-
setTimeout(() => ev.flush(), 0);
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
905
|
-
if (awaitingSyncTimeout) {
|
|
906
|
-
clearTimeout(awaitingSyncTimeout);
|
|
907
|
-
}
|
|
908
|
-
awaitingSyncTimeout = setTimeout(() => {
|
|
909
|
-
if (syncState === SyncState.AwaitingInitialSync) {
|
|
910
|
-
// TODO: investigate
|
|
911
|
-
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
912
|
-
syncState = SyncState.Online;
|
|
913
|
-
ev.flush();
|
|
934
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
935
|
+
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
936
|
+
}
|
|
937
|
+
if (receivedPendingNotifications) {
|
|
938
|
+
// if we don't have the app state key
|
|
939
|
+
// we keep buffering events until we finally have
|
|
940
|
+
// the key and can sync the messages
|
|
941
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
942
|
+
ev.buffer();
|
|
943
|
+
needToFlushWithAppStateSync = true;
|
|
914
944
|
}
|
|
915
|
-
}
|
|
945
|
+
}
|
|
916
946
|
});
|
|
917
947
|
return {
|
|
918
948
|
...sock,
|
|
919
|
-
createCallLink,
|
|
920
|
-
getBotListV2,
|
|
921
949
|
processingMutex,
|
|
922
950
|
fetchPrivacySettings,
|
|
923
951
|
upsertMessage,
|
|
@@ -925,17 +953,14 @@ export const makeChatsSocket = (config) => {
|
|
|
925
953
|
sendPresenceUpdate,
|
|
926
954
|
presenceSubscribe,
|
|
927
955
|
profilePictureUrl,
|
|
956
|
+
onWhatsApp,
|
|
928
957
|
fetchBlocklist,
|
|
929
958
|
fetchStatus,
|
|
930
|
-
fetchDisappearingDuration,
|
|
931
959
|
updateProfilePicture,
|
|
932
960
|
removeProfilePicture,
|
|
933
961
|
updateProfileStatus,
|
|
934
962
|
updateProfileName,
|
|
935
963
|
updateBlockStatus,
|
|
936
|
-
updateDisableLinkPreviewsPrivacy,
|
|
937
|
-
updateCallPrivacy,
|
|
938
|
-
updateMessagesPrivacy,
|
|
939
964
|
updateLastSeenPrivacy,
|
|
940
965
|
updateOnlinePrivacy,
|
|
941
966
|
updateProfilePicturePrivacy,
|
|
@@ -947,16 +972,12 @@ export const makeChatsSocket = (config) => {
|
|
|
947
972
|
resyncAppState,
|
|
948
973
|
chatModify,
|
|
949
974
|
cleanDirtyBits,
|
|
950
|
-
addOrEditContact,
|
|
951
|
-
removeContact,
|
|
952
|
-
addLabel,
|
|
953
975
|
addChatLabel,
|
|
954
976
|
removeChatLabel,
|
|
955
977
|
addMessageLabel,
|
|
978
|
+
checkWhatsApp,
|
|
956
979
|
removeMessageLabel,
|
|
957
|
-
star
|
|
958
|
-
addOrEditQuickReply,
|
|
959
|
-
removeQuickReply
|
|
980
|
+
star
|
|
960
981
|
};
|
|
961
982
|
};
|
|
962
|
-
|
|
983
|
+
exports.makeChatsSocket = makeChatsSocket;
|