supunmd-bail 2.0.2 → 2.1.3
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 +1 -1
- package/README.md +2 -2
- package/WAProto/index.js +130529 -45236
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -18
- package/lib/Defaults/index.js +136 -104
- 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 +0 -1
- package/lib/Signal/Group/queue-job.js +5 -2
- 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 -258
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
- 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} +1 -2
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -125
- package/lib/Socket/business.js +43 -159
- package/lib/Socket/chats.d.ts +239 -70
- package/lib/Socket/chats.js +384 -363
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +56 -78
- package/lib/Socket/groups.js +96 -106
- package/lib/Socket/index.d.ts +115 -173
- package/lib/Socket/index.js +10 -17
- package/lib/Socket/messages-recv.d.ts +79 -91
- package/lib/Socket/messages-recv.js +521 -639
- package/lib/Socket/messages-send.d.ts +91 -111
- package/lib/Socket/messages-send.js +438 -599
- package/lib/Socket/newsletter.d.ts +84 -97
- package/lib/Socket/newsletter.js +1 -181
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -26
- package/lib/Socket/socket.js +230 -448
- package/lib/Socket/usync.d.ts +16 -17
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -13
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -34
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +15 -60
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -17
- 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 +54 -84
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +98 -130
- package/lib/Types/Newsletter.js +38 -31
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -20
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -47
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- 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 -7
- package/lib/Utils/auth-utils.js +148 -199
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +226 -260
- package/lib/Utils/crypto.d.ts +19 -19
- package/lib/Utils/crypto.js +86 -77
- package/lib/Utils/decode-wa-message.d.ts +8 -37
- package/lib/Utils/decode-wa-message.js +83 -164
- package/lib/Utils/event-buffer.d.ts +8 -7
- package/lib/Utils/event-buffer.js +76 -110
- package/lib/Utils/generics.d.ts +29 -27
- package/lib/Utils/generics.js +210 -168
- package/lib/Utils/history.d.ts +8 -12
- package/lib/Utils/history.js +46 -34
- package/lib/Utils/index.d.ts +17 -20
- package/lib/Utils/index.js +33 -20
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +22 -14
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +28 -25
- package/lib/Utils/make-mutex.d.ts +2 -3
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.d.ts +44 -42
- package/lib/Utils/messages-media.js +475 -319
- package/lib/Utils/messages.d.ts +18 -17
- package/lib/Utils/messages.js +259 -383
- package/lib/Utils/noise-handler.d.ts +15 -14
- package/lib/Utils/noise-handler.js +38 -30
- package/lib/Utils/process-message.d.ts +13 -14
- package/lib/Utils/process-message.js +147 -239
- package/lib/Utils/signal.d.ts +5 -7
- package/lib/Utils/signal.js +72 -78
- 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 +106 -72
- 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 -28
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +7 -5
- package/lib/WABinary/generic-utils.js +63 -56
- 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 +11 -8
- 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 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +4 -5
- package/lib/WAUSync/USyncQuery.js +35 -40
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -19
- package/lib/index.js +1 -36
- package/package.json +109 -103
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5519
- package/WAProto/fix-imports.js +0 -29
- package/WAProto/index.d.ts +0 -11969
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.d.ts +0 -244
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.js +0 -149
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- /package/lib/{supun → supunmd} +0 -0
|
@@ -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,22 +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 bufferCount = 0;
|
|
32
|
-
const MAX_HISTORY_CACHE_SIZE = 10000; // Limit the history cache size to prevent memory bloat
|
|
33
|
-
const BUFFER_TIMEOUT_MS = 30000; // 30 seconds
|
|
36
|
+
let buffersInProgress = 0;
|
|
34
37
|
// take the generic event and fire it as a baileys event
|
|
35
38
|
ev.on('event', (map) => {
|
|
36
39
|
for (const event in map) {
|
|
@@ -38,44 +41,25 @@ export const makeEventBuffer = (logger) => {
|
|
|
38
41
|
}
|
|
39
42
|
});
|
|
40
43
|
function buffer() {
|
|
41
|
-
|
|
42
|
-
logger.debug('Event buffer activated');
|
|
43
|
-
isBuffering = true;
|
|
44
|
-
bufferCount++;
|
|
45
|
-
// Auto-flush after a timeout to prevent infinite buffering
|
|
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
|
-
else {
|
|
57
|
-
bufferCount++;
|
|
58
|
-
}
|
|
44
|
+
buffersInProgress += 1;
|
|
59
45
|
}
|
|
60
|
-
function flush() {
|
|
61
|
-
|
|
46
|
+
function flush(force = false) {
|
|
47
|
+
// no buffer going on
|
|
48
|
+
if (!buffersInProgress) {
|
|
62
49
|
return false;
|
|
63
50
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Clear history cache if it exceeds the max size
|
|
73
|
-
if (historyCache.size > MAX_HISTORY_CACHE_SIZE) {
|
|
74
|
-
logger.debug({ cacheSize: historyCache.size }, 'Clearing history cache');
|
|
75
|
-
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
|
+
}
|
|
76
59
|
}
|
|
77
60
|
const newData = makeBufferData();
|
|
78
61
|
const chatUpdates = Object.values(data.chatUpdates);
|
|
62
|
+
// gather the remaining conditional events so we re-queue them
|
|
79
63
|
let conditionalChatUpdatesLeft = 0;
|
|
80
64
|
for (const update of chatUpdates) {
|
|
81
65
|
if (update.conditional) {
|
|
@@ -103,14 +87,14 @@ export const makeEventBuffer = (logger) => {
|
|
|
103
87
|
};
|
|
104
88
|
},
|
|
105
89
|
emit(event, evData) {
|
|
106
|
-
if (
|
|
90
|
+
if (buffersInProgress && BUFFERABLE_EVENT_SET.has(event)) {
|
|
107
91
|
append(data, historyCache, event, evData, logger);
|
|
108
92
|
return true;
|
|
109
93
|
}
|
|
110
94
|
return ev.emit('event', { [event]: evData });
|
|
111
95
|
},
|
|
112
96
|
isBuffering() {
|
|
113
|
-
return
|
|
97
|
+
return buffersInProgress > 0;
|
|
114
98
|
},
|
|
115
99
|
buffer,
|
|
116
100
|
flush,
|
|
@@ -119,33 +103,19 @@ export const makeEventBuffer = (logger) => {
|
|
|
119
103
|
buffer();
|
|
120
104
|
try {
|
|
121
105
|
const result = await work(...args);
|
|
122
|
-
// If this is the only buffer, flush after a small delay
|
|
123
|
-
if (bufferCount === 1) {
|
|
124
|
-
setTimeout(() => {
|
|
125
|
-
if (isBuffering && bufferCount === 1) {
|
|
126
|
-
flush();
|
|
127
|
-
}
|
|
128
|
-
}, 100); // Small delay to allow nested buffers
|
|
129
|
-
}
|
|
130
106
|
return result;
|
|
131
107
|
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
108
|
finally {
|
|
136
|
-
|
|
137
|
-
if (bufferCount === 0) {
|
|
138
|
-
// Auto-flush when no other buffers are active
|
|
139
|
-
setTimeout(flush, 100);
|
|
140
|
-
}
|
|
109
|
+
flush();
|
|
141
110
|
}
|
|
142
111
|
};
|
|
143
112
|
},
|
|
144
113
|
on: (...args) => ev.on(...args),
|
|
145
114
|
off: (...args) => ev.off(...args),
|
|
146
|
-
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
115
|
+
removeAllListeners: (...args) => ev.removeAllListeners(...args),
|
|
147
116
|
};
|
|
148
117
|
};
|
|
118
|
+
exports.makeEventBuffer = makeEventBuffer;
|
|
149
119
|
const makeBufferData = () => {
|
|
150
120
|
return {
|
|
151
121
|
historySets: {
|
|
@@ -168,27 +138,25 @@ const makeBufferData = () => {
|
|
|
168
138
|
groupUpdates: {}
|
|
169
139
|
};
|
|
170
140
|
};
|
|
171
|
-
function append(data, historyCache, event,
|
|
172
|
-
|
|
173
|
-
eventData, logger) {
|
|
141
|
+
function append(data, historyCache, event, eventData, logger) {
|
|
142
|
+
var _a, _b, _c;
|
|
174
143
|
switch (event) {
|
|
175
144
|
case 'messaging-history.set':
|
|
176
145
|
for (const chat of eventData.chats) {
|
|
177
|
-
const
|
|
178
|
-
const existingChat = data.historySets.chats[id];
|
|
146
|
+
const existingChat = data.historySets.chats[chat.id];
|
|
179
147
|
if (existingChat) {
|
|
180
148
|
existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType;
|
|
181
149
|
}
|
|
182
|
-
if (!existingChat && !historyCache.has(id)) {
|
|
183
|
-
data.historySets.chats[id] = chat;
|
|
184
|
-
historyCache.add(id);
|
|
150
|
+
if (!existingChat && !historyCache.has(chat.id)) {
|
|
151
|
+
data.historySets.chats[chat.id] = chat;
|
|
152
|
+
historyCache.add(chat.id);
|
|
185
153
|
absorbingChatUpdate(chat);
|
|
186
154
|
}
|
|
187
155
|
}
|
|
188
156
|
for (const contact of eventData.contacts) {
|
|
189
157
|
const existingContact = data.historySets.contacts[contact.id];
|
|
190
158
|
if (existingContact) {
|
|
191
|
-
Object.assign(existingContact, trimUndefined(contact));
|
|
159
|
+
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
192
160
|
}
|
|
193
161
|
else {
|
|
194
162
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -208,19 +176,15 @@ eventData, logger) {
|
|
|
208
176
|
}
|
|
209
177
|
}
|
|
210
178
|
data.historySets.empty = false;
|
|
211
|
-
data.historySets.syncType = eventData.syncType;
|
|
212
|
-
data.historySets.progress = eventData.progress;
|
|
213
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
214
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
215
180
|
break;
|
|
216
181
|
case 'chats.upsert':
|
|
217
182
|
for (const chat of eventData) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
upsert = data.historySets.chats[id];
|
|
183
|
+
let upsert = data.chatUpserts[chat.id];
|
|
184
|
+
if (!upsert) {
|
|
185
|
+
upsert = data.historySets[chat.id];
|
|
222
186
|
if (upsert) {
|
|
223
|
-
logger.debug({ chatId: id }, 'absorbed chat upsert in chat set');
|
|
187
|
+
logger.debug({ chatId: chat.id }, 'absorbed chat upsert in chat set');
|
|
224
188
|
}
|
|
225
189
|
}
|
|
226
190
|
if (upsert) {
|
|
@@ -228,11 +192,11 @@ eventData, logger) {
|
|
|
228
192
|
}
|
|
229
193
|
else {
|
|
230
194
|
upsert = chat;
|
|
231
|
-
data.chatUpserts[id] = upsert;
|
|
195
|
+
data.chatUpserts[chat.id] = upsert;
|
|
232
196
|
}
|
|
233
197
|
absorbingChatUpdate(upsert);
|
|
234
|
-
if (data.chatDeletes.has(id)) {
|
|
235
|
-
data.chatDeletes.delete(id);
|
|
198
|
+
if (data.chatDeletes.has(chat.id)) {
|
|
199
|
+
data.chatDeletes.delete(chat.id);
|
|
236
200
|
}
|
|
237
201
|
}
|
|
238
202
|
break;
|
|
@@ -292,14 +256,14 @@ eventData, logger) {
|
|
|
292
256
|
}
|
|
293
257
|
}
|
|
294
258
|
if (upsert) {
|
|
295
|
-
upsert = Object.assign(upsert, trimUndefined(contact));
|
|
259
|
+
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
296
260
|
}
|
|
297
261
|
else {
|
|
298
262
|
upsert = contact;
|
|
299
263
|
data.contactUpserts[contact.id] = upsert;
|
|
300
264
|
}
|
|
301
265
|
if (data.contactUpdates[contact.id]) {
|
|
302
|
-
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact));
|
|
266
|
+
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
303
267
|
delete data.contactUpdates[contact.id];
|
|
304
268
|
}
|
|
305
269
|
}
|
|
@@ -324,7 +288,7 @@ eventData, logger) {
|
|
|
324
288
|
const { messages, type } = eventData;
|
|
325
289
|
for (const message of messages) {
|
|
326
290
|
const key = stringifyMessageKey(message.key);
|
|
327
|
-
let existing = data.messageUpserts[key]
|
|
291
|
+
let existing = (_a = data.messageUpserts[key]) === null || _a === void 0 ? void 0 : _a.message;
|
|
328
292
|
if (!existing) {
|
|
329
293
|
existing = data.historySets.messages[key];
|
|
330
294
|
if (existing) {
|
|
@@ -345,7 +309,9 @@ eventData, logger) {
|
|
|
345
309
|
else {
|
|
346
310
|
data.messageUpserts[key] = {
|
|
347
311
|
message,
|
|
348
|
-
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
|
|
349
315
|
};
|
|
350
316
|
}
|
|
351
317
|
}
|
|
@@ -354,13 +320,13 @@ eventData, logger) {
|
|
|
354
320
|
const msgUpdates = eventData;
|
|
355
321
|
for (const { key, update } of msgUpdates) {
|
|
356
322
|
const keyStr = stringifyMessageKey(key);
|
|
357
|
-
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);
|
|
358
324
|
if (existing) {
|
|
359
325
|
Object.assign(existing, update);
|
|
360
326
|
// if the message was received & read by us
|
|
361
327
|
// the chat counter must have been incremented
|
|
362
328
|
// so we need to decrement it
|
|
363
|
-
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
329
|
+
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
364
330
|
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
365
331
|
}
|
|
366
332
|
}
|
|
@@ -398,11 +364,12 @@ eventData, logger) {
|
|
|
398
364
|
const keyStr = stringifyMessageKey(key);
|
|
399
365
|
const existing = data.messageUpserts[keyStr];
|
|
400
366
|
if (existing) {
|
|
401
|
-
updateMessageWithReaction(existing.message, reaction);
|
|
367
|
+
(0, messages_1.updateMessageWithReaction)(existing.message, reaction);
|
|
402
368
|
}
|
|
403
369
|
else {
|
|
404
|
-
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
405
|
-
|
|
370
|
+
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
371
|
+
|| { key, reactions: [] };
|
|
372
|
+
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
406
373
|
}
|
|
407
374
|
}
|
|
408
375
|
break;
|
|
@@ -412,11 +379,12 @@ eventData, logger) {
|
|
|
412
379
|
const keyStr = stringifyMessageKey(key);
|
|
413
380
|
const existing = data.messageUpserts[keyStr];
|
|
414
381
|
if (existing) {
|
|
415
|
-
updateMessageWithReceipt(existing.message, receipt);
|
|
382
|
+
(0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
|
|
416
383
|
}
|
|
417
384
|
else {
|
|
418
|
-
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
419
|
-
|
|
385
|
+
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
386
|
+
|| { key, userReceipt: [] };
|
|
387
|
+
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
420
388
|
}
|
|
421
389
|
}
|
|
422
390
|
break;
|
|
@@ -434,7 +402,7 @@ eventData, logger) {
|
|
|
434
402
|
throw new Error(`"${event}" cannot be buffered`);
|
|
435
403
|
}
|
|
436
404
|
function absorbingChatUpdate(existing) {
|
|
437
|
-
const chatId = existing.id
|
|
405
|
+
const chatId = existing.id;
|
|
438
406
|
const update = data.chatUpdates[chatId];
|
|
439
407
|
if (update) {
|
|
440
408
|
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
@@ -455,10 +423,10 @@ eventData, logger) {
|
|
|
455
423
|
// if the message has already been marked read by us
|
|
456
424
|
const chatId = message.key.remoteJid;
|
|
457
425
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
458
|
-
if (isRealMessage(message)
|
|
459
|
-
shouldIncrementChatUnread(message)
|
|
460
|
-
typeof chat
|
|
461
|
-
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) {
|
|
462
430
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
463
431
|
chat.unreadCount -= 1;
|
|
464
432
|
if (chat.unreadCount === 0) {
|
|
@@ -474,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
474
442
|
chats: Object.values(data.historySets.chats),
|
|
475
443
|
messages: Object.values(data.historySets.messages),
|
|
476
444
|
contacts: Object.values(data.historySets.contacts),
|
|
477
|
-
|
|
478
|
-
progress: data.historySets.progress,
|
|
479
|
-
isLatest: data.historySets.isLatest,
|
|
480
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
481
446
|
};
|
|
482
447
|
}
|
|
483
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -531,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
531
496
|
return map;
|
|
532
497
|
}
|
|
533
498
|
function concatChats(a, b) {
|
|
534
|
-
if (b.unreadCount === null
|
|
535
|
-
|
|
536
|
-
a.unreadCount
|
|
537
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
538
505
|
}
|
|
539
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
540
507
|
b = { ...b };
|
|
@@ -545,4 +512,3 @@ function concatChats(a, b) {
|
|
|
545
512
|
return Object.assign(a, b);
|
|
546
513
|
}
|
|
547
514
|
const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|
|
548
|
-
//# sourceMappingURL=event-buffer.js.map
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,17 +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
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer
|
|
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;
|
|
13
20
|
export declare const generateRegistrationId: () => number;
|
|
14
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
15
22
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
16
23
|
/** unix timestamp of a date in seconds */
|
|
17
24
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
@@ -30,33 +37,34 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
30
37
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
31
38
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
32
39
|
export declare const generateMessageID: () => string;
|
|
33
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) =>
|
|
34
|
-
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;
|
|
35
43
|
/**
|
|
36
44
|
* utility that fetches latest baileys version from the master branch.
|
|
37
45
|
* Use to ensure your WA connection is always on the latest version
|
|
38
46
|
*/
|
|
39
|
-
export declare const fetchLatestBaileysVersion: (options?:
|
|
47
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
40
48
|
version: WAVersion;
|
|
41
49
|
isLatest: boolean;
|
|
42
50
|
error?: undefined;
|
|
43
51
|
} | {
|
|
44
52
|
version: WAVersion;
|
|
45
53
|
isLatest: boolean;
|
|
46
|
-
error:
|
|
54
|
+
error: any;
|
|
47
55
|
}>;
|
|
48
56
|
/**
|
|
49
57
|
* A utility that fetches the latest web version of whatsapp.
|
|
50
58
|
* Use to ensure your WA connection is always on the latest version
|
|
51
59
|
*/
|
|
52
|
-
export declare const fetchLatestWaWebVersion: (options
|
|
60
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
53
61
|
version: WAVersion;
|
|
54
62
|
isLatest: boolean;
|
|
55
63
|
error?: undefined;
|
|
56
64
|
} | {
|
|
57
65
|
version: WAVersion;
|
|
58
66
|
isLatest: boolean;
|
|
59
|
-
error:
|
|
67
|
+
error: any;
|
|
60
68
|
}>;
|
|
61
69
|
/** unique message tag prefix for MD clients */
|
|
62
70
|
export declare const generateMdTagPrefix: () => string;
|
|
@@ -64,7 +72,7 @@ export declare const generateMdTagPrefix: () => string;
|
|
|
64
72
|
* Given a type of receipt, returns what the new status of the message should be
|
|
65
73
|
* @param type type from receipt
|
|
66
74
|
*/
|
|
67
|
-
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status
|
|
75
|
+
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
68
76
|
/**
|
|
69
77
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
70
78
|
* @param reason the string reason given, eg. "conflict"
|
|
@@ -79,12 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
79
87
|
* Is the given platform WA business
|
|
80
88
|
* @param platform AuthenticationCreds.platform
|
|
81
89
|
*/
|
|
82
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
|
83
|
-
export declare function trimUndefined(obj:
|
|
84
|
-
[_: string]: any;
|
|
85
|
-
}): {
|
|
86
|
-
[_: string]: any;
|
|
87
|
-
};
|
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
91
|
+
export declare function trimUndefined(obj: any): any;
|
|
88
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
|
89
|
-
export declare function encodeNewsletterMessage(message: proto.IMessage): Uint8Array;
|
|
90
|
-
//# sourceMappingURL=generics.d.ts.map
|