@badzz88/baileys 8.5.3 → 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.
Files changed (110) hide show
  1. package/README.md +1 -1
  2. package/WAProto/WAProto.proto +1256 -75
  3. package/WAProto/index.d.ts +36042 -19649
  4. package/WAProto/index.js +181990 -135645
  5. package/engine-requirements.js +7 -15
  6. package/lib/Defaults/index.js +22 -17
  7. package/lib/Signal/Group/group_cipher.js +5 -5
  8. package/lib/Signal/Group/keyhelper.js +4 -4
  9. package/lib/Signal/Group/sender-chain-key.js +2 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-record.js +1 -1
  13. package/lib/Signal/Group/sender-message-key.js +5 -5
  14. package/lib/Signal/libsignal.js +39 -59
  15. package/lib/Signal/lid-mapping.js +28 -10
  16. package/lib/Socket/aigroups.js +5 -5
  17. package/lib/Socket/business.js +3 -11
  18. package/lib/Socket/chats.js +668 -319
  19. package/lib/Socket/communities.js +85 -89
  20. package/lib/Socket/graphql.js +435 -228
  21. package/lib/Socket/groups.js +132 -211
  22. package/lib/Socket/index.js +9 -7
  23. package/lib/Socket/interactive-handler.js +117 -60
  24. package/lib/Socket/interop.js +56 -175
  25. package/lib/Socket/managed-account.js +79 -48
  26. package/lib/Socket/messages-recv.js +898 -340
  27. package/lib/Socket/messages-send.js +462 -160
  28. package/lib/Socket/mex.js +40 -53
  29. package/lib/Socket/newsletter.js +291 -295
  30. package/lib/Socket/privacy.js +77 -265
  31. package/lib/Socket/registration.js +164 -157
  32. package/lib/Socket/socket.js +181 -199
  33. package/lib/Socket/username.js +144 -227
  34. package/lib/Store/make-cache-manager-store.js +2 -2
  35. package/lib/Store/make-in-memory-store.js +25 -141
  36. package/lib/Types/Auth.js +3 -3
  37. package/lib/Types/Label.js +1 -1
  38. package/lib/Types/LabelAssociation.js +1 -1
  39. package/lib/Types/Newsletter.js +96 -65
  40. package/lib/Types/State.js +4 -4
  41. package/lib/Types/index.js +1 -1
  42. package/lib/Utils/auth-utils.js +52 -57
  43. package/lib/Utils/browser-utils.js +1 -1
  44. package/lib/Utils/business.js +2 -6
  45. package/lib/Utils/chat-utils.js +102 -38
  46. package/lib/Utils/crypto.js +54 -84
  47. package/lib/Utils/decode-wa-message.js +316 -83
  48. package/lib/Utils/event-buffer.js +37 -61
  49. package/lib/Utils/generics.js +157 -103
  50. package/lib/Utils/group-history.js +3 -12
  51. package/lib/Utils/history.js +15 -15
  52. package/lib/Utils/index.js +1 -5
  53. package/lib/Utils/link-preview.js +3 -8
  54. package/lib/Utils/lt-hash.js +2 -35
  55. package/lib/Utils/make-mutex.js +1 -1
  56. package/lib/Utils/message-inspect.js +393 -0
  57. package/lib/Utils/message-retry-manager.js +27 -92
  58. package/lib/Utils/messages-media.js +159 -130
  59. package/lib/Utils/messages.js +144 -566
  60. package/lib/Utils/meta-ai-msmsg.js +62 -202
  61. package/lib/Utils/noise-handler.js +19 -21
  62. package/lib/Utils/offline-node-processor.js +3 -8
  63. package/lib/Utils/pre-key-manager.js +13 -23
  64. package/lib/Utils/process-message.js +197 -106
  65. package/lib/Utils/reporting-utils.js +2 -2
  66. package/lib/Utils/signal.js +28 -63
  67. package/lib/Utils/stanza-ack.js +39 -12
  68. package/lib/Utils/sync-action-utils.js +4 -7
  69. package/lib/Utils/tc-token-utils.js +20 -25
  70. package/lib/Utils/use-multi-file-auth-state.js +30 -14
  71. package/lib/Utils/validate-connection.js +59 -19
  72. package/lib/WABinary/decode.js +50 -16
  73. package/lib/WABinary/encode.js +54 -224
  74. package/lib/WABinary/generic-utils.js +7 -97
  75. package/lib/WABinary/jid-utils.js +27 -14
  76. package/lib/WAM/encode.js +7 -7
  77. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
  78. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
  79. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
  80. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
  81. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
  82. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
  83. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
  84. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
  85. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
  86. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
  87. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
  88. package/lib/WAUSync/Protocols/index.js +1 -0
  89. package/lib/WAUSync/USyncBackoff.js +26 -0
  90. package/lib/WAUSync/USyncQuery.js +77 -6
  91. package/lib/WAUSync/USyncUser.js +16 -8
  92. package/lib/WAUSync/index.js +1 -0
  93. package/lib/antiban.js +608 -854
  94. package/lib/index.js +1 -1
  95. package/package.json +16 -20
  96. package/lib/Socket/luxu.js +0 -387
  97. package/lib/Socket/text-router.js +0 -83
  98. package/lib/Store/keyed-db.js +0 -108
  99. package/lib/Types/Mex.js +0 -112
  100. package/lib/Utils/command-loader.d.ts +0 -31
  101. package/lib/Utils/command-loader.js +0 -100
  102. package/lib/Utils/companion-reg-client-utils.js +0 -42
  103. package/lib/Utils/curve25519-js.js +0 -275
  104. package/lib/Utils/native-bridge.js +0 -82
  105. package/lib/Utils/session-pool.d.ts +0 -16
  106. package/lib/Utils/session-pool.js +0 -94
  107. package/lib/Utils/sticker.d.ts +0 -17
  108. package/lib/Utils/sticker.js +0 -145
  109. package/lib/Utils/view-once-cache.d.ts +0 -9
  110. 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 // Add a specific timer for the debounced flush to prevent leak
36
+ let flushPendingTimeout = null
40
37
  let bufferCount = 0
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
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
- // Always increment count when requested
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
- // Clear timeout
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
- // Clear history cache if it exceeds the max size
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
- // 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
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
- // Emit the buffered messages with their correct type
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
- // Clear the message upserts from the buffer
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
- // If this is the only buffer, flush after a small delay
151
+
155
152
  if (bufferCount === 1) {
156
153
  setTimeout(() => {
157
154
  if (isBuffering && bufferCount === 1) {
158
155
  flush()
159
156
  }
160
- }, 100) // Small delay to allow nested buffers
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
- // Only schedule ONE timeout, not 10,000
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
- // if there is an existing upsert, merge the update into it
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
- // merge the update into the existing update
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
- // condition yet to be fulfilled
289
+
316
290
  data.chatUpdates[chatId] = update
317
291
  }
318
- // otherwise -- condition not met, update is invalid
319
- // if the chat has been updated
320
- // ignore any existing chat delete
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
- // remove any prior updates & upserts
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
- // merge into prior upsert
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
- // merge into prior update
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
- // if the message was received & read by us
416
- // the chat counter must have been incremented
417
- // so we need to decrement it
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
- // TODO: add support
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
- // decrement chat unread counter
505
- // if the message has already been marked read by us
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 && // neutralize unread counter
569
+ b.unreadCount === null &&
594
570
  a.unreadCount < 0
595
571
  ) {
596
572
  a.unreadCount = undefined