@alannxd/baileys 6.0.5 → 6.0.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.
- package/WAProto/fix-import.js +29 -0
- package/WAProto/index.js +160 -201
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +15 -37
- package/lib/Defaults/index.js +136 -119
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -154
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.d.ts +239 -96
- package/lib/Socket/chats.js +427 -627
- package/lib/Socket/communities.d.ts +146 -239
- package/lib/Socket/communities.js +80 -90
- package/lib/Socket/groups.d.ts +57 -104
- package/lib/Socket/groups.js +161 -154
- package/lib/Socket/index.d.ts +115 -202
- package/lib/Socket/index.js +10 -11
- package/lib/Socket/luxu.d.ts +266 -22
- package/lib/Socket/luxu.js +465 -422
- package/lib/Socket/messages-recv.d.ts +84 -136
- package/lib/Socket/messages-recv.js +615 -1421
- package/lib/Socket/messages-send.d.ts +126 -142
- package/lib/Socket/messages-send.js +671 -878
- package/lib/Socket/newsletter.d.ts +85 -121
- package/lib/Socket/newsletter.js +272 -147
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +19 -34
- package/lib/Socket/socket.js +313 -544
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -10
- package/lib/Store/index.js +10 -10
- package/lib/Store/make-cache-manager-store.d.ts +11 -17
- package/lib/Store/make-cache-manager-store.js +41 -43
- package/lib/Store/make-in-memory-store.d.ts +118 -39
- package/lib/Store/make-in-memory-store.js +341 -112
- package/lib/Store/make-ordered-dictionary.d.ts +10 -11
- package/lib/Store/make-ordered-dictionary.js +20 -14
- package/lib/Store/object-repository.d.ts +9 -10
- package/lib/Store/object-repository.js +6 -11
- package/lib/Types/Auth.d.ts +12 -19
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -3
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -35
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +17 -116
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -21
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +58 -105
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +2 -32
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -50
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -72
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -12
- package/lib/Utils/auth-utils.js +143 -239
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +23 -52
- package/lib/Utils/chat-utils.js +253 -396
- package/lib/Utils/crypto.d.ts +22 -18
- package/lib/Utils/crypto.js +90 -57
- package/lib/Utils/decode-wa-message.d.ts +8 -55
- package/lib/Utils/decode-wa-message.js +84 -203
- package/lib/Utils/event-buffer.d.ts +8 -9
- package/lib/Utils/event-buffer.js +77 -185
- package/lib/Utils/generics.d.ts +29 -28
- package/lib/Utils/generics.js +210 -180
- package/lib/Utils/history.d.ts +9 -18
- package/lib/Utils/history.js +55 -93
- package/lib/Utils/index.d.ts +17 -22
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +24 -16
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +12 -8
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.d.ts +2 -4
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.d.ts +44 -61
- package/lib/Utils/messages-media.js +482 -451
- package/lib/Utils/messages.d.ts +18 -32
- package/lib/Utils/messages.js +369 -458
- package/lib/Utils/noise-handler.d.ts +14 -13
- package/lib/Utils/noise-handler.js +99 -145
- package/lib/Utils/process-message.d.ts +12 -31
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.d.ts +5 -20
- package/lib/Utils/signal.js +72 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +99 -73
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -52
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +7 -8
- package/lib/WABinary/generic-utils.js +49 -48
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -6
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +4 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.d.ts +5 -10
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -10
- package/lib/index.js +34 -12
- package/package.json +50 -83
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5479
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -277
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -54
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Store/keyed-db.d.ts +0 -22
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Mex.js +0 -37
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/message-retry-manager.js +0 -265
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/tc-token-utils.js +0 -163
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/index.d.ts +0 -4
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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");
|
|
6
12
|
const BUFFERABLE_EVENT = [
|
|
7
13
|
'messaging-history.set',
|
|
8
14
|
'chats.upsert',
|
|
@@ -15,23 +21,19 @@ const BUFFERABLE_EVENT = [
|
|
|
15
21
|
'messages.delete',
|
|
16
22
|
'messages.reaction',
|
|
17
23
|
'message-receipt.update',
|
|
18
|
-
'groups.update'
|
|
24
|
+
'groups.update',
|
|
19
25
|
];
|
|
20
26
|
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
21
27
|
/**
|
|
22
28
|
* The event buffer logically consolidates different events into a single event
|
|
23
29
|
* making the data processing more efficient.
|
|
30
|
+
* @param ev the baileys event emitter
|
|
24
31
|
*/
|
|
25
|
-
|
|
26
|
-
const ev = new
|
|
32
|
+
const makeEventBuffer = (logger) => {
|
|
33
|
+
const ev = new events_1.default();
|
|
27
34
|
const historyCache = new Set();
|
|
28
35
|
let data = makeBufferData();
|
|
29
|
-
let
|
|
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
|
|
36
|
+
let buffersInProgress = 0;
|
|
35
37
|
// take the generic event and fire it as a baileys event
|
|
36
38
|
ev.on('event', (map) => {
|
|
37
39
|
for (const event in map) {
|
|
@@ -39,46 +41,25 @@ export const makeEventBuffer = (logger) => {
|
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
function buffer() {
|
|
42
|
-
|
|
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++;
|
|
44
|
+
buffersInProgress += 1;
|
|
58
45
|
}
|
|
59
|
-
function flush() {
|
|
60
|
-
|
|
46
|
+
function flush(force = false) {
|
|
47
|
+
// no buffer going on
|
|
48
|
+
if (!buffersInProgress) {
|
|
61
49
|
return false;
|
|
62
50
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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();
|
|
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
|
+
}
|
|
79
59
|
}
|
|
80
60
|
const newData = makeBufferData();
|
|
81
61
|
const chatUpdates = Object.values(data.chatUpdates);
|
|
62
|
+
// gather the remaining conditional events so we re-queue them
|
|
82
63
|
let conditionalChatUpdatesLeft = 0;
|
|
83
64
|
for (const update of chatUpdates) {
|
|
84
65
|
if (update.conditional) {
|
|
@@ -97,8 +78,8 @@ export const makeEventBuffer = (logger) => {
|
|
|
97
78
|
}
|
|
98
79
|
return {
|
|
99
80
|
process(handler) {
|
|
100
|
-
const listener =
|
|
101
|
-
|
|
81
|
+
const listener = (map) => {
|
|
82
|
+
handler(map);
|
|
102
83
|
};
|
|
103
84
|
ev.on('event', listener);
|
|
104
85
|
return () => {
|
|
@@ -106,35 +87,14 @@ export const makeEventBuffer = (logger) => {
|
|
|
106
87
|
};
|
|
107
88
|
},
|
|
108
89
|
emit(event, evData) {
|
|
109
|
-
|
|
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)) {
|
|
90
|
+
if (buffersInProgress && BUFFERABLE_EVENT_SET.has(event)) {
|
|
131
91
|
append(data, historyCache, event, evData, logger);
|
|
132
92
|
return true;
|
|
133
93
|
}
|
|
134
94
|
return ev.emit('event', { [event]: evData });
|
|
135
95
|
},
|
|
136
96
|
isBuffering() {
|
|
137
|
-
return
|
|
97
|
+
return buffersInProgress > 0;
|
|
138
98
|
},
|
|
139
99
|
buffer,
|
|
140
100
|
flush,
|
|
@@ -143,55 +103,19 @@ export const makeEventBuffer = (logger) => {
|
|
|
143
103
|
buffer();
|
|
144
104
|
try {
|
|
145
105
|
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
|
-
}
|
|
154
106
|
return result;
|
|
155
107
|
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
108
|
finally {
|
|
160
|
-
|
|
161
|
-
if (bufferCount === 0) {
|
|
162
|
-
// Only schedule ONE timeout, not 10,000
|
|
163
|
-
if (!flushPendingTimeout) {
|
|
164
|
-
flushPendingTimeout = setTimeout(flush, 100);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
109
|
+
flush();
|
|
167
110
|
}
|
|
168
111
|
};
|
|
169
112
|
},
|
|
170
113
|
on: (...args) => ev.on(...args),
|
|
171
114
|
off: (...args) => ev.off(...args),
|
|
172
115
|
removeAllListeners: (...args) => ev.removeAllListeners(...args),
|
|
173
|
-
destroy() {
|
|
174
|
-
// Clear buffer timeout
|
|
175
|
-
if (bufferTimeout) {
|
|
176
|
-
clearTimeout(bufferTimeout);
|
|
177
|
-
bufferTimeout = null;
|
|
178
|
-
}
|
|
179
|
-
if (flushPendingTimeout) {
|
|
180
|
-
clearTimeout(flushPendingTimeout);
|
|
181
|
-
flushPendingTimeout = null;
|
|
182
|
-
}
|
|
183
|
-
// Clear history cache
|
|
184
|
-
historyCache.clear();
|
|
185
|
-
// Reset buffer data
|
|
186
|
-
data = makeBufferData();
|
|
187
|
-
isBuffering = false;
|
|
188
|
-
bufferCount = 0;
|
|
189
|
-
// Remove all listeners
|
|
190
|
-
ev.removeAllListeners();
|
|
191
|
-
logger.debug('Event buffer destroyed');
|
|
192
|
-
}
|
|
193
116
|
};
|
|
194
117
|
};
|
|
118
|
+
exports.makeEventBuffer = makeEventBuffer;
|
|
195
119
|
const makeBufferData = () => {
|
|
196
120
|
return {
|
|
197
121
|
historySets: {
|
|
@@ -214,27 +138,25 @@ const makeBufferData = () => {
|
|
|
214
138
|
groupUpdates: {}
|
|
215
139
|
};
|
|
216
140
|
};
|
|
217
|
-
function append(data, historyCache, event,
|
|
218
|
-
|
|
219
|
-
eventData, logger) {
|
|
141
|
+
function append(data, historyCache, event, eventData, logger) {
|
|
142
|
+
var _a, _b, _c;
|
|
220
143
|
switch (event) {
|
|
221
144
|
case 'messaging-history.set':
|
|
222
145
|
for (const chat of eventData.chats) {
|
|
223
|
-
const
|
|
224
|
-
const existingChat = data.historySets.chats[id];
|
|
146
|
+
const existingChat = data.historySets.chats[chat.id];
|
|
225
147
|
if (existingChat) {
|
|
226
148
|
existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType;
|
|
227
149
|
}
|
|
228
|
-
if (!existingChat && !historyCache.has(id)) {
|
|
229
|
-
data.historySets.chats[id] = chat;
|
|
230
|
-
historyCache.add(id);
|
|
150
|
+
if (!existingChat && !historyCache.has(chat.id)) {
|
|
151
|
+
data.historySets.chats[chat.id] = chat;
|
|
152
|
+
historyCache.add(chat.id);
|
|
231
153
|
absorbingChatUpdate(chat);
|
|
232
154
|
}
|
|
233
155
|
}
|
|
234
156
|
for (const contact of eventData.contacts) {
|
|
235
157
|
const existingContact = data.historySets.contacts[contact.id];
|
|
236
158
|
if (existingContact) {
|
|
237
|
-
Object.assign(existingContact, trimUndefined(contact));
|
|
159
|
+
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
238
160
|
}
|
|
239
161
|
else {
|
|
240
162
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -254,45 +176,15 @@ eventData, logger) {
|
|
|
254
176
|
}
|
|
255
177
|
}
|
|
256
178
|
data.historySets.empty = false;
|
|
257
|
-
data.historySets.syncType = eventData.syncType;
|
|
258
|
-
if (eventData.pastParticipants?.length) {
|
|
259
|
-
const merged = new Map();
|
|
260
|
-
const sigOf = (p) => `${p.userJid || ''}:${p.leaveTs || ''}:${p.leaveReason || ''}`;
|
|
261
|
-
const ingest = (entry) => {
|
|
262
|
-
const key = entry.groupJid ?? JSON.stringify(entry);
|
|
263
|
-
const existing = merged.get(key);
|
|
264
|
-
if (!existing) {
|
|
265
|
-
merged.set(key, { ...entry, pastParticipants: [...(entry.pastParticipants || [])] });
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const seen = new Set((existing.pastParticipants || []).map(sigOf));
|
|
269
|
-
for (const p of entry.pastParticipants || []) {
|
|
270
|
-
const sig = sigOf(p);
|
|
271
|
-
if (!seen.has(sig)) {
|
|
272
|
-
existing.pastParticipants.push(p);
|
|
273
|
-
seen.add(sig);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
for (const entry of data.historySets.pastParticipants || [])
|
|
278
|
-
ingest(entry);
|
|
279
|
-
for (const entry of eventData.pastParticipants)
|
|
280
|
-
ingest(entry);
|
|
281
|
-
data.historySets.pastParticipants = [...merged.values()];
|
|
282
|
-
}
|
|
283
|
-
data.historySets.progress = eventData.progress;
|
|
284
|
-
data.historySets.chunkOrder = eventData.chunkOrder;
|
|
285
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
286
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
287
180
|
break;
|
|
288
181
|
case 'chats.upsert':
|
|
289
182
|
for (const chat of eventData) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
upsert = data.historySets.chats[id];
|
|
183
|
+
let upsert = data.chatUpserts[chat.id];
|
|
184
|
+
if (!upsert) {
|
|
185
|
+
upsert = data.historySets[chat.id];
|
|
294
186
|
if (upsert) {
|
|
295
|
-
logger.debug({ chatId: id }, 'absorbed chat upsert in chat set');
|
|
187
|
+
logger.debug({ chatId: chat.id }, 'absorbed chat upsert in chat set');
|
|
296
188
|
}
|
|
297
189
|
}
|
|
298
190
|
if (upsert) {
|
|
@@ -300,11 +192,11 @@ eventData, logger) {
|
|
|
300
192
|
}
|
|
301
193
|
else {
|
|
302
194
|
upsert = chat;
|
|
303
|
-
data.chatUpserts[id] = upsert;
|
|
195
|
+
data.chatUpserts[chat.id] = upsert;
|
|
304
196
|
}
|
|
305
197
|
absorbingChatUpdate(upsert);
|
|
306
|
-
if (data.chatDeletes.has(id)) {
|
|
307
|
-
data.chatDeletes.delete(id);
|
|
198
|
+
if (data.chatDeletes.has(chat.id)) {
|
|
199
|
+
data.chatDeletes.delete(chat.id);
|
|
308
200
|
}
|
|
309
201
|
}
|
|
310
202
|
break;
|
|
@@ -364,14 +256,14 @@ eventData, logger) {
|
|
|
364
256
|
}
|
|
365
257
|
}
|
|
366
258
|
if (upsert) {
|
|
367
|
-
upsert = Object.assign(upsert, trimUndefined(contact));
|
|
259
|
+
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
368
260
|
}
|
|
369
261
|
else {
|
|
370
262
|
upsert = contact;
|
|
371
263
|
data.contactUpserts[contact.id] = upsert;
|
|
372
264
|
}
|
|
373
265
|
if (data.contactUpdates[contact.id]) {
|
|
374
|
-
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact));
|
|
266
|
+
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
375
267
|
delete data.contactUpdates[contact.id];
|
|
376
268
|
}
|
|
377
269
|
}
|
|
@@ -396,7 +288,7 @@ eventData, logger) {
|
|
|
396
288
|
const { messages, type } = eventData;
|
|
397
289
|
for (const message of messages) {
|
|
398
290
|
const key = stringifyMessageKey(message.key);
|
|
399
|
-
let existing = data.messageUpserts[key]
|
|
291
|
+
let existing = (_a = data.messageUpserts[key]) === null || _a === void 0 ? void 0 : _a.message;
|
|
400
292
|
if (!existing) {
|
|
401
293
|
existing = data.historySets.messages[key];
|
|
402
294
|
if (existing) {
|
|
@@ -417,7 +309,9 @@ eventData, logger) {
|
|
|
417
309
|
else {
|
|
418
310
|
data.messageUpserts[key] = {
|
|
419
311
|
message,
|
|
420
|
-
type: type === 'notify' || data.messageUpserts[key]
|
|
312
|
+
type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify'
|
|
313
|
+
? 'notify'
|
|
314
|
+
: type
|
|
421
315
|
};
|
|
422
316
|
}
|
|
423
317
|
}
|
|
@@ -426,13 +320,13 @@ eventData, logger) {
|
|
|
426
320
|
const msgUpdates = eventData;
|
|
427
321
|
for (const { key, update } of msgUpdates) {
|
|
428
322
|
const keyStr = stringifyMessageKey(key);
|
|
429
|
-
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]
|
|
323
|
+
const existing = data.historySets.messages[keyStr] || ((_c = data.messageUpserts[keyStr]) === null || _c === void 0 ? void 0 : _c.message);
|
|
430
324
|
if (existing) {
|
|
431
325
|
Object.assign(existing, update);
|
|
432
326
|
// if the message was received & read by us
|
|
433
327
|
// the chat counter must have been incremented
|
|
434
328
|
// so we need to decrement it
|
|
435
|
-
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
329
|
+
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
436
330
|
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
437
331
|
}
|
|
438
332
|
}
|
|
@@ -470,11 +364,12 @@ eventData, logger) {
|
|
|
470
364
|
const keyStr = stringifyMessageKey(key);
|
|
471
365
|
const existing = data.messageUpserts[keyStr];
|
|
472
366
|
if (existing) {
|
|
473
|
-
updateMessageWithReaction(existing.message, reaction);
|
|
367
|
+
(0, messages_1.updateMessageWithReaction)(existing.message, reaction);
|
|
474
368
|
}
|
|
475
369
|
else {
|
|
476
|
-
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
477
|
-
|
|
370
|
+
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
371
|
+
|| { key, reactions: [] };
|
|
372
|
+
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
478
373
|
}
|
|
479
374
|
}
|
|
480
375
|
break;
|
|
@@ -484,11 +379,12 @@ eventData, logger) {
|
|
|
484
379
|
const keyStr = stringifyMessageKey(key);
|
|
485
380
|
const existing = data.messageUpserts[keyStr];
|
|
486
381
|
if (existing) {
|
|
487
|
-
updateMessageWithReceipt(existing.message, receipt);
|
|
382
|
+
(0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
|
|
488
383
|
}
|
|
489
384
|
else {
|
|
490
|
-
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
491
|
-
|
|
385
|
+
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
386
|
+
|| { key, userReceipt: [] };
|
|
387
|
+
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
492
388
|
}
|
|
493
389
|
}
|
|
494
390
|
break;
|
|
@@ -506,7 +402,7 @@ eventData, logger) {
|
|
|
506
402
|
throw new Error(`"${event}" cannot be buffered`);
|
|
507
403
|
}
|
|
508
404
|
function absorbingChatUpdate(existing) {
|
|
509
|
-
const chatId = existing.id
|
|
405
|
+
const chatId = existing.id;
|
|
510
406
|
const update = data.chatUpdates[chatId];
|
|
511
407
|
if (update) {
|
|
512
408
|
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
@@ -527,10 +423,10 @@ eventData, logger) {
|
|
|
527
423
|
// if the message has already been marked read by us
|
|
528
424
|
const chatId = message.key.remoteJid;
|
|
529
425
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
530
|
-
if (isRealMessage(message)
|
|
531
|
-
shouldIncrementChatUnread(message)
|
|
532
|
-
typeof chat
|
|
533
|
-
chat.unreadCount > 0) {
|
|
426
|
+
if ((0, process_message_1.isRealMessage)(message, '')
|
|
427
|
+
&& (0, process_message_1.shouldIncrementChatUnread)(message)
|
|
428
|
+
&& typeof (chat === null || chat === void 0 ? void 0 : chat.unreadCount) === 'number'
|
|
429
|
+
&& chat.unreadCount > 0) {
|
|
534
430
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
535
431
|
chat.unreadCount -= 1;
|
|
536
432
|
if (chat.unreadCount === 0) {
|
|
@@ -546,12 +442,7 @@ function consolidateEvents(data) {
|
|
|
546
442
|
chats: Object.values(data.historySets.chats),
|
|
547
443
|
messages: Object.values(data.historySets.messages),
|
|
548
444
|
contacts: Object.values(data.historySets.contacts),
|
|
549
|
-
|
|
550
|
-
syncType: data.historySets.syncType,
|
|
551
|
-
progress: data.historySets.progress,
|
|
552
|
-
isLatest: data.historySets.isLatest,
|
|
553
|
-
chunkOrder: data.historySets.chunkOrder,
|
|
554
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
555
446
|
};
|
|
556
447
|
}
|
|
557
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -605,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
605
496
|
return map;
|
|
606
497
|
}
|
|
607
498
|
function concatChats(a, b) {
|
|
608
|
-
if (b.unreadCount === null
|
|
609
|
-
|
|
610
|
-
a.unreadCount
|
|
611
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
612
505
|
}
|
|
613
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
614
507
|
b = { ...b };
|
|
@@ -619,4 +512,3 @@ function concatChats(a, b) {
|
|
|
619
512
|
return Object.assign(a, b);
|
|
620
513
|
}
|
|
621
514
|
const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|
|
622
|
-
//# sourceMappingURL=event-buffer.js.map
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { Logger } from 'pino';
|
|
4
|
+
import { proto } from '../../WAProto';
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
6
|
+
import { BinaryNode } from '../WABinary';
|
|
7
|
+
export declare const Browsers: {
|
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
|
11
|
+
windows: (browser: any) => [string, string, string];
|
|
12
|
+
/** The appropriate browser based on your OS & release */
|
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
|
7
14
|
};
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
|
|
11
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer<ArrayBuffer>;
|
|
15
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
16
|
+
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
17
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
18
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
19
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
14
20
|
export declare const generateRegistrationId: () => number;
|
|
15
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
16
22
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
17
23
|
/** unix timestamp of a date in seconds */
|
|
18
24
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
@@ -31,33 +37,34 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
31
37
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
32
38
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
33
39
|
export declare const generateMessageID: () => string;
|
|
34
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) =>
|
|
35
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) =>
|
|
40
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
42
|
+
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
36
43
|
/**
|
|
37
44
|
* utility that fetches latest baileys version from the master branch.
|
|
38
45
|
* Use to ensure your WA connection is always on the latest version
|
|
39
46
|
*/
|
|
40
|
-
export declare const fetchLatestBaileysVersion: (options?:
|
|
47
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
41
48
|
version: WAVersion;
|
|
42
49
|
isLatest: boolean;
|
|
43
50
|
error?: undefined;
|
|
44
51
|
} | {
|
|
45
52
|
version: WAVersion;
|
|
46
53
|
isLatest: boolean;
|
|
47
|
-
error:
|
|
54
|
+
error: any;
|
|
48
55
|
}>;
|
|
49
56
|
/**
|
|
50
57
|
* A utility that fetches the latest web version of whatsapp.
|
|
51
58
|
* Use to ensure your WA connection is always on the latest version
|
|
52
59
|
*/
|
|
53
|
-
export declare const fetchLatestWaWebVersion: (options
|
|
60
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
54
61
|
version: WAVersion;
|
|
55
62
|
isLatest: boolean;
|
|
56
63
|
error?: undefined;
|
|
57
64
|
} | {
|
|
58
65
|
version: WAVersion;
|
|
59
66
|
isLatest: boolean;
|
|
60
|
-
error:
|
|
67
|
+
error: any;
|
|
61
68
|
}>;
|
|
62
69
|
/** unique message tag prefix for MD clients */
|
|
63
70
|
export declare const generateMdTagPrefix: () => string;
|
|
@@ -65,7 +72,7 @@ export declare const generateMdTagPrefix: () => string;
|
|
|
65
72
|
* Given a type of receipt, returns what the new status of the message should be
|
|
66
73
|
* @param type type from receipt
|
|
67
74
|
*/
|
|
68
|
-
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status
|
|
75
|
+
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
69
76
|
/**
|
|
70
77
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
71
78
|
* @param reason the string reason given, eg. "conflict"
|
|
@@ -80,12 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
80
87
|
* Is the given platform WA business
|
|
81
88
|
* @param platform AuthenticationCreds.platform
|
|
82
89
|
*/
|
|
83
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
|
84
|
-
export declare function trimUndefined(obj:
|
|
85
|
-
[_: string]: any;
|
|
86
|
-
}): {
|
|
87
|
-
[_: string]: any;
|
|
88
|
-
};
|
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
91
|
+
export declare function trimUndefined(obj: any): any;
|
|
89
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
|
90
|
-
export declare function encodeNewsletterMessage(message: proto.IMessage): Uint8Array;
|
|
91
|
-
//# sourceMappingURL=generics.d.ts.map
|