@badzz88/baileys 8.5.2 → 8.5.4
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/README.md +1 -1
- package/WAProto/WAProto.proto +1256 -75
- package/WAProto/index.d.ts +36042 -19649
- package/WAProto/index.js +181990 -135645
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +22 -17
- package/lib/Signal/Group/group_cipher.js +5 -5
- package/lib/Signal/Group/keyhelper.js +4 -4
- package/lib/Signal/Group/sender-chain-key.js +2 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-record.js +1 -1
- package/lib/Signal/Group/sender-message-key.js +5 -5
- package/lib/Signal/libsignal.js +39 -59
- package/lib/Signal/lid-mapping.js +28 -10
- package/lib/Socket/aigroups.js +5 -5
- package/lib/Socket/business.js +3 -11
- package/lib/Socket/chats.js +668 -319
- package/lib/Socket/communities.js +85 -89
- package/lib/Socket/graphql.js +435 -228
- package/lib/Socket/groups.js +132 -211
- package/lib/Socket/index.js +9 -7
- package/lib/Socket/interactive-handler.js +117 -60
- package/lib/Socket/interop.js +56 -175
- package/lib/Socket/managed-account.js +79 -48
- package/lib/Socket/messages-recv.js +898 -340
- package/lib/Socket/messages-send.js +462 -160
- package/lib/Socket/mex.js +40 -53
- package/lib/Socket/newsletter.js +291 -291
- package/lib/Socket/privacy.js +77 -265
- package/lib/Socket/registration.js +164 -157
- package/lib/Socket/socket.js +181 -199
- package/lib/Socket/username.js +144 -227
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.js +25 -141
- package/lib/Types/Auth.js +3 -3
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Newsletter.js +96 -65
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +52 -57
- package/lib/Utils/browser-utils.js +1 -1
- package/lib/Utils/business.js +2 -6
- package/lib/Utils/chat-utils.js +102 -38
- package/lib/Utils/crypto.js +54 -84
- package/lib/Utils/decode-wa-message.js +316 -83
- package/lib/Utils/event-buffer.js +37 -61
- package/lib/Utils/generics.js +157 -103
- package/lib/Utils/group-history.js +3 -12
- package/lib/Utils/history.js +15 -15
- package/lib/Utils/index.js +1 -5
- package/lib/Utils/link-preview.js +3 -8
- package/lib/Utils/lt-hash.js +2 -35
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/message-inspect.js +393 -0
- package/lib/Utils/message-retry-manager.js +27 -92
- package/lib/Utils/messages-media.js +159 -130
- package/lib/Utils/messages.js +144 -566
- package/lib/Utils/meta-ai-msmsg.js +62 -202
- package/lib/Utils/noise-handler.js +19 -21
- package/lib/Utils/offline-node-processor.js +3 -8
- package/lib/Utils/pre-key-manager.js +13 -23
- package/lib/Utils/process-message.js +197 -106
- package/lib/Utils/reporting-utils.js +2 -2
- package/lib/Utils/signal.js +28 -63
- package/lib/Utils/stanza-ack.js +39 -12
- package/lib/Utils/sync-action-utils.js +4 -7
- package/lib/Utils/tc-token-utils.js +20 -25
- package/lib/Utils/use-multi-file-auth-state.js +30 -14
- package/lib/Utils/validate-connection.js +59 -19
- package/lib/WABinary/decode.js +50 -16
- package/lib/WABinary/encode.js +54 -224
- package/lib/WABinary/generic-utils.js +7 -97
- package/lib/WABinary/jid-utils.js +27 -14
- package/lib/WAM/encode.js +7 -7
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncBackoff.js +26 -0
- package/lib/WAUSync/USyncQuery.js +77 -6
- package/lib/WAUSync/USyncUser.js +16 -8
- package/lib/WAUSync/index.js +1 -0
- package/lib/antiban.js +608 -854
- package/lib/index.js +3 -3
- package/package.json +16 -19
- package/lib/Socket/luxu.js +0 -387
- package/lib/Socket/text-router.js +0 -83
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Types/Mex.js +0 -112
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/companion-reg-client-utils.js +0 -42
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/sticker.js +0 -145
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
|
@@ -26,21 +26,18 @@ const BUFFERABLE_EVENT = [
|
|
|
26
26
|
'groups.update'
|
|
27
27
|
]
|
|
28
28
|
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
|
|
29
|
-
|
|
30
|
-
* The event buffer logically consolidates different events into a single event
|
|
31
|
-
* making the data processing more efficient.
|
|
32
|
-
*/
|
|
29
|
+
|
|
33
30
|
const makeEventBuffer = logger => {
|
|
34
31
|
const ev = new events_1.default()
|
|
35
32
|
const historyCache = new Set()
|
|
36
33
|
let data = makeBufferData()
|
|
37
34
|
let isBuffering = false
|
|
38
35
|
let bufferTimeout = null
|
|
39
|
-
let flushPendingTimeout = null
|
|
36
|
+
let flushPendingTimeout = null
|
|
40
37
|
let bufferCount = 0
|
|
41
|
-
const MAX_HISTORY_CACHE_SIZE = 10000
|
|
42
|
-
const BUFFER_TIMEOUT_MS = 30000
|
|
43
|
-
|
|
38
|
+
const MAX_HISTORY_CACHE_SIZE = 10000
|
|
39
|
+
const BUFFER_TIMEOUT_MS = 30000
|
|
40
|
+
|
|
44
41
|
ev.on('event', map => {
|
|
45
42
|
for (const event in map) {
|
|
46
43
|
ev.emit(event, map[event])
|
|
@@ -61,7 +58,7 @@ const makeEventBuffer = logger => {
|
|
|
61
58
|
}
|
|
62
59
|
}, BUFFER_TIMEOUT_MS)
|
|
63
60
|
}
|
|
64
|
-
|
|
61
|
+
|
|
65
62
|
bufferCount++
|
|
66
63
|
}
|
|
67
64
|
function flush() {
|
|
@@ -71,7 +68,7 @@ const makeEventBuffer = logger => {
|
|
|
71
68
|
logger.debug({ bufferCount }, 'Flushing event buffer')
|
|
72
69
|
isBuffering = false
|
|
73
70
|
bufferCount = 0
|
|
74
|
-
|
|
71
|
+
|
|
75
72
|
if (bufferTimeout) {
|
|
76
73
|
clearTimeout(bufferTimeout)
|
|
77
74
|
bufferTimeout = null
|
|
@@ -80,7 +77,7 @@ const makeEventBuffer = logger => {
|
|
|
80
77
|
clearTimeout(flushPendingTimeout)
|
|
81
78
|
flushPendingTimeout = null
|
|
82
79
|
}
|
|
83
|
-
|
|
80
|
+
|
|
84
81
|
if (historyCache.size > MAX_HISTORY_CACHE_SIZE) {
|
|
85
82
|
logger.debug({ cacheSize: historyCache.size }, 'Clearing history cache')
|
|
86
83
|
historyCache.clear()
|
|
@@ -114,8 +111,8 @@ const makeEventBuffer = logger => {
|
|
|
114
111
|
}
|
|
115
112
|
},
|
|
116
113
|
emit(event, evData) {
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
|
|
115
|
+
|
|
119
116
|
if (event === 'messages.upsert') {
|
|
120
117
|
const { type } = evData
|
|
121
118
|
const existingUpserts = Object.values(data.messageUpserts)
|
|
@@ -123,14 +120,14 @@ const makeEventBuffer = logger => {
|
|
|
123
120
|
const bufferedType = existingUpserts[0].type
|
|
124
121
|
if (bufferedType !== type) {
|
|
125
122
|
logger.debug({ bufferedType, newType: type }, 'messages.upsert type mismatch, emitting buffered messages')
|
|
126
|
-
|
|
123
|
+
|
|
127
124
|
ev.emit('event', {
|
|
128
125
|
'messages.upsert': {
|
|
129
126
|
messages: existingUpserts.map(m => m.message),
|
|
130
127
|
type: bufferedType
|
|
131
128
|
}
|
|
132
129
|
})
|
|
133
|
-
|
|
130
|
+
|
|
134
131
|
data.messageUpserts = {}
|
|
135
132
|
}
|
|
136
133
|
}
|
|
@@ -151,13 +148,13 @@ const makeEventBuffer = logger => {
|
|
|
151
148
|
buffer()
|
|
152
149
|
try {
|
|
153
150
|
const result = await work(...args)
|
|
154
|
-
|
|
151
|
+
|
|
155
152
|
if (bufferCount === 1) {
|
|
156
153
|
setTimeout(() => {
|
|
157
154
|
if (isBuffering && bufferCount === 1) {
|
|
158
155
|
flush()
|
|
159
156
|
}
|
|
160
|
-
}, 100)
|
|
157
|
+
}, 100)
|
|
161
158
|
}
|
|
162
159
|
return result
|
|
163
160
|
} catch (error) {
|
|
@@ -165,7 +162,7 @@ const makeEventBuffer = logger => {
|
|
|
165
162
|
} finally {
|
|
166
163
|
bufferCount = Math.max(0, bufferCount - 1)
|
|
167
164
|
if (bufferCount === 0) {
|
|
168
|
-
|
|
165
|
+
|
|
169
166
|
if (!flushPendingTimeout) {
|
|
170
167
|
flushPendingTimeout = setTimeout(flush, 100)
|
|
171
168
|
}
|
|
@@ -175,6 +172,7 @@ const makeEventBuffer = logger => {
|
|
|
175
172
|
},
|
|
176
173
|
on: (...args) => ev.on(...args),
|
|
177
174
|
off: (...args) => ev.off(...args),
|
|
175
|
+
once: (...args) => ev.once(...args),
|
|
178
176
|
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
179
177
|
}
|
|
180
178
|
}
|
|
@@ -205,7 +203,7 @@ function append(
|
|
|
205
203
|
data,
|
|
206
204
|
historyCache,
|
|
207
205
|
event,
|
|
208
|
-
|
|
206
|
+
|
|
209
207
|
eventData,
|
|
210
208
|
logger
|
|
211
209
|
) {
|
|
@@ -246,30 +244,6 @@ function append(
|
|
|
246
244
|
}
|
|
247
245
|
data.historySets.empty = false
|
|
248
246
|
data.historySets.syncType = eventData.syncType
|
|
249
|
-
if (eventData.pastParticipants?.length) {
|
|
250
|
-
const merged = new Map()
|
|
251
|
-
const sigOf = p => `${p.userJid || ''}:${p.leaveTs || ''}:${p.leaveReason || ''}`
|
|
252
|
-
const ingest = entry => {
|
|
253
|
-
const key = entry.groupJid ?? JSON.stringify(entry)
|
|
254
|
-
const existing = merged.get(key)
|
|
255
|
-
if (!existing) {
|
|
256
|
-
merged.set(key, { ...entry, pastParticipants: [...(entry.pastParticipants || [])] })
|
|
257
|
-
return
|
|
258
|
-
}
|
|
259
|
-
const seen = new Set((existing.pastParticipants || []).map(sigOf))
|
|
260
|
-
for (const p of entry.pastParticipants || []) {
|
|
261
|
-
const sig = sigOf(p)
|
|
262
|
-
if (!seen.has(sig)) {
|
|
263
|
-
existing.pastParticipants.push(p)
|
|
264
|
-
seen.add(sig)
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
for (const entry of data.historySets.pastParticipants || []) ingest(entry)
|
|
269
|
-
for (const entry of eventData.pastParticipants) ingest(entry)
|
|
270
|
-
data.historySets.pastParticipants = [...merged.values()]
|
|
271
|
-
}
|
|
272
|
-
data.historySets.chunkOrder = eventData.chunkOrder
|
|
273
247
|
data.historySets.progress = eventData.progress
|
|
274
248
|
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId
|
|
275
249
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest
|
|
@@ -302,22 +276,22 @@ function append(
|
|
|
302
276
|
const conditionMatches = update.conditional ? update.conditional(data) : true
|
|
303
277
|
if (conditionMatches) {
|
|
304
278
|
delete update.conditional
|
|
305
|
-
|
|
279
|
+
|
|
306
280
|
const upsert = data.historySets.chats[chatId] || data.chatUpserts[chatId]
|
|
307
281
|
if (upsert) {
|
|
308
282
|
concatChats(upsert, update)
|
|
309
283
|
} else {
|
|
310
|
-
|
|
284
|
+
|
|
311
285
|
const chatUpdate = data.chatUpdates[chatId] || {}
|
|
312
286
|
data.chatUpdates[chatId] = concatChats(chatUpdate, update)
|
|
313
287
|
}
|
|
314
288
|
} else if (conditionMatches === undefined) {
|
|
315
|
-
|
|
289
|
+
|
|
316
290
|
data.chatUpdates[chatId] = update
|
|
317
291
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
321
295
|
if (data.chatDeletes.has(chatId)) {
|
|
322
296
|
data.chatDeletes.delete(chatId)
|
|
323
297
|
}
|
|
@@ -328,7 +302,7 @@ function append(
|
|
|
328
302
|
if (!data.chatDeletes.has(chatId)) {
|
|
329
303
|
data.chatDeletes.add(chatId)
|
|
330
304
|
}
|
|
331
|
-
|
|
305
|
+
|
|
332
306
|
if (data.chatUpdates[chatId]) {
|
|
333
307
|
delete data.chatUpdates[chatId]
|
|
334
308
|
}
|
|
@@ -365,12 +339,12 @@ function append(
|
|
|
365
339
|
const contactUpdates = eventData
|
|
366
340
|
for (const update of contactUpdates) {
|
|
367
341
|
const id = update.id
|
|
368
|
-
|
|
342
|
+
|
|
369
343
|
const upsert = data.historySets.contacts[id] || data.contactUpserts[id]
|
|
370
344
|
if (upsert) {
|
|
371
345
|
Object.assign(upsert, update)
|
|
372
346
|
} else {
|
|
373
|
-
|
|
347
|
+
|
|
374
348
|
const contactUpdate = data.contactUpdates[id] || {}
|
|
375
349
|
data.contactUpdates[id] = Object.assign(contactUpdate, update)
|
|
376
350
|
}
|
|
@@ -412,9 +386,9 @@ function append(
|
|
|
412
386
|
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]?.message
|
|
413
387
|
if (existing) {
|
|
414
388
|
Object.assign(existing, update)
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
418
392
|
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
419
393
|
decrementChatReadCounterIfMsgDidUnread(existing)
|
|
420
394
|
}
|
|
@@ -442,7 +416,11 @@ function append(
|
|
|
442
416
|
}
|
|
443
417
|
}
|
|
444
418
|
} else {
|
|
445
|
-
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
446
424
|
}
|
|
447
425
|
break
|
|
448
426
|
case 'messages.reaction':
|
|
@@ -501,8 +479,8 @@ function append(
|
|
|
501
479
|
}
|
|
502
480
|
}
|
|
503
481
|
function decrementChatReadCounterIfMsgDidUnread(message) {
|
|
504
|
-
|
|
505
|
-
|
|
482
|
+
|
|
483
|
+
|
|
506
484
|
const chatId = message.key.remoteJid
|
|
507
485
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
|
508
486
|
if (
|
|
@@ -526,11 +504,9 @@ function consolidateEvents(data) {
|
|
|
526
504
|
chats: Object.values(data.historySets.chats),
|
|
527
505
|
messages: Object.values(data.historySets.messages),
|
|
528
506
|
contacts: Object.values(data.historySets.contacts),
|
|
529
|
-
pastParticipants: data.historySets.pastParticipants,
|
|
530
507
|
syncType: data.historySets.syncType,
|
|
531
508
|
progress: data.historySets.progress,
|
|
532
509
|
isLatest: data.historySets.isLatest,
|
|
533
|
-
chunkOrder: data.historySets.chunkOrder,
|
|
534
510
|
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
535
511
|
}
|
|
536
512
|
}
|
|
@@ -590,7 +566,7 @@ function consolidateEvents(data) {
|
|
|
590
566
|
}
|
|
591
567
|
function concatChats(a, b) {
|
|
592
568
|
if (
|
|
593
|
-
b.unreadCount === null &&
|
|
569
|
+
b.unreadCount === null &&
|
|
594
570
|
a.unreadCount < 0
|
|
595
571
|
) {
|
|
596
572
|
a.unreadCount = undefined
|