@badzz88/baileys 8.5.4 → 8.5.5
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 +75 -1256
- package/WAProto/index.d.ts +19729 -36122
- package/WAProto/index.js +132193 -178538
- package/engine-requirements.js +15 -7
- package/lib/Defaults/index.js +14 -22
- 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 +28 -39
- package/lib/Signal/lid-mapping.js +8 -28
- package/lib/Socket/aigroups.js +5 -5
- package/lib/Socket/business.js +11 -3
- package/lib/Socket/chats.js +319 -668
- package/lib/Socket/communities.js +89 -85
- package/lib/Socket/graphql.js +228 -435
- package/lib/Socket/groups.js +211 -132
- package/lib/Socket/index.js +7 -9
- package/lib/Socket/interactive-handler.js +60 -117
- package/lib/Socket/interop.js +175 -56
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/managed-account.js +48 -79
- package/lib/Socket/messages-recv.js +340 -898
- package/lib/Socket/messages-send.js +160 -462
- package/lib/Socket/mex.js +53 -40
- package/lib/Socket/newsletter.js +295 -291
- package/lib/Socket/privacy.js +265 -77
- package/lib/Socket/registration.js +157 -164
- package/lib/Socket/socket.js +199 -181
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +227 -144
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.js +141 -25
- package/lib/Types/Auth.js +3 -3
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Mex.js +112 -0
- package/lib/Types/Newsletter.js +65 -96
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +57 -52
- package/lib/Utils/browser-utils.js +1 -1
- package/lib/Utils/business.js +6 -2
- package/lib/Utils/chat-utils.js +38 -102
- package/lib/Utils/command-loader.d.ts +31 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +42 -0
- package/lib/Utils/crypto.js +84 -54
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +83 -316
- package/lib/Utils/event-buffer.js +61 -37
- package/lib/Utils/generics.js +103 -157
- package/lib/Utils/group-history.js +12 -3
- package/lib/Utils/history.js +15 -15
- package/lib/Utils/index.js +5 -1
- package/lib/Utils/link-preview.js +8 -3
- package/lib/Utils/lt-hash.js +35 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/message-retry-manager.js +92 -27
- package/lib/Utils/messages-media.js +130 -159
- package/lib/Utils/messages.js +566 -144
- package/lib/Utils/meta-ai-msmsg.js +202 -62
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +21 -19
- package/lib/Utils/offline-node-processor.js +8 -3
- package/lib/Utils/pre-key-manager.js +23 -13
- package/lib/Utils/process-message.js +106 -197
- package/lib/Utils/reporting-utils.js +2 -2
- package/lib/Utils/session-pool.d.ts +16 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +63 -28
- package/lib/Utils/stanza-ack.js +12 -39
- package/lib/Utils/sticker.d.ts +17 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +7 -4
- package/lib/Utils/tc-token-utils.js +25 -20
- package/lib/Utils/use-multi-file-auth-state.js +14 -30
- package/lib/Utils/validate-connection.js +19 -59
- package/lib/Utils/view-once-cache.d.ts +9 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/WABinary/decode.js +16 -50
- package/lib/WABinary/encode.js +224 -54
- package/lib/WABinary/generic-utils.js +97 -7
- package/lib/WABinary/jid-utils.js +14 -27
- package/lib/WAM/encode.js +7 -7
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +1 -58
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +1 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -13
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +4 -1
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +7 -20
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +1 -2
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +6 -77
- package/lib/WAUSync/USyncUser.js +8 -16
- package/lib/WAUSync/index.js +0 -1
- package/lib/antiban.js +854 -608
- package/lib/index.js +1 -1
- package/package.json +20 -16
|
@@ -26,18 +26,21 @@ const BUFFERABLE_EVENT = [
|
|
|
26
26
|
'groups.update'
|
|
27
27
|
]
|
|
28
28
|
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The event buffer logically consolidates different events into a single event
|
|
31
|
+
* making the data processing more efficient.
|
|
32
|
+
*/
|
|
30
33
|
const makeEventBuffer = logger => {
|
|
31
34
|
const ev = new events_1.default()
|
|
32
35
|
const historyCache = new Set()
|
|
33
36
|
let data = makeBufferData()
|
|
34
37
|
let isBuffering = false
|
|
35
38
|
let bufferTimeout = null
|
|
36
|
-
let flushPendingTimeout = null
|
|
39
|
+
let flushPendingTimeout = null // Add a specific timer for the debounced flush to prevent leak
|
|
37
40
|
let bufferCount = 0
|
|
38
|
-
const MAX_HISTORY_CACHE_SIZE = 10000
|
|
39
|
-
const BUFFER_TIMEOUT_MS = 30000
|
|
40
|
-
|
|
41
|
+
const MAX_HISTORY_CACHE_SIZE = 10000 // Limit the history cache size to prevent memory bloat
|
|
42
|
+
const BUFFER_TIMEOUT_MS = 30000 // 30 seconds
|
|
43
|
+
// take the generic event and fire it as a baileys event
|
|
41
44
|
ev.on('event', map => {
|
|
42
45
|
for (const event in map) {
|
|
43
46
|
ev.emit(event, map[event])
|
|
@@ -58,7 +61,7 @@ const makeEventBuffer = logger => {
|
|
|
58
61
|
}
|
|
59
62
|
}, BUFFER_TIMEOUT_MS)
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
// Always increment count when requested
|
|
62
65
|
bufferCount++
|
|
63
66
|
}
|
|
64
67
|
function flush() {
|
|
@@ -68,7 +71,7 @@ const makeEventBuffer = logger => {
|
|
|
68
71
|
logger.debug({ bufferCount }, 'Flushing event buffer')
|
|
69
72
|
isBuffering = false
|
|
70
73
|
bufferCount = 0
|
|
71
|
-
|
|
74
|
+
// Clear timeout
|
|
72
75
|
if (bufferTimeout) {
|
|
73
76
|
clearTimeout(bufferTimeout)
|
|
74
77
|
bufferTimeout = null
|
|
@@ -77,7 +80,7 @@ const makeEventBuffer = logger => {
|
|
|
77
80
|
clearTimeout(flushPendingTimeout)
|
|
78
81
|
flushPendingTimeout = null
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
// Clear history cache if it exceeds the max size
|
|
81
84
|
if (historyCache.size > MAX_HISTORY_CACHE_SIZE) {
|
|
82
85
|
logger.debug({ cacheSize: historyCache.size }, 'Clearing history cache')
|
|
83
86
|
historyCache.clear()
|
|
@@ -111,8 +114,8 @@ const makeEventBuffer = logger => {
|
|
|
111
114
|
}
|
|
112
115
|
},
|
|
113
116
|
emit(event, evData) {
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
// Check if this is a messages.upsert with a different type than what's buffered
|
|
118
|
+
// If so, flush the buffered messages first to avoid type overshadowing
|
|
116
119
|
if (event === 'messages.upsert') {
|
|
117
120
|
const { type } = evData
|
|
118
121
|
const existingUpserts = Object.values(data.messageUpserts)
|
|
@@ -120,14 +123,14 @@ const makeEventBuffer = logger => {
|
|
|
120
123
|
const bufferedType = existingUpserts[0].type
|
|
121
124
|
if (bufferedType !== type) {
|
|
122
125
|
logger.debug({ bufferedType, newType: type }, 'messages.upsert type mismatch, emitting buffered messages')
|
|
123
|
-
|
|
126
|
+
// Emit the buffered messages with their correct type
|
|
124
127
|
ev.emit('event', {
|
|
125
128
|
'messages.upsert': {
|
|
126
129
|
messages: existingUpserts.map(m => m.message),
|
|
127
130
|
type: bufferedType
|
|
128
131
|
}
|
|
129
132
|
})
|
|
130
|
-
|
|
133
|
+
// Clear the message upserts from the buffer
|
|
131
134
|
data.messageUpserts = {}
|
|
132
135
|
}
|
|
133
136
|
}
|
|
@@ -148,13 +151,13 @@ const makeEventBuffer = logger => {
|
|
|
148
151
|
buffer()
|
|
149
152
|
try {
|
|
150
153
|
const result = await work(...args)
|
|
151
|
-
|
|
154
|
+
// If this is the only buffer, flush after a small delay
|
|
152
155
|
if (bufferCount === 1) {
|
|
153
156
|
setTimeout(() => {
|
|
154
157
|
if (isBuffering && bufferCount === 1) {
|
|
155
158
|
flush()
|
|
156
159
|
}
|
|
157
|
-
}, 100)
|
|
160
|
+
}, 100) // Small delay to allow nested buffers
|
|
158
161
|
}
|
|
159
162
|
return result
|
|
160
163
|
} catch (error) {
|
|
@@ -162,7 +165,7 @@ const makeEventBuffer = logger => {
|
|
|
162
165
|
} finally {
|
|
163
166
|
bufferCount = Math.max(0, bufferCount - 1)
|
|
164
167
|
if (bufferCount === 0) {
|
|
165
|
-
|
|
168
|
+
// Only schedule ONE timeout, not 10,000
|
|
166
169
|
if (!flushPendingTimeout) {
|
|
167
170
|
flushPendingTimeout = setTimeout(flush, 100)
|
|
168
171
|
}
|
|
@@ -172,7 +175,6 @@ const makeEventBuffer = logger => {
|
|
|
172
175
|
},
|
|
173
176
|
on: (...args) => ev.on(...args),
|
|
174
177
|
off: (...args) => ev.off(...args),
|
|
175
|
-
once: (...args) => ev.once(...args),
|
|
176
178
|
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -203,7 +205,7 @@ function append(
|
|
|
203
205
|
data,
|
|
204
206
|
historyCache,
|
|
205
207
|
event,
|
|
206
|
-
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
209
|
eventData,
|
|
208
210
|
logger
|
|
209
211
|
) {
|
|
@@ -244,6 +246,30 @@ function append(
|
|
|
244
246
|
}
|
|
245
247
|
data.historySets.empty = false
|
|
246
248
|
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
|
|
247
273
|
data.historySets.progress = eventData.progress
|
|
248
274
|
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId
|
|
249
275
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest
|
|
@@ -276,22 +302,22 @@ function append(
|
|
|
276
302
|
const conditionMatches = update.conditional ? update.conditional(data) : true
|
|
277
303
|
if (conditionMatches) {
|
|
278
304
|
delete update.conditional
|
|
279
|
-
|
|
305
|
+
// if there is an existing upsert, merge the update into it
|
|
280
306
|
const upsert = data.historySets.chats[chatId] || data.chatUpserts[chatId]
|
|
281
307
|
if (upsert) {
|
|
282
308
|
concatChats(upsert, update)
|
|
283
309
|
} else {
|
|
284
|
-
|
|
310
|
+
// merge the update into the existing update
|
|
285
311
|
const chatUpdate = data.chatUpdates[chatId] || {}
|
|
286
312
|
data.chatUpdates[chatId] = concatChats(chatUpdate, update)
|
|
287
313
|
}
|
|
288
314
|
} else if (conditionMatches === undefined) {
|
|
289
|
-
|
|
315
|
+
// condition yet to be fulfilled
|
|
290
316
|
data.chatUpdates[chatId] = update
|
|
291
317
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
318
|
+
// otherwise -- condition not met, update is invalid
|
|
319
|
+
// if the chat has been updated
|
|
320
|
+
// ignore any existing chat delete
|
|
295
321
|
if (data.chatDeletes.has(chatId)) {
|
|
296
322
|
data.chatDeletes.delete(chatId)
|
|
297
323
|
}
|
|
@@ -302,7 +328,7 @@ function append(
|
|
|
302
328
|
if (!data.chatDeletes.has(chatId)) {
|
|
303
329
|
data.chatDeletes.add(chatId)
|
|
304
330
|
}
|
|
305
|
-
|
|
331
|
+
// remove any prior updates & upserts
|
|
306
332
|
if (data.chatUpdates[chatId]) {
|
|
307
333
|
delete data.chatUpdates[chatId]
|
|
308
334
|
}
|
|
@@ -339,12 +365,12 @@ function append(
|
|
|
339
365
|
const contactUpdates = eventData
|
|
340
366
|
for (const update of contactUpdates) {
|
|
341
367
|
const id = update.id
|
|
342
|
-
|
|
368
|
+
// merge into prior upsert
|
|
343
369
|
const upsert = data.historySets.contacts[id] || data.contactUpserts[id]
|
|
344
370
|
if (upsert) {
|
|
345
371
|
Object.assign(upsert, update)
|
|
346
372
|
} else {
|
|
347
|
-
|
|
373
|
+
// merge into prior update
|
|
348
374
|
const contactUpdate = data.contactUpdates[id] || {}
|
|
349
375
|
data.contactUpdates[id] = Object.assign(contactUpdate, update)
|
|
350
376
|
}
|
|
@@ -386,9 +412,9 @@ function append(
|
|
|
386
412
|
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]?.message
|
|
387
413
|
if (existing) {
|
|
388
414
|
Object.assign(existing, update)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
415
|
+
// if the message was received & read by us
|
|
416
|
+
// the chat counter must have been incremented
|
|
417
|
+
// so we need to decrement it
|
|
392
418
|
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
393
419
|
decrementChatReadCounterIfMsgDidUnread(existing)
|
|
394
420
|
}
|
|
@@ -416,11 +442,7 @@ function append(
|
|
|
416
442
|
}
|
|
417
443
|
}
|
|
418
444
|
} else {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
445
|
+
// TODO: add support
|
|
424
446
|
}
|
|
425
447
|
break
|
|
426
448
|
case 'messages.reaction':
|
|
@@ -479,8 +501,8 @@ function append(
|
|
|
479
501
|
}
|
|
480
502
|
}
|
|
481
503
|
function decrementChatReadCounterIfMsgDidUnread(message) {
|
|
482
|
-
|
|
483
|
-
|
|
504
|
+
// decrement chat unread counter
|
|
505
|
+
// if the message has already been marked read by us
|
|
484
506
|
const chatId = message.key.remoteJid
|
|
485
507
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
|
486
508
|
if (
|
|
@@ -504,9 +526,11 @@ function consolidateEvents(data) {
|
|
|
504
526
|
chats: Object.values(data.historySets.chats),
|
|
505
527
|
messages: Object.values(data.historySets.messages),
|
|
506
528
|
contacts: Object.values(data.historySets.contacts),
|
|
529
|
+
pastParticipants: data.historySets.pastParticipants,
|
|
507
530
|
syncType: data.historySets.syncType,
|
|
508
531
|
progress: data.historySets.progress,
|
|
509
532
|
isLatest: data.historySets.isLatest,
|
|
533
|
+
chunkOrder: data.historySets.chunkOrder,
|
|
510
534
|
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
511
535
|
}
|
|
512
536
|
}
|
|
@@ -566,7 +590,7 @@ function consolidateEvents(data) {
|
|
|
566
590
|
}
|
|
567
591
|
function concatChats(a, b) {
|
|
568
592
|
if (
|
|
569
|
-
b.unreadCount === null &&
|
|
593
|
+
b.unreadCount === null && // neutralize unread counter
|
|
570
594
|
a.unreadCount < 0
|
|
571
595
|
) {
|
|
572
596
|
a.unreadCount = undefined
|