@baileys-md/baileys 11.0.3 → 11.1.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/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
package/lib/Socket/chats.js
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
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 node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
|
+
const WAProto_1 = require("../../WAProto");
|
|
10
|
+
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const Types_1 = require("../Types");
|
|
12
|
+
const Utils_1 = require("../Utils");
|
|
13
|
+
const jimp_1 = require('jimp');
|
|
14
|
+
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
|
+
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
16
|
+
const WABinary_1 = require("../WABinary");
|
|
17
|
+
const WAUSync_1 = require("../WAUSync");
|
|
18
|
+
const usync_1 = require("./usync");
|
|
13
19
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
14
|
-
|
|
15
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
16
|
-
const sock = makeUSyncSocket(config);
|
|
17
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
20
|
+
const makeChatsSocket = (config) => {
|
|
21
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
22
|
+
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
23
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
18
24
|
let privacySettings;
|
|
19
25
|
let needToFlushWithAppStateSync = false;
|
|
20
26
|
let pendingAppStateSync = false;
|
|
21
27
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
22
|
-
const processingMutex = makeMutex();
|
|
23
|
-
const placeholderResendCache = config.placeholderResendCache ||
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
+
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
29
|
+
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
30
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
31
|
+
useClones: false
|
|
32
|
+
});
|
|
28
33
|
if (!config.placeholderResendCache) {
|
|
29
34
|
config.placeholderResendCache = placeholderResendCache;
|
|
30
35
|
}
|
|
@@ -39,12 +44,14 @@ export const makeChatsSocket = (config) => {
|
|
|
39
44
|
tag: 'iq',
|
|
40
45
|
attrs: {
|
|
41
46
|
xmlns: 'privacy',
|
|
42
|
-
to: S_WHATSAPP_NET,
|
|
47
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
43
48
|
type: 'get'
|
|
44
49
|
},
|
|
45
|
-
content: [
|
|
50
|
+
content: [
|
|
51
|
+
{ tag: 'privacy', attrs: {} }
|
|
52
|
+
]
|
|
46
53
|
});
|
|
47
|
-
privacySettings = reduceBinaryNodeToDictionary(content
|
|
54
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
48
55
|
}
|
|
49
56
|
return privacySettings;
|
|
50
57
|
};
|
|
@@ -54,11 +61,10 @@ export const makeChatsSocket = (config) => {
|
|
|
54
61
|
tag: 'iq',
|
|
55
62
|
attrs: {
|
|
56
63
|
xmlns: 'privacy',
|
|
57
|
-
to: S_WHATSAPP_NET,
|
|
64
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
58
65
|
type: 'set'
|
|
59
66
|
},
|
|
60
|
-
content: [
|
|
61
|
-
{
|
|
67
|
+
content: [{
|
|
62
68
|
tag: 'privacy',
|
|
63
69
|
attrs: {},
|
|
64
70
|
content: [
|
|
@@ -67,8 +73,7 @@ export const makeChatsSocket = (config) => {
|
|
|
67
73
|
attrs: { name, value }
|
|
68
74
|
}
|
|
69
75
|
]
|
|
70
|
-
}
|
|
71
|
-
]
|
|
76
|
+
}]
|
|
72
77
|
});
|
|
73
78
|
};
|
|
74
79
|
const updateMessagesPrivacy = async (value) => {
|
|
@@ -100,17 +105,15 @@ export const makeChatsSocket = (config) => {
|
|
|
100
105
|
tag: 'iq',
|
|
101
106
|
attrs: {
|
|
102
107
|
xmlns: 'disappearing_mode',
|
|
103
|
-
to: S_WHATSAPP_NET,
|
|
108
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
104
109
|
type: 'set'
|
|
105
110
|
},
|
|
106
|
-
content: [
|
|
107
|
-
{
|
|
111
|
+
content: [{
|
|
108
112
|
tag: 'disappearing_mode',
|
|
109
113
|
attrs: {
|
|
110
114
|
duration: duration.toString()
|
|
111
115
|
}
|
|
112
|
-
}
|
|
113
|
-
]
|
|
116
|
+
}]
|
|
114
117
|
});
|
|
115
118
|
};
|
|
116
119
|
const getBotListV2 = async () => {
|
|
@@ -118,23 +121,21 @@ export const makeChatsSocket = (config) => {
|
|
|
118
121
|
tag: 'iq',
|
|
119
122
|
attrs: {
|
|
120
123
|
xmlns: 'bot',
|
|
121
|
-
to: S_WHATSAPP_NET,
|
|
124
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
122
125
|
type: 'get'
|
|
123
126
|
},
|
|
124
|
-
content: [
|
|
125
|
-
{
|
|
127
|
+
content: [{
|
|
126
128
|
tag: 'bot',
|
|
127
129
|
attrs: {
|
|
128
130
|
v: '2'
|
|
129
131
|
}
|
|
130
|
-
}
|
|
131
|
-
]
|
|
132
|
+
}]
|
|
132
133
|
});
|
|
133
|
-
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
134
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
134
135
|
const botList = [];
|
|
135
|
-
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
136
|
+
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
|
136
137
|
if (section.attrs.type === 'all') {
|
|
137
|
-
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
138
|
+
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
|
138
139
|
botList.push({
|
|
139
140
|
jid: bot.attrs.jid,
|
|
140
141
|
personaId: bot.attrs['persona_id']
|
|
@@ -145,20 +146,23 @@ export const makeChatsSocket = (config) => {
|
|
|
145
146
|
return botList;
|
|
146
147
|
};
|
|
147
148
|
const onWhatsApp = async (...jids) => {
|
|
148
|
-
const usyncQuery = new USyncQuery()
|
|
149
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
150
|
+
.withContactProtocol()
|
|
151
|
+
.withLIDProtocol();
|
|
149
152
|
for (const jid of jids) {
|
|
150
|
-
const phone = `+${jid.replace('+', '').split('@')[0]
|
|
151
|
-
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
153
|
+
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
154
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
152
155
|
}
|
|
153
156
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
154
157
|
if (results) {
|
|
155
|
-
return results.list.filter(a => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
158
|
+
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
156
159
|
}
|
|
157
160
|
};
|
|
158
161
|
const fetchStatus = async (...jids) => {
|
|
159
|
-
const usyncQuery = new USyncQuery()
|
|
162
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
163
|
+
.withStatusProtocol();
|
|
160
164
|
for (const jid of jids) {
|
|
161
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
165
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
162
166
|
}
|
|
163
167
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
164
168
|
if (result) {
|
|
@@ -166,9 +170,10 @@ export const makeChatsSocket = (config) => {
|
|
|
166
170
|
}
|
|
167
171
|
};
|
|
168
172
|
const fetchDisappearingDuration = async (...jids) => {
|
|
169
|
-
const usyncQuery = new USyncQuery()
|
|
173
|
+
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
174
|
+
.withDisappearingModeProtocol();
|
|
170
175
|
for (const jid of jids) {
|
|
171
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
176
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
172
177
|
}
|
|
173
178
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
174
179
|
if (result) {
|
|
@@ -177,14 +182,24 @@ export const makeChatsSocket = (config) => {
|
|
|
177
182
|
};
|
|
178
183
|
/** update the profile picture for yourself or a group */
|
|
179
184
|
const updateProfilePicture = async (jid, content) => {
|
|
180
|
-
let targetJid;
|
|
185
|
+
let targetJid;
|
|
186
|
+
const generate_1 = async (media) => {
|
|
187
|
+
const jimp = await jimp_1.read(media);
|
|
188
|
+
const min = await jimp.getWidth();
|
|
189
|
+
const max = await jimp.getHeight();
|
|
190
|
+
const cropped = await jimp.crop(0, 0, min, max);
|
|
191
|
+
return {
|
|
192
|
+
img: await cropped.scaleToFit(720, 720).getBufferAsync(jimp_1.MIME_JPEG),
|
|
193
|
+
preview: await cropped.normalize().getBufferAsync(jimp_1.MIME_JPEG)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
181
196
|
if (!jid) {
|
|
182
197
|
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');
|
|
183
198
|
}
|
|
184
199
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
185
200
|
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
186
201
|
}
|
|
187
|
-
const { img } = await
|
|
202
|
+
const { img } = await generate_1(content);
|
|
188
203
|
await query({
|
|
189
204
|
tag: 'iq',
|
|
190
205
|
attrs: {
|
|
@@ -206,21 +221,18 @@ export const makeChatsSocket = (config) => {
|
|
|
206
221
|
const removeProfilePicture = async (jid) => {
|
|
207
222
|
let targetJid;
|
|
208
223
|
if (!jid) {
|
|
209
|
-
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
210
|
-
}
|
|
211
|
-
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
212
|
-
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
224
|
+
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');
|
|
213
225
|
}
|
|
214
|
-
|
|
215
|
-
targetJid =
|
|
226
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
227
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
216
228
|
}
|
|
217
229
|
await query({
|
|
218
230
|
tag: 'iq',
|
|
219
231
|
attrs: {
|
|
220
|
-
|
|
232
|
+
target: targetJid,
|
|
233
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
221
234
|
type: 'set',
|
|
222
|
-
xmlns: 'w:profile:picture'
|
|
223
|
-
...(targetJid ? { target: targetJid } : {})
|
|
235
|
+
xmlns: 'w:profile:picture'
|
|
224
236
|
}
|
|
225
237
|
});
|
|
226
238
|
};
|
|
@@ -229,7 +241,7 @@ export const makeChatsSocket = (config) => {
|
|
|
229
241
|
await query({
|
|
230
242
|
tag: 'iq',
|
|
231
243
|
attrs: {
|
|
232
|
-
to: S_WHATSAPP_NET,
|
|
244
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
233
245
|
type: 'set',
|
|
234
246
|
xmlns: 'status'
|
|
235
247
|
},
|
|
@@ -250,19 +262,20 @@ export const makeChatsSocket = (config) => {
|
|
|
250
262
|
tag: 'iq',
|
|
251
263
|
attrs: {
|
|
252
264
|
xmlns: 'blocklist',
|
|
253
|
-
to: S_WHATSAPP_NET,
|
|
265
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
254
266
|
type: 'get'
|
|
255
267
|
}
|
|
256
268
|
});
|
|
257
|
-
const listNode = getBinaryNodeChild(result, 'list');
|
|
258
|
-
return getBinaryNodeChildren(listNode, 'item')
|
|
269
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
270
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
271
|
+
.map(n => n.attrs.jid);
|
|
259
272
|
};
|
|
260
273
|
const updateBlockStatus = async (jid, action) => {
|
|
261
274
|
await query({
|
|
262
275
|
tag: 'iq',
|
|
263
276
|
attrs: {
|
|
264
277
|
xmlns: 'blocklist',
|
|
265
|
-
to: S_WHATSAPP_NET,
|
|
278
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
266
279
|
type: 'set'
|
|
267
280
|
},
|
|
268
281
|
content: [
|
|
@@ -277,6 +290,7 @@ export const makeChatsSocket = (config) => {
|
|
|
277
290
|
});
|
|
278
291
|
};
|
|
279
292
|
const getBusinessProfile = async (jid) => {
|
|
293
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
280
294
|
const results = await query({
|
|
281
295
|
tag: 'iq',
|
|
282
296
|
attrs: {
|
|
@@ -284,42 +298,38 @@ export const makeChatsSocket = (config) => {
|
|
|
284
298
|
xmlns: 'w:biz',
|
|
285
299
|
type: 'get'
|
|
286
300
|
},
|
|
287
|
-
content: [
|
|
288
|
-
{
|
|
301
|
+
content: [{
|
|
289
302
|
tag: 'business_profile',
|
|
290
303
|
attrs: { v: '244' },
|
|
291
|
-
content: [
|
|
292
|
-
{
|
|
304
|
+
content: [{
|
|
293
305
|
tag: 'profile',
|
|
294
306
|
attrs: { jid }
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
]
|
|
307
|
+
}]
|
|
308
|
+
}]
|
|
299
309
|
});
|
|
300
|
-
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
301
|
-
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
310
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
311
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
302
312
|
if (profiles) {
|
|
303
|
-
const address = getBinaryNodeChild(profiles, 'address');
|
|
304
|
-
const description = getBinaryNodeChild(profiles, 'description');
|
|
305
|
-
const website = getBinaryNodeChild(profiles, 'website');
|
|
306
|
-
const email = getBinaryNodeChild(profiles, 'email');
|
|
307
|
-
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
308
|
-
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
313
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
314
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
315
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
316
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
317
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
318
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
309
319
|
const businessHoursConfig = businessHours
|
|
310
|
-
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
320
|
+
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
311
321
|
: undefined;
|
|
312
|
-
const websiteStr = website
|
|
322
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
313
323
|
return {
|
|
314
|
-
wid: profiles.attrs
|
|
315
|
-
address: address
|
|
316
|
-
description: description
|
|
324
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
325
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
326
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
317
327
|
website: websiteStr ? [websiteStr] : [],
|
|
318
|
-
email: email
|
|
319
|
-
category: category
|
|
320
|
-
business_hours: {
|
|
321
|
-
timezone: businessHours
|
|
322
|
-
business_config: businessHoursConfig
|
|
328
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
329
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
330
|
+
'business_hours': {
|
|
331
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
332
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
323
333
|
}
|
|
324
334
|
};
|
|
325
335
|
}
|
|
@@ -329,17 +339,17 @@ export const makeChatsSocket = (config) => {
|
|
|
329
339
|
await sendNode({
|
|
330
340
|
tag: 'iq',
|
|
331
341
|
attrs: {
|
|
332
|
-
to: S_WHATSAPP_NET,
|
|
342
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
333
343
|
type: 'set',
|
|
334
344
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
335
|
-
id: generateMessageTag()
|
|
345
|
+
id: generateMessageTag(),
|
|
336
346
|
},
|
|
337
347
|
content: [
|
|
338
348
|
{
|
|
339
349
|
tag: 'clean',
|
|
340
350
|
attrs: {
|
|
341
351
|
type,
|
|
342
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
352
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
343
353
|
}
|
|
344
354
|
}
|
|
345
355
|
]
|
|
@@ -348,7 +358,7 @@ export const makeChatsSocket = (config) => {
|
|
|
348
358
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
349
359
|
return {
|
|
350
360
|
onMutation(mutation) {
|
|
351
|
-
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
361
|
+
(0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
352
362
|
}
|
|
353
363
|
};
|
|
354
364
|
};
|
|
@@ -358,6 +368,7 @@ export const makeChatsSocket = (config) => {
|
|
|
358
368
|
const initialVersionMap = {};
|
|
359
369
|
const globalMutationMap = {};
|
|
360
370
|
await authState.keys.transaction(async () => {
|
|
371
|
+
var _a;
|
|
361
372
|
const collectionsToHandle = new Set(collections);
|
|
362
373
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
363
374
|
const attemptsMap = {};
|
|
@@ -376,7 +387,7 @@ export const makeChatsSocket = (config) => {
|
|
|
376
387
|
}
|
|
377
388
|
}
|
|
378
389
|
else {
|
|
379
|
-
state = newLTHashState();
|
|
390
|
+
state = (0, Utils_1.newLTHashState)();
|
|
380
391
|
}
|
|
381
392
|
states[name] = state;
|
|
382
393
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -386,14 +397,14 @@ export const makeChatsSocket = (config) => {
|
|
|
386
397
|
name,
|
|
387
398
|
version: state.version.toString(),
|
|
388
399
|
// return snapshot if being synced from scratch
|
|
389
|
-
return_snapshot: (!state.version).toString()
|
|
400
|
+
'return_snapshot': (!state.version).toString()
|
|
390
401
|
}
|
|
391
402
|
});
|
|
392
403
|
}
|
|
393
404
|
const result = await query({
|
|
394
405
|
tag: 'iq',
|
|
395
406
|
attrs: {
|
|
396
|
-
to: S_WHATSAPP_NET,
|
|
407
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
397
408
|
xmlns: 'w:sync:app:state',
|
|
398
409
|
type: 'set'
|
|
399
410
|
},
|
|
@@ -406,13 +417,13 @@ export const makeChatsSocket = (config) => {
|
|
|
406
417
|
]
|
|
407
418
|
});
|
|
408
419
|
// extract from binary node
|
|
409
|
-
const decoded = await extractSyncdPatches(result, config
|
|
420
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
410
421
|
for (const key in decoded) {
|
|
411
422
|
const name = key;
|
|
412
423
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
413
424
|
try {
|
|
414
425
|
if (snapshot) {
|
|
415
|
-
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
426
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
416
427
|
states[name] = newState;
|
|
417
428
|
Object.assign(globalMutationMap, mutationMap);
|
|
418
429
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
@@ -420,7 +431,7 @@ export const makeChatsSocket = (config) => {
|
|
|
420
431
|
}
|
|
421
432
|
// only process if there are syncd patches
|
|
422
433
|
if (patches.length) {
|
|
423
|
-
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
434
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
424
435
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
425
436
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
426
437
|
initialVersionMap[name] = newState.version;
|
|
@@ -429,17 +440,16 @@ export const makeChatsSocket = (config) => {
|
|
|
429
440
|
if (hasMorePatches) {
|
|
430
441
|
logger.info(`${name} has more patches...`);
|
|
431
442
|
}
|
|
432
|
-
else {
|
|
433
|
-
// collection is done with sync
|
|
443
|
+
else { // collection is done with sync
|
|
434
444
|
collectionsToHandle.delete(name);
|
|
435
445
|
}
|
|
436
446
|
}
|
|
437
447
|
catch (error) {
|
|
438
448
|
// if retry attempts overshoot
|
|
439
449
|
// or key not found
|
|
440
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
441
|
-
error.output
|
|
442
|
-
error.name === 'TypeError';
|
|
450
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
451
|
+
|| ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
|
|
452
|
+
|| error.name === 'TypeError';
|
|
443
453
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
444
454
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
445
455
|
// increment number of retries
|
|
@@ -463,19 +473,22 @@ export const makeChatsSocket = (config) => {
|
|
|
463
473
|
* type = "image for the high res picture"
|
|
464
474
|
*/
|
|
465
475
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
466
|
-
|
|
476
|
+
var _a;
|
|
477
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
467
478
|
const result = await query({
|
|
468
479
|
tag: 'iq',
|
|
469
480
|
attrs: {
|
|
470
481
|
target: jid,
|
|
471
|
-
to: S_WHATSAPP_NET,
|
|
482
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
472
483
|
type: 'get',
|
|
473
484
|
xmlns: 'w:profile:picture'
|
|
474
485
|
},
|
|
475
|
-
content: [
|
|
486
|
+
content: [
|
|
487
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
488
|
+
]
|
|
476
489
|
}, timeoutMs);
|
|
477
|
-
const child = getBinaryNodeChild(result, 'picture');
|
|
478
|
-
return child
|
|
490
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
491
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
479
492
|
};
|
|
480
493
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
481
494
|
const me = authState.creds.me;
|
|
@@ -488,19 +501,17 @@ export const makeChatsSocket = (config) => {
|
|
|
488
501
|
await sendNode({
|
|
489
502
|
tag: 'presence',
|
|
490
503
|
attrs: {
|
|
491
|
-
name: me.name
|
|
504
|
+
name: me.name,
|
|
492
505
|
type
|
|
493
506
|
}
|
|
494
507
|
});
|
|
495
508
|
}
|
|
496
509
|
else {
|
|
497
|
-
const { server } = jidDecode(toJid);
|
|
498
|
-
const isLid = server === 'lid';
|
|
499
510
|
await sendNode({
|
|
500
511
|
tag: 'chatstate',
|
|
501
512
|
attrs: {
|
|
502
|
-
from:
|
|
503
|
-
to: toJid
|
|
513
|
+
from: me.id,
|
|
514
|
+
to: toJid,
|
|
504
515
|
},
|
|
505
516
|
content: [
|
|
506
517
|
{
|
|
@@ -515,7 +526,7 @@ export const makeChatsSocket = (config) => {
|
|
|
515
526
|
* @param toJid the jid to subscribe to
|
|
516
527
|
* @param tcToken token for subscription, use if present
|
|
517
528
|
*/
|
|
518
|
-
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
529
|
+
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
519
530
|
tag: 'presence',
|
|
520
531
|
attrs: {
|
|
521
532
|
to: toJid,
|
|
@@ -531,12 +542,13 @@ export const makeChatsSocket = (config) => {
|
|
|
531
542
|
}
|
|
532
543
|
]
|
|
533
544
|
: undefined
|
|
534
|
-
});
|
|
545
|
+
}));
|
|
535
546
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
547
|
+
var _a;
|
|
536
548
|
let presence;
|
|
537
549
|
const jid = attrs.from;
|
|
538
550
|
const participant = attrs.participant || attrs.from;
|
|
539
|
-
if (shouldIgnoreJid(jid) && jid
|
|
551
|
+
if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
|
|
540
552
|
return;
|
|
541
553
|
}
|
|
542
554
|
if (tag === 'presence') {
|
|
@@ -551,7 +563,7 @@ export const makeChatsSocket = (config) => {
|
|
|
551
563
|
if (type === 'paused') {
|
|
552
564
|
type = 'available';
|
|
553
565
|
}
|
|
554
|
-
if (firstChild.attrs
|
|
566
|
+
if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
|
|
555
567
|
type = 'recording';
|
|
556
568
|
}
|
|
557
569
|
presence = { lastKnownPresence: type };
|
|
@@ -567,7 +579,7 @@ export const makeChatsSocket = (config) => {
|
|
|
567
579
|
const name = patchCreate.type;
|
|
568
580
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
569
581
|
if (!myAppStateKeyId) {
|
|
570
|
-
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
582
|
+
throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
|
|
571
583
|
}
|
|
572
584
|
let initial;
|
|
573
585
|
let encodeResult;
|
|
@@ -576,13 +588,13 @@ export const makeChatsSocket = (config) => {
|
|
|
576
588
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
577
589
|
await resyncAppState([name], false);
|
|
578
590
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
579
|
-
initial = currentSyncVersion || newLTHashState();
|
|
580
|
-
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
591
|
+
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
592
|
+
encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
581
593
|
const { patch, state } = encodeResult;
|
|
582
594
|
const node = {
|
|
583
595
|
tag: 'iq',
|
|
584
596
|
attrs: {
|
|
585
|
-
to: S_WHATSAPP_NET,
|
|
597
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
586
598
|
type: 'set',
|
|
587
599
|
xmlns: 'w:sync:app:state'
|
|
588
600
|
},
|
|
@@ -596,13 +608,13 @@ export const makeChatsSocket = (config) => {
|
|
|
596
608
|
attrs: {
|
|
597
609
|
name,
|
|
598
610
|
version: (state.version - 1).toString(),
|
|
599
|
-
return_snapshot: 'false'
|
|
611
|
+
'return_snapshot': 'false'
|
|
600
612
|
},
|
|
601
613
|
content: [
|
|
602
614
|
{
|
|
603
615
|
tag: 'patch',
|
|
604
616
|
attrs: {},
|
|
605
|
-
content: proto.SyncdPatch.encode(patch).finish()
|
|
617
|
+
content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
|
|
606
618
|
}
|
|
607
619
|
]
|
|
608
620
|
}
|
|
@@ -616,7 +628,7 @@ export const makeChatsSocket = (config) => {
|
|
|
616
628
|
});
|
|
617
629
|
if (config.emitOwnEvents) {
|
|
618
630
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
619
|
-
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
631
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
620
632
|
for (const key in mutationMap) {
|
|
621
633
|
onMutation(mutationMap[key]);
|
|
622
634
|
}
|
|
@@ -624,32 +636,29 @@ export const makeChatsSocket = (config) => {
|
|
|
624
636
|
};
|
|
625
637
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
626
638
|
const fetchProps = async () => {
|
|
639
|
+
var _a, _b, _c;
|
|
627
640
|
const resultNode = await query({
|
|
628
641
|
tag: 'iq',
|
|
629
642
|
attrs: {
|
|
630
|
-
to: S_WHATSAPP_NET,
|
|
643
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
631
644
|
xmlns: 'w',
|
|
632
|
-
type: 'get'
|
|
645
|
+
type: 'get',
|
|
633
646
|
},
|
|
634
647
|
content: [
|
|
635
|
-
{
|
|
636
|
-
tag: 'props',
|
|
637
|
-
attrs: {
|
|
648
|
+
{ tag: 'props', attrs: {
|
|
638
649
|
protocol: '2',
|
|
639
|
-
hash: authState
|
|
640
|
-
}
|
|
641
|
-
}
|
|
650
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
651
|
+
} }
|
|
642
652
|
]
|
|
643
653
|
});
|
|
644
|
-
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
654
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
645
655
|
let props = {};
|
|
646
656
|
if (propsNode) {
|
|
647
|
-
if (propsNode.attrs
|
|
648
|
-
|
|
649
|
-
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
657
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
|
|
658
|
+
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
650
659
|
ev.emit('creds.update', authState.creds);
|
|
651
660
|
}
|
|
652
|
-
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
661
|
+
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
653
662
|
}
|
|
654
663
|
logger.debug('fetched props');
|
|
655
664
|
return props;
|
|
@@ -658,9 +667,9 @@ export const makeChatsSocket = (config) => {
|
|
|
658
667
|
* modify a chat -- mark unread, read etc.
|
|
659
668
|
* lastMessages must be sorted in reverse chronologically
|
|
660
669
|
* requires the last messages till the last message received; required for archive & unread
|
|
661
|
-
|
|
670
|
+
*/
|
|
662
671
|
const chatModify = (mod, jid) => {
|
|
663
|
-
const patch = chatModificationToAppPatch(mod, jid);
|
|
672
|
+
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
664
673
|
return appPatch(patch);
|
|
665
674
|
};
|
|
666
675
|
/**
|
|
@@ -674,32 +683,6 @@ export const makeChatsSocket = (config) => {
|
|
|
674
683
|
}
|
|
675
684
|
}, jid);
|
|
676
685
|
};
|
|
677
|
-
/**
|
|
678
|
-
* Add or Edit Contact
|
|
679
|
-
*/
|
|
680
|
-
const addOrEditContact = (jid, contact) => {
|
|
681
|
-
return chatModify({
|
|
682
|
-
contact
|
|
683
|
-
}, jid);
|
|
684
|
-
};
|
|
685
|
-
/**
|
|
686
|
-
* Remove Contact
|
|
687
|
-
*/
|
|
688
|
-
const removeContact = (jid) => {
|
|
689
|
-
return chatModify({
|
|
690
|
-
contact: null
|
|
691
|
-
}, jid);
|
|
692
|
-
};
|
|
693
|
-
/**
|
|
694
|
-
* Adds label
|
|
695
|
-
*/
|
|
696
|
-
const addLabel = (jid, labels) => {
|
|
697
|
-
return chatModify({
|
|
698
|
-
addLabel: {
|
|
699
|
-
...labels
|
|
700
|
-
}
|
|
701
|
-
}, jid);
|
|
702
|
-
};
|
|
703
686
|
/**
|
|
704
687
|
* Adds label for the chats
|
|
705
688
|
*/
|
|
@@ -747,24 +730,30 @@ export const makeChatsSocket = (config) => {
|
|
|
747
730
|
* help ensure parity with WA Web
|
|
748
731
|
* */
|
|
749
732
|
const executeInitQueries = async () => {
|
|
750
|
-
await Promise.all([
|
|
733
|
+
await Promise.all([
|
|
734
|
+
fetchProps(),
|
|
735
|
+
fetchBlocklist(),
|
|
736
|
+
fetchPrivacySettings(),
|
|
737
|
+
]);
|
|
751
738
|
};
|
|
752
739
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
740
|
+
var _a, _b, _c;
|
|
753
741
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
754
742
|
if (!!msg.pushName) {
|
|
755
|
-
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
756
|
-
jid = jidNormalizedUser(jid);
|
|
743
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
|
|
744
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
757
745
|
if (!msg.key.fromMe) {
|
|
758
746
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
759
747
|
}
|
|
760
748
|
// update our pushname too
|
|
761
|
-
if (msg.key.fromMe && msg.pushName && authState.creds.me
|
|
749
|
+
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
762
750
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
763
751
|
}
|
|
764
752
|
}
|
|
765
|
-
const historyMsg = getHistoryMsg(msg.message);
|
|
753
|
+
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
766
754
|
const shouldProcessHistoryMsg = historyMsg
|
|
767
|
-
? shouldSyncHistoryMessage(historyMsg)
|
|
755
|
+
? (shouldSyncHistoryMessage(historyMsg)
|
|
756
|
+
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
768
757
|
: false;
|
|
769
758
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
770
759
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
@@ -772,29 +761,32 @@ export const makeChatsSocket = (config) => {
|
|
|
772
761
|
}
|
|
773
762
|
await Promise.all([
|
|
774
763
|
(async () => {
|
|
775
|
-
if (historyMsg
|
|
764
|
+
if (historyMsg
|
|
765
|
+
&& authState.creds.myAppStateKeyId) {
|
|
776
766
|
pendingAppStateSync = false;
|
|
777
767
|
await doAppStateSync();
|
|
778
768
|
}
|
|
779
769
|
})(),
|
|
780
|
-
|
|
770
|
+
(0, process_message_1.default)(msg, {
|
|
781
771
|
shouldProcessHistoryMsg,
|
|
782
772
|
placeholderResendCache,
|
|
783
773
|
ev,
|
|
784
774
|
creds: authState.creds,
|
|
785
775
|
keyStore: authState.keys,
|
|
786
776
|
logger,
|
|
787
|
-
options: config.options
|
|
777
|
+
options: config.options,
|
|
778
|
+
getMessage: config.getMessage,
|
|
788
779
|
})
|
|
789
780
|
]);
|
|
790
|
-
if (msg.message
|
|
781
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
782
|
+
&& pendingAppStateSync) {
|
|
791
783
|
await doAppStateSync();
|
|
792
784
|
pendingAppStateSync = false;
|
|
793
785
|
}
|
|
794
786
|
async function doAppStateSync() {
|
|
795
787
|
if (!authState.creds.accountSyncCounter) {
|
|
796
788
|
logger.info('doing initial app state sync');
|
|
797
|
-
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
789
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
798
790
|
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
799
791
|
ev.emit('creds.update', { accountSyncCounter });
|
|
800
792
|
if (needToFlushWithAppStateSync) {
|
|
@@ -807,7 +799,7 @@ export const makeChatsSocket = (config) => {
|
|
|
807
799
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
808
800
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
809
801
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
810
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
802
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
811
803
|
const type = attrs.type;
|
|
812
804
|
switch (type) {
|
|
813
805
|
case 'account_sync':
|
|
@@ -829,19 +821,23 @@ export const makeChatsSocket = (config) => {
|
|
|
829
821
|
}
|
|
830
822
|
});
|
|
831
823
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
824
|
+
var _a;
|
|
832
825
|
if (connection === 'open') {
|
|
833
826
|
if (fireInitQueries) {
|
|
834
|
-
executeInitQueries()
|
|
827
|
+
executeInitQueries()
|
|
828
|
+
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
835
829
|
}
|
|
836
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
830
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
831
|
+
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
837
832
|
}
|
|
838
|
-
if (receivedPendingNotifications
|
|
833
|
+
if (receivedPendingNotifications) {
|
|
834
|
+
// if we don't have the app state key
|
|
839
835
|
// we keep buffering events until we finally have
|
|
840
836
|
// the key and can sync the messages
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
837
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
838
|
+
ev.buffer();
|
|
839
|
+
needToFlushWithAppStateSync = true;
|
|
840
|
+
}
|
|
845
841
|
}
|
|
846
842
|
});
|
|
847
843
|
return {
|
|
@@ -856,8 +852,8 @@ export const makeChatsSocket = (config) => {
|
|
|
856
852
|
profilePictureUrl,
|
|
857
853
|
onWhatsApp,
|
|
858
854
|
fetchBlocklist,
|
|
859
|
-
fetchStatus,
|
|
860
855
|
fetchDisappearingDuration,
|
|
856
|
+
fetchStatus,
|
|
861
857
|
updateProfilePicture,
|
|
862
858
|
removeProfilePicture,
|
|
863
859
|
updateProfileStatus,
|
|
@@ -876,9 +872,6 @@ export const makeChatsSocket = (config) => {
|
|
|
876
872
|
resyncAppState,
|
|
877
873
|
chatModify,
|
|
878
874
|
cleanDirtyBits,
|
|
879
|
-
addOrEditContact,
|
|
880
|
-
removeContact,
|
|
881
|
-
addLabel,
|
|
882
875
|
addChatLabel,
|
|
883
876
|
removeChatLabel,
|
|
884
877
|
addMessageLabel,
|
|
@@ -886,4 +879,4 @@ export const makeChatsSocket = (config) => {
|
|
|
886
879
|
star
|
|
887
880
|
};
|
|
888
881
|
};
|
|
889
|
-
|
|
882
|
+
exports.makeChatsSocket = makeChatsSocket;
|