@hansaka02/baileys 7.3.2 → 7.3.6

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 (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
@@ -1,16 +1,15 @@
1
1
  "use strict"
2
2
 
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
3
  Object.defineProperty(exports, "__esModule", { value: true })
8
4
 
9
- const events_1 = __importDefault(require("events"))
10
- const Types_1 = require("../Types")
11
- const generics_1 = require("./generics")
12
- const messages_1 = require("./messages")
13
- const process_message_1 = require("./process-message")
5
+ const EventEmitter = require("events")
6
+ const { WAMessageStatus } = require("../Types")
7
+ const { trimUndefined } = require("./generics")
8
+ const {
9
+ updateMessageWithReceipt,
10
+ updateMessageWithReaction
11
+ } = require("./messages")
12
+ const { isRealMessage } = require("./process-message")
14
13
 
15
14
  const BUFFERABLE_EVENT = [
16
15
  'messaging-history.set',
@@ -35,7 +34,7 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
35
34
  * making the data processing more efficient.
36
35
  */
37
36
  const makeEventBuffer = (logger) => {
38
- const ev = new events_1.default()
37
+ const ev = new EventEmitter()
39
38
  const historyCache = new Set()
40
39
  let data = makeBufferData()
41
40
  let isBuffering = false
@@ -122,10 +121,37 @@ const makeEventBuffer = (logger) => {
122
121
  }
123
122
  },
124
123
  emit(event, evData) {
124
+ // Check if this is a messages.upsert with a different type than what's buffered
125
+ // If so, flush the buffered messages first to avoid type overshadowing
126
+ if (event === 'messages.upsert') {
127
+ const { type } = evData
128
+ const existingUpserts = Object.values(data.messageUpserts)
129
+
130
+ if (existingUpserts.length > 0) {
131
+ const bufferedType = existingUpserts[0].type
132
+
133
+ if (bufferedType !== type) {
134
+ logger.debug({ bufferedType, newType: type }, 'messages.upsert type mismatch, emitting buffered messages')
135
+
136
+ // Emit the buffered messages with their correct type
137
+ ev.emit('event', {
138
+ 'messages.upsert': {
139
+ messages: existingUpserts.map(m => m.message),
140
+ type: bufferedType
141
+ }
142
+ })
143
+
144
+ // Clear the message upserts from the buffer
145
+ data.messageUpserts = {}
146
+ }
147
+ }
148
+ }
149
+
125
150
  if (isBuffering && BUFFERABLE_EVENT_SET.has(event)) {
126
151
  append(data, historyCache, event, evData, logger)
127
152
  return true
128
153
  }
154
+
129
155
  return ev.emit('event', { [event]: evData })
130
156
  },
131
157
  isBuffering() {
@@ -193,42 +219,50 @@ const makeBufferData = () => {
193
219
  }
194
220
 
195
221
  function append(data, historyCache, event, eventData, logger) {
196
- var _a, _b, _c
197
222
  switch (event) {
198
223
  case 'messaging-history.set':
199
224
  for (const chat of eventData.chats) {
200
- const existingChat = data.historySets.chats[chat.id]
225
+ const id = chat.id || ''
226
+ const existingChat = data.historySets.chats[id]
227
+
201
228
  if (existingChat) {
202
229
  existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType
203
230
  }
204
- if (!existingChat && !historyCache.has(chat.id)) {
205
- data.historySets.chats[chat.id] = chat
206
- historyCache.add(chat.id)
231
+
232
+ if (!existingChat && !historyCache.has(id)) {
233
+ data.historySets.chats[id] = chat
234
+ historyCache.add(id)
207
235
  absorbingChatUpdate(chat)
208
236
  }
209
237
  }
238
+
210
239
  for (const contact of eventData.contacts) {
211
240
  const existingContact = data.historySets.contacts[contact.id]
241
+
212
242
  if (existingContact) {
213
- Object.assign(existingContact, generics_1.trimUndefined(contact))
243
+ Object.assign(existingContact, trimUndefined(contact))
214
244
  }
215
245
  else {
216
246
  const historyContactId = `c:${contact.id}`
217
247
  const hasAnyName = contact.notify || contact.name || contact.verifiedName
248
+
218
249
  if (!historyCache.has(historyContactId) || hasAnyName) {
219
250
  data.historySets.contacts[contact.id] = contact
220
251
  historyCache.add(historyContactId)
221
252
  }
222
253
  }
223
254
  }
255
+
224
256
  for (const message of eventData.messages) {
225
257
  const key = stringifyMessageKey(message.key)
226
258
  const existingMsg = data.historySets.messages[key]
259
+
227
260
  if (!existingMsg && !historyCache.has(key)) {
228
261
  data.historySets.messages[key] = message
229
262
  historyCache.add(key)
230
263
  }
231
264
  }
265
+
232
266
  data.historySets.empty = false
233
267
  data.historySets.syncType = eventData.syncType
234
268
  data.historySets.progress = eventData.progress
@@ -237,23 +271,30 @@ function append(data, historyCache, event, eventData, logger) {
237
271
  break
238
272
  case 'chats.upsert':
239
273
  for (const chat of eventData) {
240
- let upsert = data.chatUpserts[chat.id]
241
- if (!upsert) {
242
- upsert = data.historySets[chat.id]
274
+ const id = chat.id || ''
275
+
276
+ let upsert = data.chatUpserts[id]
277
+
278
+ if (id && !upsert) {
279
+ upsert = data.historySets.chats[id]
280
+
243
281
  if (upsert) {
244
- logger.debug({ chatId: chat.id }, 'absorbed chat upsert in chat set')
282
+ logger.debug({ chatId: id }, 'absorbed chat upsert in chat set')
245
283
  }
246
284
  }
285
+
247
286
  if (upsert) {
248
287
  upsert = concatChats(upsert, chat)
249
288
  }
250
289
  else {
251
290
  upsert = chat
252
- data.chatUpserts[chat.id] = upsert
291
+ data.chatUpserts[id] = upsert
253
292
  }
293
+
254
294
  absorbingChatUpdate(upsert)
255
- if (data.chatDeletes.has(chat.id)) {
256
- data.chatDeletes.delete(chat.id)
295
+
296
+ if (data.chatDeletes.has(id)) {
297
+ data.chatDeletes.delete(id)
257
298
  }
258
299
  }
259
300
  break
@@ -313,14 +354,14 @@ function append(data, historyCache, event, eventData, logger) {
313
354
  }
314
355
  }
315
356
  if (upsert) {
316
- upsert = Object.assign(upsert, generics_1.trimUndefined(contact))
357
+ upsert = Object.assign(upsert, trimUndefined(contact))
317
358
  }
318
359
  else {
319
360
  upsert = contact
320
361
  data.contactUpserts[contact.id] = upsert
321
362
  }
322
363
  if (data.contactUpdates[contact.id]) {
323
- upsert = Object.assign(data.contactUpdates[contact.id], generics_1.trimUndefined(contact))
364
+ upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact))
324
365
  delete data.contactUpdates[contact.id]
325
366
  }
326
367
  }
@@ -343,47 +384,55 @@ function append(data, historyCache, event, eventData, logger) {
343
384
  break
344
385
  case 'messages.upsert':
345
386
  const { messages, type } = eventData
387
+
346
388
  for (const message of messages) {
347
389
  const key = stringifyMessageKey(message.key)
348
- let existing = (_a = data.messageUpserts[key]) === null || _a === void 0 ? void 0 : _a.message
390
+
391
+ let existing = data.messageUpserts[key]?.message
392
+
349
393
  if (!existing) {
350
394
  existing = data.historySets.messages[key]
395
+
351
396
  if (existing) {
352
397
  logger.debug({ messageId: key }, 'absorbed message upsert in message set')
353
398
  }
354
399
  }
400
+
355
401
  if (existing) {
356
402
  message.messageTimestamp = existing.messageTimestamp
357
403
  }
404
+
358
405
  if (data.messageUpdates[key]) {
359
406
  logger.debug('absorbed prior message update in message upsert')
360
407
  Object.assign(message, data.messageUpdates[key].update)
361
408
  delete data.messageUpdates[key]
362
409
  }
410
+
363
411
  if (data.historySets.messages[key]) {
364
412
  data.historySets.messages[key] = message
365
413
  }
366
414
  else {
367
415
  data.messageUpserts[key] = {
368
416
  message,
369
- type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify'
370
- ? 'notify'
371
- : type
417
+ type: type === 'notify' || data.messageUpserts[key]?.type === 'notify' ? 'notify' : type
372
418
  }
373
419
  }
374
420
  }
375
421
  break
376
422
  case 'messages.update':
377
423
  const msgUpdates = eventData
424
+
378
425
  for (const { key, update } of msgUpdates) {
379
426
  const keyStr = stringifyMessageKey(key)
380
- const existing = data.historySets.messages[keyStr] || ((_c = data.messageUpserts[keyStr]) === null || _c === void 0 ? void 0 : _c.message)
427
+ const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]?.message
428
+
381
429
  if (existing) {
382
430
  Object.assign(existing, update)
431
+
383
432
  // if the message was received & read by us
384
433
  // the chat counter must have been incremented
385
434
  // so we need to decrement it
386
- if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
435
+ if (update.status === WAMessageStatus.READ && !key.fromMe) {
387
436
  decrementChatReadCounterIfMsgDidUnread(existing)
388
437
  }
389
438
  }
@@ -421,11 +470,11 @@ function append(data, historyCache, event, eventData, logger) {
421
470
  // const keyStr = stringifyMessageKey(pollUpdateMessageKey)
422
471
  // const existing = data.messagePollings[keyStr]
423
472
  // if(existing) {
424
- // messages_1.updateMessageWithPollUpdate(existing.message, pollUpdates)
473
+ // updateMessageWithPollUpdate(existing.message, pollUpdates)
425
474
  // } else {
426
475
  // data.messagePollings[keyStr] = data.messagePollings[keyStr]
427
476
  // || { pollUpdateMessageKey, pollUpdates: [] }
428
- // messages_1.updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
477
+ // updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
429
478
  // }
430
479
  // }
431
480
  // break
@@ -435,12 +484,12 @@ function append(data, historyCache, event, eventData, logger) {
435
484
  const keyStr = stringifyMessageKey(key)
436
485
  const existing = data.messageUpserts[keyStr]
437
486
  if (existing) {
438
- messages_1.updateMessageWithReaction(existing.message, reaction)
487
+ updateMessageWithReaction(existing.message, reaction)
439
488
  }
440
489
  else {
441
490
  data.messageReactions[keyStr] = data.messageReactions[keyStr]
442
491
  || { key, reactions: [] }
443
- messages_1.updateMessageWithReaction(data.messageReactions[keyStr], reaction)
492
+ updateMessageWithReaction(data.messageReactions[keyStr], reaction)
444
493
  }
445
494
  }
446
495
  break
@@ -450,12 +499,12 @@ function append(data, historyCache, event, eventData, logger) {
450
499
  const keyStr = stringifyMessageKey(key)
451
500
  const existing = data.messageUpserts[keyStr]
452
501
  if (existing) {
453
- messages_1.updateMessageWithReceipt(existing.message, receipt)
502
+ updateMessageWithReceipt(existing.message, receipt)
454
503
  }
455
504
  else {
456
505
  data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
457
506
  || { key, userReceipt: [] }
458
- messages_1.updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
507
+ updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
459
508
  }
460
509
  }
461
510
  break
@@ -472,11 +521,14 @@ function append(data, historyCache, event, eventData, logger) {
472
521
  default:
473
522
  throw new Error(`"${event}" cannot be buffered`)
474
523
  }
524
+
475
525
  function absorbingChatUpdate(existing) {
476
- const chatId = existing.id
526
+ const chatId = existing.id || ''
477
527
  const update = data.chatUpdates[chatId]
528
+
478
529
  if (update) {
479
530
  const conditionMatches = update.conditional ? update.conditional(data) : true
531
+
480
532
  if (conditionMatches) {
481
533
  delete update.conditional
482
534
  logger.debug({ chatId }, 'absorbed chat update in existing chat')
@@ -489,17 +541,20 @@ function append(data, historyCache, event, eventData, logger) {
489
541
  }
490
542
  }
491
543
  }
544
+
492
545
  function decrementChatReadCounterIfMsgDidUnread(message) {
493
546
  // decrement chat unread counter
494
547
  // if the message has already been marked read by us
495
548
  const chatId = message.key.remoteJid
496
549
  const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
497
- if (process_message_1.isRealMessage(message, '')
498
- && process_message_1.shouldIncrementChatUnread(message)
499
- && typeof (chat?.unreadCount) === 'number'
500
- && chat.unreadCount > 0) {
550
+
551
+ if (isRealMessage(message) &&
552
+ shouldIncrementChatUnread(message) &&
553
+ typeof chat?.unreadCount === 'number' &&
554
+ chat.unreadCount > 0) {
501
555
  logger.debug({ chatId: chat.id }, 'decrementing chat counter')
502
556
  chat.unreadCount -= 1
557
+
503
558
  if (chat.unreadCount === 0) {
504
559
  delete chat.unreadCount
505
560
  }