violetics 7.0.0-alpha → 7.0.2-alpha
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/LICENSE +3 -2
- package/README.md +1001 -232
- package/WAProto/index.js +75379 -142631
- package/engine-requirements.js +11 -8
- package/lib/Defaults/index.js +132 -144
- package/lib/Signal/Group/ciphertext-message.js +2 -6
- package/lib/Signal/Group/group-session-builder.js +7 -42
- package/lib/Signal/Group/group_cipher.js +37 -52
- package/lib/Signal/Group/index.js +11 -57
- package/lib/Signal/Group/keyhelper.js +7 -45
- package/lib/Signal/Group/sender-chain-key.js +7 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
- package/lib/Signal/Group/sender-key-message.js +9 -13
- package/lib/Signal/Group/sender-key-name.js +2 -6
- package/lib/Signal/Group/sender-key-record.js +9 -22
- package/lib/Signal/Group/sender-key-state.js +27 -43
- package/lib/Signal/Group/sender-message-key.js +4 -8
- package/lib/Signal/libsignal.js +319 -94
- package/lib/Signal/lid-mapping.js +224 -139
- package/lib/Socket/Client/index.js +2 -19
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.js +162 -44
- package/lib/Socket/chats.js +477 -442
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +110 -99
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.js +878 -552
- package/lib/Socket/messages-send.js +859 -428
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +195 -390
- package/lib/Socket/socket.js +463 -289
- package/lib/Store/index.js +3 -10
- package/lib/Store/make-in-memory-store.js +73 -79
- package/lib/Store/make-ordered-dictionary.js +4 -7
- package/lib/Store/object-repository.js +2 -6
- package/lib/Types/Auth.js +1 -2
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -2
- package/lib/Types/Chat.js +7 -4
- package/lib/Types/Contact.js +1 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +1 -2
- package/lib/Types/Label.js +2 -5
- package/lib/Types/LabelAssociation.js +2 -5
- package/lib/Types/Message.js +17 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.js +1 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -2
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +14 -31
- package/lib/Utils/auth-utils.js +228 -145
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +66 -70
- package/lib/Utils/chat-utils.js +331 -249
- package/lib/Utils/crypto.js +57 -91
- package/lib/Utils/decode-wa-message.js +168 -84
- package/lib/Utils/event-buffer.js +138 -80
- package/lib/Utils/generics.js +180 -297
- package/lib/Utils/history.js +83 -49
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -23
- package/lib/Utils/logger.js +2 -7
- package/lib/Utils/lt-hash.js +2 -46
- package/lib/Utils/make-mutex.js +24 -35
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.js +501 -496
- package/lib/Utils/messages.js +1428 -362
- package/lib/Utils/noise-handler.js +145 -100
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +356 -150
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/signal.js +78 -73
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.js +32 -34
- package/lib/Utils/validate-connection.js +91 -107
- package/lib/WABinary/constants.js +1300 -1304
- package/lib/WABinary/decode.js +26 -48
- package/lib/WABinary/encode.js +109 -155
- package/lib/WABinary/generic-utils.js +161 -149
- package/lib/WABinary/index.js +5 -21
- package/lib/WABinary/jid-utils.js +73 -40
- package/lib/WABinary/types.js +1 -2
- package/lib/WAM/BinaryInfo.js +2 -6
- package/lib/WAM/constants.js +19070 -11568
- package/lib/WAM/encode.js +17 -23
- package/lib/WAM/index.js +3 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
- package/lib/WAUSync/Protocols/index.js +4 -20
- package/lib/WAUSync/USyncQuery.js +40 -36
- package/lib/WAUSync/USyncUser.js +2 -6
- package/lib/WAUSync/index.js +3 -19
- package/lib/index.js +11 -44
- package/package.json +75 -108
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -111
- package/lib/Socket/groupStatus.js +0 -637
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/baileys-event-stream.js +0 -63
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
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");
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { WAMessageStatus } from '../Types/index.js';
|
|
3
|
+
import { trimUndefined } from './generics.js';
|
|
4
|
+
import { updateMessageWithReaction, updateMessageWithReceipt } from './messages.js';
|
|
5
|
+
import { isRealMessage, shouldIncrementChatUnread } from './process-message.js';
|
|
12
6
|
const BUFFERABLE_EVENT = [
|
|
13
7
|
'messaging-history.set',
|
|
14
8
|
'chats.upsert',
|
|
@@ -21,20 +15,23 @@ const BUFFERABLE_EVENT = [
|
|
|
21
15
|
'messages.delete',
|
|
22
16
|
'messages.reaction',
|
|
23
17
|
'message-receipt.update',
|
|
24
|
-
'groups.update'
|
|
18
|
+
'groups.update'
|
|
25
19
|
];
|
|
26
20
|
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
27
21
|
/**
|
|
28
22
|
* The event buffer logically consolidates different events into a single event
|
|
29
23
|
* making the data processing more efficient.
|
|
30
|
-
* @param ev the baileys event emitter
|
|
31
24
|
*/
|
|
32
|
-
const makeEventBuffer = (logger) => {
|
|
33
|
-
const ev = new
|
|
34
|
-
ev.setMaxListeners(0);
|
|
25
|
+
export const makeEventBuffer = (logger) => {
|
|
26
|
+
const ev = new EventEmitter();
|
|
35
27
|
const historyCache = new Set();
|
|
36
28
|
let data = makeBufferData();
|
|
37
|
-
let
|
|
29
|
+
let isBuffering = false;
|
|
30
|
+
let bufferTimeout = null;
|
|
31
|
+
let flushPendingTimeout = null; // Add a specific timer for the debounced flush to prevent leak
|
|
32
|
+
let bufferCount = 0;
|
|
33
|
+
const MAX_HISTORY_CACHE_SIZE = 10000; // Limit the history cache size to prevent memory bloat
|
|
34
|
+
const BUFFER_TIMEOUT_MS = 30000; // 30 seconds
|
|
38
35
|
// take the generic event and fire it as a baileys event
|
|
39
36
|
ev.on('event', (map) => {
|
|
40
37
|
for (const event in map) {
|
|
@@ -42,25 +39,46 @@ const makeEventBuffer = (logger) => {
|
|
|
42
39
|
}
|
|
43
40
|
});
|
|
44
41
|
function buffer() {
|
|
45
|
-
|
|
42
|
+
if (!isBuffering) {
|
|
43
|
+
logger.debug('Event buffer activated');
|
|
44
|
+
isBuffering = true;
|
|
45
|
+
bufferCount = 0;
|
|
46
|
+
if (bufferTimeout) {
|
|
47
|
+
clearTimeout(bufferTimeout);
|
|
48
|
+
}
|
|
49
|
+
bufferTimeout = setTimeout(() => {
|
|
50
|
+
if (isBuffering) {
|
|
51
|
+
logger.warn('Buffer timeout reached, auto-flushing');
|
|
52
|
+
flush();
|
|
53
|
+
}
|
|
54
|
+
}, BUFFER_TIMEOUT_MS);
|
|
55
|
+
}
|
|
56
|
+
// Always increment count when requested
|
|
57
|
+
bufferCount++;
|
|
46
58
|
}
|
|
47
|
-
function flush(
|
|
48
|
-
|
|
49
|
-
if (!buffersInProgress) {
|
|
59
|
+
function flush() {
|
|
60
|
+
if (!isBuffering) {
|
|
50
61
|
return false;
|
|
51
62
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
logger.debug({ bufferCount }, 'Flushing event buffer');
|
|
64
|
+
isBuffering = false;
|
|
65
|
+
bufferCount = 0;
|
|
66
|
+
// Clear timeout
|
|
67
|
+
if (bufferTimeout) {
|
|
68
|
+
clearTimeout(bufferTimeout);
|
|
69
|
+
bufferTimeout = null;
|
|
70
|
+
}
|
|
71
|
+
if (flushPendingTimeout) {
|
|
72
|
+
clearTimeout(flushPendingTimeout);
|
|
73
|
+
flushPendingTimeout = null;
|
|
74
|
+
}
|
|
75
|
+
// Clear history cache if it exceeds the max size
|
|
76
|
+
if (historyCache.size > MAX_HISTORY_CACHE_SIZE) {
|
|
77
|
+
logger.debug({ cacheSize: historyCache.size }, 'Clearing history cache');
|
|
78
|
+
historyCache.clear();
|
|
60
79
|
}
|
|
61
80
|
const newData = makeBufferData();
|
|
62
81
|
const chatUpdates = Object.values(data.chatUpdates);
|
|
63
|
-
// gather the remaining conditional events so we re-queue them
|
|
64
82
|
let conditionalChatUpdatesLeft = 0;
|
|
65
83
|
for (const update of chatUpdates) {
|
|
66
84
|
if (update.conditional) {
|
|
@@ -79,8 +97,8 @@ const makeEventBuffer = (logger) => {
|
|
|
79
97
|
}
|
|
80
98
|
return {
|
|
81
99
|
process(handler) {
|
|
82
|
-
const listener = (map) => {
|
|
83
|
-
handler(map);
|
|
100
|
+
const listener = async (map) => {
|
|
101
|
+
await handler(map);
|
|
84
102
|
};
|
|
85
103
|
ev.on('event', listener);
|
|
86
104
|
return () => {
|
|
@@ -88,14 +106,35 @@ const makeEventBuffer = (logger) => {
|
|
|
88
106
|
};
|
|
89
107
|
},
|
|
90
108
|
emit(event, evData) {
|
|
91
|
-
if
|
|
109
|
+
// Check if this is a messages.upsert with a different type than what's buffered
|
|
110
|
+
// If so, flush the buffered messages first to avoid type overshadowing
|
|
111
|
+
if (event === 'messages.upsert') {
|
|
112
|
+
const { type } = evData;
|
|
113
|
+
const existingUpserts = Object.values(data.messageUpserts);
|
|
114
|
+
if (existingUpserts.length > 0) {
|
|
115
|
+
const bufferedType = existingUpserts[0].type;
|
|
116
|
+
if (bufferedType !== type) {
|
|
117
|
+
logger.debug({ bufferedType, newType: type }, 'messages.upsert type mismatch, emitting buffered messages');
|
|
118
|
+
// Emit the buffered messages with their correct type
|
|
119
|
+
ev.emit('event', {
|
|
120
|
+
'messages.upsert': {
|
|
121
|
+
messages: existingUpserts.map(m => m.message),
|
|
122
|
+
type: bufferedType
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Clear the message upserts from the buffer
|
|
126
|
+
data.messageUpserts = {};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (isBuffering && BUFFERABLE_EVENT_SET.has(event)) {
|
|
92
131
|
append(data, historyCache, event, evData, logger);
|
|
93
132
|
return true;
|
|
94
133
|
}
|
|
95
134
|
return ev.emit('event', { [event]: evData });
|
|
96
135
|
},
|
|
97
136
|
isBuffering() {
|
|
98
|
-
return
|
|
137
|
+
return isBuffering;
|
|
99
138
|
},
|
|
100
139
|
buffer,
|
|
101
140
|
flush,
|
|
@@ -104,19 +143,35 @@ const makeEventBuffer = (logger) => {
|
|
|
104
143
|
buffer();
|
|
105
144
|
try {
|
|
106
145
|
const result = await work(...args);
|
|
146
|
+
// If this is the only buffer, flush after a small delay
|
|
147
|
+
if (bufferCount === 1) {
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
if (isBuffering && bufferCount === 1) {
|
|
150
|
+
flush();
|
|
151
|
+
}
|
|
152
|
+
}, 100); // Small delay to allow nested buffers
|
|
153
|
+
}
|
|
107
154
|
return result;
|
|
108
155
|
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
109
159
|
finally {
|
|
110
|
-
|
|
160
|
+
bufferCount = Math.max(0, bufferCount - 1);
|
|
161
|
+
if (bufferCount === 0) {
|
|
162
|
+
// Only schedule ONE timeout, not 10,000
|
|
163
|
+
if (!flushPendingTimeout) {
|
|
164
|
+
flushPendingTimeout = setTimeout(flush, 100);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
111
167
|
}
|
|
112
168
|
};
|
|
113
169
|
},
|
|
114
170
|
on: (...args) => ev.on(...args),
|
|
115
171
|
off: (...args) => ev.off(...args),
|
|
116
|
-
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
172
|
+
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
117
173
|
};
|
|
118
174
|
};
|
|
119
|
-
exports.makeEventBuffer = makeEventBuffer;
|
|
120
175
|
const makeBufferData = () => {
|
|
121
176
|
return {
|
|
122
177
|
historySets: {
|
|
@@ -139,25 +194,27 @@ const makeBufferData = () => {
|
|
|
139
194
|
groupUpdates: {}
|
|
140
195
|
};
|
|
141
196
|
};
|
|
142
|
-
function append(data, historyCache, event,
|
|
143
|
-
|
|
197
|
+
function append(data, historyCache, event,
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
|
+
eventData, logger) {
|
|
144
200
|
switch (event) {
|
|
145
201
|
case 'messaging-history.set':
|
|
146
202
|
for (const chat of eventData.chats) {
|
|
147
|
-
const
|
|
203
|
+
const id = chat.id || '';
|
|
204
|
+
const existingChat = data.historySets.chats[id];
|
|
148
205
|
if (existingChat) {
|
|
149
206
|
existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType;
|
|
150
207
|
}
|
|
151
|
-
if (!existingChat && !historyCache.has(
|
|
152
|
-
data.historySets.chats[
|
|
153
|
-
historyCache.add(
|
|
208
|
+
if (!existingChat && !historyCache.has(id)) {
|
|
209
|
+
data.historySets.chats[id] = chat;
|
|
210
|
+
historyCache.add(id);
|
|
154
211
|
absorbingChatUpdate(chat);
|
|
155
212
|
}
|
|
156
213
|
}
|
|
157
214
|
for (const contact of eventData.contacts) {
|
|
158
215
|
const existingContact = data.historySets.contacts[contact.id];
|
|
159
216
|
if (existingContact) {
|
|
160
|
-
Object.assign(existingContact,
|
|
217
|
+
Object.assign(existingContact, trimUndefined(contact));
|
|
161
218
|
}
|
|
162
219
|
else {
|
|
163
220
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -177,15 +234,19 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
177
234
|
}
|
|
178
235
|
}
|
|
179
236
|
data.historySets.empty = false;
|
|
237
|
+
data.historySets.syncType = eventData.syncType;
|
|
238
|
+
data.historySets.progress = eventData.progress;
|
|
239
|
+
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
180
240
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
181
241
|
break;
|
|
182
242
|
case 'chats.upsert':
|
|
183
243
|
for (const chat of eventData) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
244
|
+
const id = chat.id || '';
|
|
245
|
+
let upsert = data.chatUpserts[id];
|
|
246
|
+
if (id && !upsert) {
|
|
247
|
+
upsert = data.historySets.chats[id];
|
|
187
248
|
if (upsert) {
|
|
188
|
-
logger.debug({ chatId:
|
|
249
|
+
logger.debug({ chatId: id }, 'absorbed chat upsert in chat set');
|
|
189
250
|
}
|
|
190
251
|
}
|
|
191
252
|
if (upsert) {
|
|
@@ -193,11 +254,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
193
254
|
}
|
|
194
255
|
else {
|
|
195
256
|
upsert = chat;
|
|
196
|
-
data.chatUpserts[
|
|
257
|
+
data.chatUpserts[id] = upsert;
|
|
197
258
|
}
|
|
198
259
|
absorbingChatUpdate(upsert);
|
|
199
|
-
if (data.chatDeletes.has(
|
|
200
|
-
data.chatDeletes.delete(
|
|
260
|
+
if (data.chatDeletes.has(id)) {
|
|
261
|
+
data.chatDeletes.delete(id);
|
|
201
262
|
}
|
|
202
263
|
}
|
|
203
264
|
break;
|
|
@@ -257,14 +318,14 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
257
318
|
}
|
|
258
319
|
}
|
|
259
320
|
if (upsert) {
|
|
260
|
-
upsert = Object.assign(upsert,
|
|
321
|
+
upsert = Object.assign(upsert, trimUndefined(contact));
|
|
261
322
|
}
|
|
262
323
|
else {
|
|
263
324
|
upsert = contact;
|
|
264
325
|
data.contactUpserts[contact.id] = upsert;
|
|
265
326
|
}
|
|
266
327
|
if (data.contactUpdates[contact.id]) {
|
|
267
|
-
upsert = Object.assign(data.contactUpdates[contact.id],
|
|
328
|
+
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact));
|
|
268
329
|
delete data.contactUpdates[contact.id];
|
|
269
330
|
}
|
|
270
331
|
}
|
|
@@ -289,7 +350,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
289
350
|
const { messages, type } = eventData;
|
|
290
351
|
for (const message of messages) {
|
|
291
352
|
const key = stringifyMessageKey(message.key);
|
|
292
|
-
let existing =
|
|
353
|
+
let existing = data.messageUpserts[key]?.message;
|
|
293
354
|
if (!existing) {
|
|
294
355
|
existing = data.historySets.messages[key];
|
|
295
356
|
if (existing) {
|
|
@@ -310,9 +371,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
310
371
|
else {
|
|
311
372
|
data.messageUpserts[key] = {
|
|
312
373
|
message,
|
|
313
|
-
type: type === 'notify' ||
|
|
314
|
-
? 'notify'
|
|
315
|
-
: type
|
|
374
|
+
type: type === 'notify' || data.messageUpserts[key]?.type === 'notify' ? 'notify' : type
|
|
316
375
|
};
|
|
317
376
|
}
|
|
318
377
|
}
|
|
@@ -321,13 +380,13 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
321
380
|
const msgUpdates = eventData;
|
|
322
381
|
for (const { key, update } of msgUpdates) {
|
|
323
382
|
const keyStr = stringifyMessageKey(key);
|
|
324
|
-
const existing = data.historySets.messages[keyStr] ||
|
|
383
|
+
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]?.message;
|
|
325
384
|
if (existing) {
|
|
326
385
|
Object.assign(existing, update);
|
|
327
386
|
// if the message was received & read by us
|
|
328
387
|
// the chat counter must have been incremented
|
|
329
388
|
// so we need to decrement it
|
|
330
|
-
if (update.status ===
|
|
389
|
+
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
331
390
|
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
332
391
|
}
|
|
333
392
|
}
|
|
@@ -365,12 +424,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
365
424
|
const keyStr = stringifyMessageKey(key);
|
|
366
425
|
const existing = data.messageUpserts[keyStr];
|
|
367
426
|
if (existing) {
|
|
368
|
-
|
|
427
|
+
updateMessageWithReaction(existing.message, reaction);
|
|
369
428
|
}
|
|
370
429
|
else {
|
|
371
|
-
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
372
|
-
|
|
373
|
-
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
430
|
+
data.messageReactions[keyStr] = data.messageReactions[keyStr] || { key, reactions: [] };
|
|
431
|
+
updateMessageWithReaction(data.messageReactions[keyStr], reaction);
|
|
374
432
|
}
|
|
375
433
|
}
|
|
376
434
|
break;
|
|
@@ -380,12 +438,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
380
438
|
const keyStr = stringifyMessageKey(key);
|
|
381
439
|
const existing = data.messageUpserts[keyStr];
|
|
382
440
|
if (existing) {
|
|
383
|
-
|
|
441
|
+
updateMessageWithReceipt(existing.message, receipt);
|
|
384
442
|
}
|
|
385
443
|
else {
|
|
386
|
-
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
387
|
-
|
|
388
|
-
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
444
|
+
data.messageReceipts[keyStr] = data.messageReceipts[keyStr] || { key, userReceipt: [] };
|
|
445
|
+
updateMessageWithReceipt(data.messageReceipts[keyStr], receipt);
|
|
389
446
|
}
|
|
390
447
|
}
|
|
391
448
|
break;
|
|
@@ -403,7 +460,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
403
460
|
throw new Error(`"${event}" cannot be buffered`);
|
|
404
461
|
}
|
|
405
462
|
function absorbingChatUpdate(existing) {
|
|
406
|
-
const chatId = existing.id;
|
|
463
|
+
const chatId = existing.id || '';
|
|
407
464
|
const update = data.chatUpdates[chatId];
|
|
408
465
|
if (update) {
|
|
409
466
|
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
@@ -424,10 +481,10 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
424
481
|
// if the message has already been marked read by us
|
|
425
482
|
const chatId = message.key.remoteJid;
|
|
426
483
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
484
|
+
if (isRealMessage(message) &&
|
|
485
|
+
shouldIncrementChatUnread(message) &&
|
|
486
|
+
typeof chat?.unreadCount === 'number' &&
|
|
487
|
+
chat.unreadCount > 0) {
|
|
431
488
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
432
489
|
chat.unreadCount -= 1;
|
|
433
490
|
if (chat.unreadCount === 0) {
|
|
@@ -443,7 +500,10 @@ function consolidateEvents(data) {
|
|
|
443
500
|
chats: Object.values(data.historySets.chats),
|
|
444
501
|
messages: Object.values(data.historySets.messages),
|
|
445
502
|
contacts: Object.values(data.historySets.contacts),
|
|
446
|
-
|
|
503
|
+
syncType: data.historySets.syncType,
|
|
504
|
+
progress: data.historySets.progress,
|
|
505
|
+
isLatest: data.historySets.isLatest,
|
|
506
|
+
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
447
507
|
};
|
|
448
508
|
}
|
|
449
509
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -497,12 +557,10 @@ function consolidateEvents(data) {
|
|
|
497
557
|
return map;
|
|
498
558
|
}
|
|
499
559
|
function concatChats(a, b) {
|
|
500
|
-
if (b.unreadCount === null
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
b.unreadCount = undefined;
|
|
505
|
-
}
|
|
560
|
+
if (b.unreadCount === null && // neutralize unread counter
|
|
561
|
+
a.unreadCount < 0) {
|
|
562
|
+
a.unreadCount = undefined;
|
|
563
|
+
b.unreadCount = undefined;
|
|
506
564
|
}
|
|
507
565
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
508
566
|
b = { ...b };
|
|
@@ -512,4 +570,4 @@ function concatChats(a, b) {
|
|
|
512
570
|
}
|
|
513
571
|
return Object.assign(a, b);
|
|
514
572
|
}
|
|
515
|
-
const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|
|
573
|
+
const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|