@queenanya/baileys 7.5.11 → 8.0.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.
Files changed (157) hide show
  1. package/package.json +13 -97
  2. package/LICENSE +0 -21
  3. package/README.md +0 -931
  4. package/WAProto/GenerateStatics.sh +0 -4
  5. package/WAProto/WAProto.proto +0 -3344
  6. package/WAProto/index.d.ts +0 -37016
  7. package/WAProto/index.js +0 -101044
  8. package/WASignalGroup/GroupProtocol.js +0 -1697
  9. package/WASignalGroup/ciphertext_message.js +0 -16
  10. package/WASignalGroup/group_cipher.js +0 -120
  11. package/WASignalGroup/group_session_builder.js +0 -46
  12. package/WASignalGroup/index.js +0 -5
  13. package/WASignalGroup/keyhelper.js +0 -21
  14. package/WASignalGroup/protobufs.js +0 -3
  15. package/WASignalGroup/queue_job.js +0 -69
  16. package/WASignalGroup/sender_chain_key.js +0 -50
  17. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  18. package/WASignalGroup/sender_key_message.js +0 -92
  19. package/WASignalGroup/sender_key_name.js +0 -70
  20. package/WASignalGroup/sender_key_record.js +0 -56
  21. package/WASignalGroup/sender_key_state.js +0 -129
  22. package/WASignalGroup/sender_message_key.js +0 -39
  23. package/lib/Defaults/baileys-version.json +0 -3
  24. package/lib/Defaults/index.d.ts +0 -53
  25. package/lib/Defaults/index.js +0 -107
  26. package/lib/Signal/libsignal.d.ts +0 -3
  27. package/lib/Signal/libsignal.js +0 -152
  28. package/lib/Socket/Client/index.d.ts +0 -2
  29. package/lib/Socket/Client/index.js +0 -18
  30. package/lib/Socket/Client/types.d.ts +0 -17
  31. package/lib/Socket/Client/types.js +0 -13
  32. package/lib/Socket/Client/websocket.d.ts +0 -12
  33. package/lib/Socket/Client/websocket.js +0 -62
  34. package/lib/Socket/business.d.ts +0 -177
  35. package/lib/Socket/business.js +0 -260
  36. package/lib/Socket/chats.d.ts +0 -91
  37. package/lib/Socket/chats.js +0 -949
  38. package/lib/Socket/groups.d.ts +0 -131
  39. package/lib/Socket/groups.js +0 -314
  40. package/lib/Socket/index.d.ts +0 -177
  41. package/lib/Socket/index.js +0 -10
  42. package/lib/Socket/messages-recv.d.ts +0 -164
  43. package/lib/Socket/messages-recv.js +0 -918
  44. package/lib/Socket/messages-send.d.ts +0 -157
  45. package/lib/Socket/messages-send.js +0 -794
  46. package/lib/Socket/newsletter.d.ts +0 -143
  47. package/lib/Socket/newsletter.js +0 -249
  48. package/lib/Socket/socket.d.ts +0 -45
  49. package/lib/Socket/socket.js +0 -616
  50. package/lib/Store/index.d.ts +0 -3
  51. package/lib/Store/index.js +0 -10
  52. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  53. package/lib/Store/make-cache-manager-store.js +0 -83
  54. package/lib/Store/make-in-memory-store.d.ts +0 -118
  55. package/lib/Store/make-in-memory-store.js +0 -420
  56. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  57. package/lib/Store/make-ordered-dictionary.js +0 -81
  58. package/lib/Store/object-repository.d.ts +0 -10
  59. package/lib/Store/object-repository.js +0 -27
  60. package/lib/Types/Auth.d.ts +0 -105
  61. package/lib/Types/Auth.js +0 -2
  62. package/lib/Types/Call.d.ts +0 -13
  63. package/lib/Types/Call.js +0 -2
  64. package/lib/Types/Chat.d.ts +0 -107
  65. package/lib/Types/Chat.js +0 -4
  66. package/lib/Types/Contact.d.ts +0 -19
  67. package/lib/Types/Contact.js +0 -2
  68. package/lib/Types/Events.d.ts +0 -199
  69. package/lib/Types/Events.js +0 -2
  70. package/lib/Types/GroupMetadata.d.ts +0 -56
  71. package/lib/Types/GroupMetadata.js +0 -2
  72. package/lib/Types/Label.d.ts +0 -46
  73. package/lib/Types/Label.js +0 -27
  74. package/lib/Types/LabelAssociation.d.ts +0 -29
  75. package/lib/Types/LabelAssociation.js +0 -9
  76. package/lib/Types/Message.d.ts +0 -280
  77. package/lib/Types/Message.js +0 -9
  78. package/lib/Types/Newsletter.d.ts +0 -79
  79. package/lib/Types/Newsletter.js +0 -18
  80. package/lib/Types/Product.d.ts +0 -78
  81. package/lib/Types/Product.js +0 -2
  82. package/lib/Types/Signal.d.ts +0 -57
  83. package/lib/Types/Signal.js +0 -2
  84. package/lib/Types/Socket.d.ts +0 -118
  85. package/lib/Types/Socket.js +0 -2
  86. package/lib/Types/State.d.ts +0 -27
  87. package/lib/Types/State.js +0 -2
  88. package/lib/Types/index.d.ts +0 -65
  89. package/lib/Types/index.js +0 -42
  90. package/lib/Utils/auth-utils.d.ts +0 -18
  91. package/lib/Utils/auth-utils.js +0 -200
  92. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  93. package/lib/Utils/baileys-event-stream.js +0 -63
  94. package/lib/Utils/business.d.ts +0 -22
  95. package/lib/Utils/business.js +0 -234
  96. package/lib/Utils/chat-utils.d.ts +0 -72
  97. package/lib/Utils/chat-utils.js +0 -745
  98. package/lib/Utils/crypto.d.ts +0 -42
  99. package/lib/Utils/crypto.js +0 -153
  100. package/lib/Utils/decode-wa-message.d.ts +0 -20
  101. package/lib/Utils/decode-wa-message.js +0 -218
  102. package/lib/Utils/event-buffer.d.ts +0 -35
  103. package/lib/Utils/event-buffer.js +0 -520
  104. package/lib/Utils/generics.d.ts +0 -119
  105. package/lib/Utils/generics.js +0 -467
  106. package/lib/Utils/history.d.ts +0 -19
  107. package/lib/Utils/history.js +0 -94
  108. package/lib/Utils/index.d.ts +0 -18
  109. package/lib/Utils/index.js +0 -34
  110. package/lib/Utils/link-preview.d.ts +0 -21
  111. package/lib/Utils/link-preview.js +0 -116
  112. package/lib/Utils/logger.d.ts +0 -2
  113. package/lib/Utils/logger.js +0 -7
  114. package/lib/Utils/lt-hash.d.ts +0 -12
  115. package/lib/Utils/lt-hash.js +0 -51
  116. package/lib/Utils/make-mutex.d.ts +0 -7
  117. package/lib/Utils/make-mutex.js +0 -44
  118. package/lib/Utils/messages-media.d.ts +0 -131
  119. package/lib/Utils/messages-media.js +0 -786
  120. package/lib/Utils/messages.d.ts +0 -78
  121. package/lib/Utils/messages.js +0 -767
  122. package/lib/Utils/noise-handler.d.ts +0 -21
  123. package/lib/Utils/noise-handler.js +0 -150
  124. package/lib/Utils/process-message.d.ts +0 -42
  125. package/lib/Utils/process-message.js +0 -355
  126. package/lib/Utils/signal.d.ts +0 -32
  127. package/lib/Utils/signal.js +0 -158
  128. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  129. package/lib/Utils/use-multi-file-auth-state.js +0 -94
  130. package/lib/Utils/use-single-file-auth-state.d.ts +0 -5
  131. package/lib/Utils/use-single-file-auth-state.js +0 -66
  132. package/lib/Utils/validate-connection.d.ts +0 -10
  133. package/lib/Utils/validate-connection.js +0 -171
  134. package/lib/WABinary/constants.d.ts +0 -27
  135. package/lib/WABinary/constants.js +0 -40
  136. package/lib/WABinary/decode.d.ts +0 -8
  137. package/lib/WABinary/decode.js +0 -254
  138. package/lib/WABinary/encode.d.ts +0 -2
  139. package/lib/WABinary/encode.js +0 -230
  140. package/lib/WABinary/generic-utils.d.ts +0 -16
  141. package/lib/WABinary/generic-utils.js +0 -110
  142. package/lib/WABinary/index.d.ts +0 -5
  143. package/lib/WABinary/index.js +0 -21
  144. package/lib/WABinary/jid-utils.d.ts +0 -31
  145. package/lib/WABinary/jid-utils.js +0 -62
  146. package/lib/WABinary/types.d.ts +0 -18
  147. package/lib/WABinary/types.js +0 -2
  148. package/lib/WAM/BinaryInfo.d.ts +0 -18
  149. package/lib/WAM/BinaryInfo.js +0 -13
  150. package/lib/WAM/constants.d.ts +0 -39
  151. package/lib/WAM/constants.js +0 -15350
  152. package/lib/WAM/encode.d.ts +0 -4
  153. package/lib/WAM/encode.js +0 -155
  154. package/lib/WAM/index.d.ts +0 -3
  155. package/lib/WAM/index.js +0 -19
  156. package/lib/index.d.ts +0 -11
  157. package/lib/index.js +0 -30
@@ -1,520 +0,0 @@
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.makeEventBuffer = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- const Types_1 = require("../Types");
9
- const generics_1 = require("./generics");
10
- const messages_1 = require("./messages");
11
- const process_message_1 = require("./process-message");
12
- const BUFFERABLE_EVENT = [
13
- 'messaging-history.set',
14
- 'chats.upsert',
15
- 'chats.update',
16
- 'chats.delete',
17
- 'contacts.upsert',
18
- 'contacts.update',
19
- 'messages.upsert',
20
- 'messages.update',
21
- 'messages.delete',
22
- 'messages.reaction',
23
- 'message-receipt.update',
24
- 'groups.update',
25
- ];
26
- const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
27
- /**
28
- * The event buffer logically consolidates different events into a single event
29
- * making the data processing more efficient.
30
- * @param ev the baileys event emitter
31
- */
32
- const makeEventBuffer = (logger) => {
33
- const ev = new events_1.default();
34
- const historyCache = new Set();
35
- let data = makeBufferData();
36
- let buffersInProgress = 0;
37
- // take the generic event and fire it as a baileys event
38
- ev.on('event', (map) => {
39
- for (const event in map) {
40
- ev.emit(event, map[event]);
41
- }
42
- });
43
- function buffer() {
44
- buffersInProgress += 1;
45
- }
46
- function flush(force = false) {
47
- // no buffer going on
48
- if (!buffersInProgress) {
49
- return false;
50
- }
51
- if (!force) {
52
- // reduce the number of buffers in progress
53
- buffersInProgress -= 1;
54
- // if there are still some buffers going on
55
- // then we don't flush now
56
- if (buffersInProgress) {
57
- return false;
58
- }
59
- }
60
- const newData = makeBufferData();
61
- const chatUpdates = Object.values(data.chatUpdates);
62
- // gather the remaining conditional events so we re-queue them
63
- let conditionalChatUpdatesLeft = 0;
64
- for (const update of chatUpdates) {
65
- if (update.conditional) {
66
- conditionalChatUpdatesLeft += 1;
67
- newData.chatUpdates[update.id] = update;
68
- delete data.chatUpdates[update.id];
69
- }
70
- }
71
- const consolidatedData = consolidateEvents(data);
72
- if (Object.keys(consolidatedData).length) {
73
- ev.emit('event', consolidatedData);
74
- }
75
- data = newData;
76
- logger.trace({ conditionalChatUpdatesLeft }, 'released buffered events');
77
- return true;
78
- }
79
- return {
80
- process(handler) {
81
- const listener = (map) => {
82
- handler(map);
83
- };
84
- ev.on('event', listener);
85
- return () => {
86
- ev.off('event', listener);
87
- };
88
- },
89
- emit(event, evData) {
90
- if (buffersInProgress && BUFFERABLE_EVENT_SET.has(event)) {
91
- append(data, historyCache, event, evData, logger);
92
- return true;
93
- }
94
- return ev.emit('event', { [event]: evData });
95
- },
96
- isBuffering() {
97
- return buffersInProgress > 0;
98
- },
99
- buffer,
100
- flush,
101
- createBufferedFunction(work) {
102
- return async (...args) => {
103
- buffer();
104
- try {
105
- const result = await work(...args);
106
- return result;
107
- }
108
- finally {
109
- flush();
110
- }
111
- };
112
- },
113
- on: (...args) => ev.on(...args),
114
- off: (...args) => ev.off(...args),
115
- removeAllListeners: (...args) => ev.removeAllListeners(...args),
116
- };
117
- };
118
- exports.makeEventBuffer = makeEventBuffer;
119
- const makeBufferData = () => {
120
- return {
121
- historySets: {
122
- chats: {},
123
- messages: {},
124
- contacts: {},
125
- isLatest: false,
126
- empty: true
127
- },
128
- chatUpserts: {},
129
- chatUpdates: {},
130
- chatDeletes: new Set(),
131
- contactUpserts: {},
132
- contactUpdates: {},
133
- messageUpserts: {},
134
- messageUpdates: {},
135
- messageReactions: {},
136
- messageDeletes: {},
137
- messageReceipts: {},
138
- groupUpdates: {}
139
- };
140
- };
141
- function append(data, historyCache, event,
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- eventData, logger) {
144
- var _a, _b, _c;
145
- switch (event) {
146
- case 'messaging-history.set':
147
- for (const chat of eventData.chats) {
148
- const existingChat = data.historySets.chats[chat.id];
149
- if (existingChat) {
150
- existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType;
151
- }
152
- if (!existingChat && !historyCache.has(chat.id)) {
153
- data.historySets.chats[chat.id] = chat;
154
- historyCache.add(chat.id);
155
- absorbingChatUpdate(chat);
156
- }
157
- }
158
- for (const contact of eventData.contacts) {
159
- const existingContact = data.historySets.contacts[contact.id];
160
- if (existingContact) {
161
- Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
162
- }
163
- else {
164
- const historyContactId = `c:${contact.id}`;
165
- const hasAnyName = contact.notify || contact.name || contact.verifiedName;
166
- if (!historyCache.has(historyContactId) || hasAnyName) {
167
- data.historySets.contacts[contact.id] = contact;
168
- historyCache.add(historyContactId);
169
- }
170
- }
171
- }
172
- for (const message of eventData.messages) {
173
- const key = stringifyMessageKey(message.key);
174
- const existingMsg = data.historySets.messages[key];
175
- if (!existingMsg && !historyCache.has(key)) {
176
- data.historySets.messages[key] = message;
177
- historyCache.add(key);
178
- }
179
- }
180
- data.historySets.empty = false;
181
- data.historySets.syncType = eventData.syncType;
182
- data.historySets.progress = eventData.progress;
183
- data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
184
- data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
185
- break;
186
- case 'chats.upsert':
187
- for (const chat of eventData) {
188
- let upsert = data.chatUpserts[chat.id];
189
- if (!upsert) {
190
- upsert = data.historySets[chat.id];
191
- if (upsert) {
192
- logger.debug({ chatId: chat.id }, 'absorbed chat upsert in chat set');
193
- }
194
- }
195
- if (upsert) {
196
- upsert = concatChats(upsert, chat);
197
- }
198
- else {
199
- upsert = chat;
200
- data.chatUpserts[chat.id] = upsert;
201
- }
202
- absorbingChatUpdate(upsert);
203
- if (data.chatDeletes.has(chat.id)) {
204
- data.chatDeletes.delete(chat.id);
205
- }
206
- }
207
- break;
208
- case 'chats.update':
209
- for (const update of eventData) {
210
- const chatId = update.id;
211
- const conditionMatches = update.conditional ? update.conditional(data) : true;
212
- if (conditionMatches) {
213
- delete update.conditional;
214
- // if there is an existing upsert, merge the update into it
215
- const upsert = data.historySets.chats[chatId] || data.chatUpserts[chatId];
216
- if (upsert) {
217
- concatChats(upsert, update);
218
- }
219
- else {
220
- // merge the update into the existing update
221
- const chatUpdate = data.chatUpdates[chatId] || {};
222
- data.chatUpdates[chatId] = concatChats(chatUpdate, update);
223
- }
224
- }
225
- else if (conditionMatches === undefined) {
226
- // condition yet to be fulfilled
227
- data.chatUpdates[chatId] = update;
228
- }
229
- // otherwise -- condition not met, update is invalid
230
- // if the chat has been updated
231
- // ignore any existing chat delete
232
- if (data.chatDeletes.has(chatId)) {
233
- data.chatDeletes.delete(chatId);
234
- }
235
- }
236
- break;
237
- case 'chats.delete':
238
- for (const chatId of eventData) {
239
- if (!data.chatDeletes.has(chatId)) {
240
- data.chatDeletes.add(chatId);
241
- }
242
- // remove any prior updates & upserts
243
- if (data.chatUpdates[chatId]) {
244
- delete data.chatUpdates[chatId];
245
- }
246
- if (data.chatUpserts[chatId]) {
247
- delete data.chatUpserts[chatId];
248
- }
249
- if (data.historySets.chats[chatId]) {
250
- delete data.historySets.chats[chatId];
251
- }
252
- }
253
- break;
254
- case 'contacts.upsert':
255
- for (const contact of eventData) {
256
- let upsert = data.contactUpserts[contact.id];
257
- if (!upsert) {
258
- upsert = data.historySets.contacts[contact.id];
259
- if (upsert) {
260
- logger.debug({ contactId: contact.id }, 'absorbed contact upsert in contact set');
261
- }
262
- }
263
- if (upsert) {
264
- upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
265
- }
266
- else {
267
- upsert = contact;
268
- data.contactUpserts[contact.id] = upsert;
269
- }
270
- if (data.contactUpdates[contact.id]) {
271
- upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
272
- delete data.contactUpdates[contact.id];
273
- }
274
- }
275
- break;
276
- case 'contacts.update':
277
- const contactUpdates = eventData;
278
- for (const update of contactUpdates) {
279
- const id = update.id;
280
- // merge into prior upsert
281
- const upsert = data.historySets.contacts[id] || data.contactUpserts[id];
282
- if (upsert) {
283
- Object.assign(upsert, update);
284
- }
285
- else {
286
- // merge into prior update
287
- const contactUpdate = data.contactUpdates[id] || {};
288
- data.contactUpdates[id] = Object.assign(contactUpdate, update);
289
- }
290
- }
291
- break;
292
- case 'messages.upsert':
293
- const { messages, type } = eventData;
294
- for (const message of messages) {
295
- const key = stringifyMessageKey(message.key);
296
- let existing = (_a = data.messageUpserts[key]) === null || _a === void 0 ? void 0 : _a.message;
297
- if (!existing) {
298
- existing = data.historySets.messages[key];
299
- if (existing) {
300
- logger.debug({ messageId: key }, 'absorbed message upsert in message set');
301
- }
302
- }
303
- if (existing) {
304
- message.messageTimestamp = existing.messageTimestamp;
305
- }
306
- if (data.messageUpdates[key]) {
307
- logger.debug('absorbed prior message update in message upsert');
308
- Object.assign(message, data.messageUpdates[key].update);
309
- delete data.messageUpdates[key];
310
- }
311
- if (data.historySets.messages[key]) {
312
- data.historySets.messages[key] = message;
313
- }
314
- else {
315
- data.messageUpserts[key] = {
316
- message,
317
- type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify'
318
- ? 'notify'
319
- : type
320
- };
321
- }
322
- }
323
- break;
324
- case 'messages.update':
325
- const msgUpdates = eventData;
326
- for (const { key, update } of msgUpdates) {
327
- const keyStr = stringifyMessageKey(key);
328
- const existing = data.historySets.messages[keyStr] || ((_c = data.messageUpserts[keyStr]) === null || _c === void 0 ? void 0 : _c.message);
329
- if (existing) {
330
- Object.assign(existing, update);
331
- // if the message was received & read by us
332
- // the chat counter must have been incremented
333
- // so we need to decrement it
334
- if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
335
- decrementChatReadCounterIfMsgDidUnread(existing);
336
- }
337
- }
338
- else {
339
- const msgUpdate = data.messageUpdates[keyStr] || { key, update: {} };
340
- Object.assign(msgUpdate.update, update);
341
- data.messageUpdates[keyStr] = msgUpdate;
342
- }
343
- }
344
- break;
345
- case 'messages.delete':
346
- const deleteData = eventData;
347
- if ('keys' in deleteData) {
348
- const { keys } = deleteData;
349
- for (const key of keys) {
350
- const keyStr = stringifyMessageKey(key);
351
- if (!data.messageDeletes[keyStr]) {
352
- data.messageDeletes[keyStr] = key;
353
- }
354
- if (data.messageUpserts[keyStr]) {
355
- delete data.messageUpserts[keyStr];
356
- }
357
- if (data.messageUpdates[keyStr]) {
358
- delete data.messageUpdates[keyStr];
359
- }
360
- }
361
- }
362
- else {
363
- // TODO: add support
364
- }
365
- break;
366
- case 'messages.reaction':
367
- const reactions = eventData;
368
- for (const { key, reaction } of reactions) {
369
- const keyStr = stringifyMessageKey(key);
370
- const existing = data.messageUpserts[keyStr];
371
- if (existing) {
372
- (0, messages_1.updateMessageWithReaction)(existing.message, reaction);
373
- }
374
- else {
375
- data.messageReactions[keyStr] = data.messageReactions[keyStr]
376
- || { key, reactions: [] };
377
- (0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
378
- }
379
- }
380
- break;
381
- case 'message-receipt.update':
382
- const receipts = eventData;
383
- for (const { key, receipt } of receipts) {
384
- const keyStr = stringifyMessageKey(key);
385
- const existing = data.messageUpserts[keyStr];
386
- if (existing) {
387
- (0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
388
- }
389
- else {
390
- data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
391
- || { key, userReceipt: [] };
392
- (0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
393
- }
394
- }
395
- break;
396
- case 'groups.update':
397
- const groupUpdates = eventData;
398
- for (const update of groupUpdates) {
399
- const id = update.id;
400
- const groupUpdate = data.groupUpdates[id] || {};
401
- if (!data.groupUpdates[id]) {
402
- data.groupUpdates[id] = Object.assign(groupUpdate, update);
403
- }
404
- }
405
- break;
406
- default:
407
- throw new Error(`"${event}" cannot be buffered`);
408
- }
409
- function absorbingChatUpdate(existing) {
410
- const chatId = existing.id;
411
- const update = data.chatUpdates[chatId];
412
- if (update) {
413
- const conditionMatches = update.conditional ? update.conditional(data) : true;
414
- if (conditionMatches) {
415
- delete update.conditional;
416
- logger.debug({ chatId }, 'absorbed chat update in existing chat');
417
- Object.assign(existing, concatChats(update, existing));
418
- delete data.chatUpdates[chatId];
419
- }
420
- else if (conditionMatches === false) {
421
- logger.debug({ chatId }, 'chat update condition fail, removing');
422
- delete data.chatUpdates[chatId];
423
- }
424
- }
425
- }
426
- function decrementChatReadCounterIfMsgDidUnread(message) {
427
- // decrement chat unread counter
428
- // if the message has already been marked read by us
429
- const chatId = message.key.remoteJid;
430
- const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
431
- if ((0, process_message_1.isRealMessage)(message, '')
432
- && (0, process_message_1.shouldIncrementChatUnread)(message)
433
- && typeof (chat === null || chat === void 0 ? void 0 : chat.unreadCount) === 'number'
434
- && chat.unreadCount > 0) {
435
- logger.debug({ chatId: chat.id }, 'decrementing chat counter');
436
- chat.unreadCount -= 1;
437
- if (chat.unreadCount === 0) {
438
- delete chat.unreadCount;
439
- }
440
- }
441
- }
442
- }
443
- function consolidateEvents(data) {
444
- const map = {};
445
- if (!data.historySets.empty) {
446
- map['messaging-history.set'] = {
447
- chats: Object.values(data.historySets.chats),
448
- messages: Object.values(data.historySets.messages),
449
- contacts: Object.values(data.historySets.contacts),
450
- syncType: data.historySets.syncType,
451
- progress: data.historySets.progress,
452
- isLatest: data.historySets.isLatest,
453
- peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
454
- };
455
- }
456
- const chatUpsertList = Object.values(data.chatUpserts);
457
- if (chatUpsertList.length) {
458
- map['chats.upsert'] = chatUpsertList;
459
- }
460
- const chatUpdateList = Object.values(data.chatUpdates);
461
- if (chatUpdateList.length) {
462
- map['chats.update'] = chatUpdateList;
463
- }
464
- const chatDeleteList = Array.from(data.chatDeletes);
465
- if (chatDeleteList.length) {
466
- map['chats.delete'] = chatDeleteList;
467
- }
468
- const messageUpsertList = Object.values(data.messageUpserts);
469
- if (messageUpsertList.length) {
470
- const type = messageUpsertList[0].type;
471
- map['messages.upsert'] = {
472
- messages: messageUpsertList.map(m => m.message),
473
- type
474
- };
475
- }
476
- const messageUpdateList = Object.values(data.messageUpdates);
477
- if (messageUpdateList.length) {
478
- map['messages.update'] = messageUpdateList;
479
- }
480
- const messageDeleteList = Object.values(data.messageDeletes);
481
- if (messageDeleteList.length) {
482
- map['messages.delete'] = { keys: messageDeleteList };
483
- }
484
- const messageReactionList = Object.values(data.messageReactions).flatMap(({ key, reactions }) => reactions.flatMap(reaction => ({ key, reaction })));
485
- if (messageReactionList.length) {
486
- map['messages.reaction'] = messageReactionList;
487
- }
488
- const messageReceiptList = Object.values(data.messageReceipts).flatMap(({ key, userReceipt }) => userReceipt.flatMap(receipt => ({ key, receipt })));
489
- if (messageReceiptList.length) {
490
- map['message-receipt.update'] = messageReceiptList;
491
- }
492
- const contactUpsertList = Object.values(data.contactUpserts);
493
- if (contactUpsertList.length) {
494
- map['contacts.upsert'] = contactUpsertList;
495
- }
496
- const contactUpdateList = Object.values(data.contactUpdates);
497
- if (contactUpdateList.length) {
498
- map['contacts.update'] = contactUpdateList;
499
- }
500
- const groupUpdateList = Object.values(data.groupUpdates);
501
- if (groupUpdateList.length) {
502
- map['groups.update'] = groupUpdateList;
503
- }
504
- return map;
505
- }
506
- function concatChats(a, b) {
507
- if (b.unreadCount === null && // neutralize unread counter
508
- a.unreadCount < 0) {
509
- a.unreadCount = undefined;
510
- b.unreadCount = undefined;
511
- }
512
- if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
513
- b = { ...b };
514
- if (b.unreadCount >= 0) {
515
- b.unreadCount = Math.max(b.unreadCount, 0) + Math.max(a.unreadCount, 0);
516
- }
517
- }
518
- return Object.assign(a, b);
519
- }
520
- const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
@@ -1,119 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { AxiosRequestConfig } from 'axios';
4
- import { Logger } from 'pino';
5
- import { proto } from '../../WAProto';
6
- import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
7
- import { BinaryNode } from '../WABinary';
8
- /**
9
- const COMPANION_PLATFORM_MAP = {
10
- 'Chrome': '49',
11
- 'Edge': '50',
12
- 'Firefox': '51',
13
- 'Opera': '53',
14
- 'Safari': '54'
15
- }
16
- */
17
- export declare const Browsers: BrowsersMap;
18
- /** Other Browser Support for Paircode */
19
- export declare const getPlatformId: (browser: string) => any;
20
- export declare const BufferJSON: {
21
- replacer: (k: any, value: any) => any;
22
- reviver: (_: any, value: any) => any;
23
- };
24
- export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
25
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
26
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
27
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
28
- export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
29
- export declare const generateRegistrationId: () => number;
30
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
31
- export declare const toNumber: (t: Long | number | null | undefined) => number;
32
- /** unix timestamp of a date in seconds */
33
- export declare const unixTimestampSeconds: (date?: Date) => number;
34
- export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
35
- export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
36
- start: (newIntervalMs?: number, newTask?: () => void) => void;
37
- cancel: () => void;
38
- setTask: (newTask: () => void) => () => void;
39
- setInterval: (newInterval: number) => number;
40
- };
41
- export declare const delay: (ms: number) => Promise<void>;
42
- export declare const delayCancellable: (ms: number) => {
43
- delay: Promise<void>;
44
- cancel: () => void;
45
- };
46
- export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
47
- export declare const generateMessageIDV2: (userId?: string) => string;
48
- export declare const generateMessageIDV3: (userId?: string) => string;
49
- export declare const generateMessageID: () => string;
50
- export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
51
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
52
- export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
53
- /**
54
- * utility that fetches latest baileys version from the main branch.
55
- * Use to ensure your WA connection is always on the latest version
56
- */
57
- export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
58
- version: number[];
59
- isLatest: boolean;
60
- error?: undefined;
61
- } | {
62
- version: WAVersion;
63
- isLatest: boolean;
64
- error: any;
65
- }>;
66
- /**
67
- * utility that fetches latest baileys version from the master branch.
68
- * Use to ensure your WA connection is always on the latest version
69
- */
70
- export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<any>) => Promise<{
71
- version: WAVersion;
72
- isLatest: boolean;
73
- error?: undefined;
74
- } | {
75
- version: WAVersion;
76
- isLatest: boolean;
77
- error: any;
78
- }>;
79
- /**
80
- * A utility that fetches the latest web version of whatsapp.
81
- * Use to ensure your WA connection is always on the latest version
82
- */
83
- export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>) => Promise<{
84
- version: WAVersion;
85
- isLatest: boolean;
86
- error?: undefined;
87
- } | {
88
- version: WAVersion;
89
- isLatest: boolean;
90
- error: any;
91
- }>;
92
- /** unique message tag prefix for MD clients */
93
- export declare const generateMdTagPrefix: () => string;
94
- /**
95
- * Given a type of receipt, returns what the new status of the message should be
96
- * @param type type from receipt
97
- */
98
- export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
99
- /**
100
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
101
- * @param reason the string reason given, eg. "conflict"
102
- */
103
- export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
104
- reason: string;
105
- statusCode: number;
106
- };
107
- export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
108
- export declare const getCodeFromWSError: (error: Error) => number;
109
- /**
110
- * Is the given platform WA business
111
- * @param platform AuthenticationCreds.platform
112
- */
113
- export declare const isWABusinessPlatform: (platform: string) => boolean;
114
- export declare function trimUndefined(obj: {
115
- [_: string]: any;
116
- }): {
117
- [_: string]: any;
118
- };
119
- export declare function bytesToCrockford(buffer: Buffer): string;