@badzz88/baileys 8.5.6 → 8.5.7
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/README.md +2 -2
- package/WAProto/WAProto.proto +75 -1256
- package/WAProto/fix-imports.js +79 -69
- package/WAProto/index.d.ts +71491 -15254
- package/WAProto/index.js +126432 -19810
- package/engine-requirements.js +4 -3
- package/lib/Defaults/index.js +187 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +92 -0
- package/lib/Signal/Group/group_cipher.js +89 -0
- package/lib/Signal/Group/index.js +136 -0
- package/lib/Signal/Group/keyhelper.js +73 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.js +97 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +459 -0
- package/lib/Signal/lid-mapping.js +260 -0
- package/lib/Socket/Client/index.js +30 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -0
- package/lib/Socket/chats.js +1816 -0
- package/lib/Socket/communities.js +549 -0
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -0
- package/lib/Socket/index.js +39 -0
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/{src → lib}/Socket/luxu.js +120 -82
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2442 -0
- package/lib/Socket/messages-send.js +1853 -0
- package/lib/Socket/mex.js +60 -0
- package/lib/Socket/newsletter.js +818 -0
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1092 -0
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +243 -0
- package/lib/Store/index.js +36 -0
- package/{src → lib}/Store/keyed-db.js +11 -21
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +604 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +29 -0
- package/lib/Types/Auth.js +38 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +95 -0
- package/lib/Types/Mex.js +112 -0
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +70 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +55 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/browser-utils.js +114 -0
- package/lib/Utils/business.js +247 -0
- package/lib/Utils/chat-utils.js +1208 -0
- package/lib/Utils/command-loader.d.ts +31 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +42 -0
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +155 -0
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +560 -0
- package/lib/Utils/event-buffer.js +607 -0
- package/lib/Utils/generics.js +563 -0
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -0
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +143 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +39 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-composer.js +479 -0
- package/lib/Utils/message-retry-manager.js +270 -0
- package/lib/Utils/messages-media.js +896 -0
- package/lib/Utils/messages.js +2904 -0
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +196 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +107 -0
- package/lib/Utils/process-message.js +1048 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/session-pool.d.ts +16 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +224 -0
- package/lib/Utils/stanza-ack.js +40 -0
- package/lib/Utils/sticker.d.ts +17 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +54 -0
- package/lib/Utils/tc-token-utils.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +219 -0
- package/lib/Utils/view-once-cache.d.ts +9 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1304 -0
- package/lib/WABinary/decode.js +343 -0
- package/{src → lib}/WABinary/encode.js +12 -9
- package/lib/WABinary/generic-utils.js +240 -0
- package/lib/WABinary/index.js +33 -0
- package/lib/WABinary/jid-utils.js +361 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +39486 -0
- package/lib/WAM/encode.js +142 -0
- package/lib/WAM/index.js +31 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +39 -0
- package/lib/WAUSync/USyncQuery.js +133 -0
- package/lib/WAUSync/USyncUser.js +50 -0
- package/lib/WAUSync/index.js +31 -0
- package/lib/antiban.js +4637 -0
- package/{src → lib}/index.js +49 -51
- package/package.json +4 -4
- package/src/Defaults/index.js +0 -186
- package/src/Signal/Group/ciphertext-message.js +0 -15
- package/src/Signal/Group/group-session-builder.js +0 -86
- package/src/Signal/Group/group_cipher.js +0 -82
- package/src/Signal/Group/index.js +0 -140
- package/src/Signal/Group/keyhelper.js +0 -77
- package/src/Signal/Group/sender-chain-key.js +0 -29
- package/src/Signal/Group/sender-key-distribution-message.js +0 -66
- package/src/Signal/Group/sender-key-message.js +0 -69
- package/src/Signal/Group/sender-key-name.js +0 -51
- package/src/Signal/Group/sender-key-record.js +0 -44
- package/src/Signal/Group/sender-key-state.js +0 -87
- package/src/Signal/Group/sender-message-key.js +0 -29
- package/src/Signal/libsignal.js +0 -455
- package/src/Signal/lid-mapping.js +0 -273
- package/src/Socket/Client/index.js +0 -31
- package/src/Socket/Client/types.js +0 -13
- package/src/Socket/Client/websocket.js +0 -61
- package/src/Socket/aigroups.js +0 -221
- package/src/Socket/business.js +0 -411
- package/src/Socket/chats.js +0 -1449
- package/src/Socket/communities.js +0 -463
- package/src/Socket/graphql.js +0 -523
- package/src/Socket/groups.js +0 -516
- package/src/Socket/index.js +0 -31
- package/src/Socket/interactive-handler.js +0 -527
- package/src/Socket/interop.js +0 -339
- package/src/Socket/managed-account.js +0 -98
- package/src/Socket/messages-recv.js +0 -2685
- package/src/Socket/messages-send.js +0 -2047
- package/src/Socket/mex.js +0 -57
- package/src/Socket/newsletter.js +0 -455
- package/src/Socket/privacy.js +0 -125
- package/src/Socket/registration.js +0 -236
- package/src/Socket/socket.js +0 -983
- package/src/Socket/text-router.js +0 -65
- package/src/Socket/username.js +0 -130
- package/src/Store/index.js +0 -33
- package/src/Store/make-cache-manager-store.js +0 -84
- package/src/Store/make-in-memory-store.js +0 -551
- package/src/Store/make-ordered-dictionary.js +0 -81
- package/src/Store/object-repository.js +0 -26
- package/src/Types/Auth.js +0 -31
- package/src/Types/Bussines.js +0 -2
- package/src/Types/Call.js +0 -2
- package/src/Types/Chat.js +0 -4
- package/src/Types/Contact.js +0 -2
- package/src/Types/Events.js +0 -2
- package/src/Types/GroupMetadata.js +0 -2
- package/src/Types/Label.js +0 -26
- package/src/Types/LabelAssociation.js +0 -8
- package/src/Types/Message.js +0 -93
- package/src/Types/Mex.js +0 -112
- package/src/Types/Newsletter.js +0 -109
- package/src/Types/Product.js +0 -2
- package/src/Types/Signal.js +0 -2
- package/src/Types/Socket.js +0 -2
- package/src/Types/State.js +0 -62
- package/src/Types/USync.js +0 -2
- package/src/Types/index.js +0 -56
- package/src/Utils/auth-utils.js +0 -254
- package/src/Utils/browser-utils.js +0 -112
- package/src/Utils/business.js +0 -240
- package/src/Utils/chat-utils.js +0 -1230
- package/src/Utils/command-loader.d.ts +0 -27
- package/src/Utils/command-loader.js +0 -89
- package/src/Utils/companion-reg-client-utils.js +0 -40
- package/src/Utils/consumer-application.js +0 -105
- package/src/Utils/crypto.js +0 -118
- package/src/Utils/curve25519-js.js +0 -242
- package/src/Utils/decode-wa-message.js +0 -529
- package/src/Utils/event-buffer.js +0 -580
- package/src/Utils/generics.js +0 -483
- package/src/Utils/group-history.js +0 -44
- package/src/Utils/history.js +0 -232
- package/src/Utils/identity-change-handler.js +0 -52
- package/src/Utils/index.js +0 -58
- package/src/Utils/jid-display-normalization.js +0 -195
- package/src/Utils/link-preview.js +0 -135
- package/src/Utils/logger.js +0 -8
- package/src/Utils/lt-hash.js +0 -25
- package/src/Utils/make-mutex.js +0 -36
- package/src/Utils/message-composer.js +0 -471
- package/src/Utils/message-retry-manager.js +0 -217
- package/src/Utils/messages-media.js +0 -843
- package/src/Utils/messages.js +0 -2817
- package/src/Utils/meta-ai-msmsg.js +0 -222
- package/src/Utils/native-bridge.js +0 -68
- package/src/Utils/noise-handler.js +0 -169
- package/src/Utils/offline-node-processor.js +0 -34
- package/src/Utils/pre-key-manager.js +0 -90
- package/src/Utils/process-message.js +0 -950
- package/src/Utils/reporting-utils.js +0 -261
- package/src/Utils/session-pool.d.ts +0 -14
- package/src/Utils/session-pool.js +0 -70
- package/src/Utils/signal.js +0 -217
- package/src/Utils/stanza-ack.js +0 -30
- package/src/Utils/sticker.d.ts +0 -13
- package/src/Utils/sticker.js +0 -123
- package/src/Utils/sync-action-utils.js +0 -45
- package/src/Utils/tc-token-utils.js +0 -158
- package/src/Utils/use-multi-file-auth-state.js +0 -111
- package/src/Utils/validate-connection.js +0 -209
- package/src/Utils/view-once-cache.d.ts +0 -12
- package/src/Utils/view-once-cache.js +0 -63
- package/src/Utils/voip-rekey.js +0 -22
- package/src/WABinary/constants.js +0 -1304
- package/src/WABinary/decode.js +0 -342
- package/src/WABinary/generic-utils.js +0 -238
- package/src/WABinary/index.js +0 -34
- package/src/WABinary/jid-utils.js +0 -351
- package/src/WABinary/types.js +0 -2
- package/src/WAM/BinaryInfo.js +0 -13
- package/src/WAM/constants.js +0 -39484
- package/src/WAM/encode.js +0 -149
- package/src/WAM/index.js +0 -32
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
- package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/src/WAUSync/Protocols/index.js +0 -40
- package/src/WAUSync/USyncQuery.js +0 -126
- package/src/WAUSync/USyncUser.js +0 -50
- package/src/WAUSync/index.js +0 -32
- package/src/antiban.js +0 -4152
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
|
@@ -1,580 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault = (this && this.__importDefault) ||
|
|
3
|
-
function (mod) {
|
|
4
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
7
|
-
exports.makeEventBuffer = void 0;
|
|
8
|
-
const events_1 = __importDefault(require('events'));
|
|
9
|
-
const Types_1 = require('../Types');
|
|
10
|
-
const generics_1 = require('./generics');
|
|
11
|
-
const messages_1 = require('./messages');
|
|
12
|
-
const process_message_1 = require('./process-message');
|
|
13
|
-
const BUFFERABLE_EVENT = [
|
|
14
|
-
'messaging-history.set',
|
|
15
|
-
'chats.upsert',
|
|
16
|
-
'chats.update',
|
|
17
|
-
'chats.delete',
|
|
18
|
-
'contacts.upsert',
|
|
19
|
-
'contacts.update',
|
|
20
|
-
'messages.upsert',
|
|
21
|
-
'messages.update',
|
|
22
|
-
'messages.delete',
|
|
23
|
-
'messages.reaction',
|
|
24
|
-
'message-receipt.update',
|
|
25
|
-
'groups.update'
|
|
26
|
-
];
|
|
27
|
-
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
28
|
-
const makeEventBuffer = logger => {
|
|
29
|
-
const ev = new events_1.default();
|
|
30
|
-
const historyCache = new Set();
|
|
31
|
-
let data = makeBufferData();
|
|
32
|
-
let isBuffering = false;
|
|
33
|
-
let bufferTimeout = null;
|
|
34
|
-
let flushPendingTimeout = null;
|
|
35
|
-
let bufferCount = 0;
|
|
36
|
-
const MAX_HISTORY_CACHE_SIZE = 10000;
|
|
37
|
-
const BUFFER_TIMEOUT_MS = 30000;
|
|
38
|
-
ev.on('event', map => {
|
|
39
|
-
for (const event in map) {
|
|
40
|
-
ev.emit(event, map[event]);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
function buffer() {
|
|
44
|
-
if (!isBuffering) {
|
|
45
|
-
logger.debug('Event buffer activated');
|
|
46
|
-
isBuffering = true;
|
|
47
|
-
bufferCount = 0;
|
|
48
|
-
if (bufferTimeout) {
|
|
49
|
-
clearTimeout(bufferTimeout);
|
|
50
|
-
}
|
|
51
|
-
bufferTimeout = setTimeout(() => {
|
|
52
|
-
if (isBuffering) {
|
|
53
|
-
logger.warn('Buffer timeout reached, auto-flushing');
|
|
54
|
-
flush();
|
|
55
|
-
}
|
|
56
|
-
}, BUFFER_TIMEOUT_MS);
|
|
57
|
-
}
|
|
58
|
-
bufferCount++;
|
|
59
|
-
}
|
|
60
|
-
function flush() {
|
|
61
|
-
if (!isBuffering) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
logger.debug({ bufferCount }, 'Flushing event buffer');
|
|
65
|
-
isBuffering = false;
|
|
66
|
-
bufferCount = 0;
|
|
67
|
-
if (bufferTimeout) {
|
|
68
|
-
clearTimeout(bufferTimeout);
|
|
69
|
-
bufferTimeout = null;
|
|
70
|
-
}
|
|
71
|
-
if (flushPendingTimeout) {
|
|
72
|
-
clearTimeout(flushPendingTimeout);
|
|
73
|
-
flushPendingTimeout = null;
|
|
74
|
-
}
|
|
75
|
-
if (historyCache.size > MAX_HISTORY_CACHE_SIZE) {
|
|
76
|
-
logger.debug({ cacheSize: historyCache.size }, 'Clearing history cache');
|
|
77
|
-
historyCache.clear();
|
|
78
|
-
}
|
|
79
|
-
const newData = makeBufferData();
|
|
80
|
-
const chatUpdates = Object.values(data.chatUpdates);
|
|
81
|
-
let conditionalChatUpdatesLeft = 0;
|
|
82
|
-
for (const update of chatUpdates) {
|
|
83
|
-
if (update.conditional) {
|
|
84
|
-
conditionalChatUpdatesLeft += 1;
|
|
85
|
-
newData.chatUpdates[update.id] = update;
|
|
86
|
-
delete data.chatUpdates[update.id];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const consolidatedData = consolidateEvents(data);
|
|
90
|
-
if (Object.keys(consolidatedData).length) {
|
|
91
|
-
ev.emit('event', consolidatedData);
|
|
92
|
-
}
|
|
93
|
-
data = newData;
|
|
94
|
-
logger.trace({ conditionalChatUpdatesLeft }, 'released buffered events');
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
process(handler) {
|
|
99
|
-
const listener = async (map) => {
|
|
100
|
-
await handler(map);
|
|
101
|
-
};
|
|
102
|
-
ev.on('event', listener);
|
|
103
|
-
return () => {
|
|
104
|
-
ev.off('event', listener);
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
emit(event, evData) {
|
|
108
|
-
if (event === 'messages.upsert') {
|
|
109
|
-
const { type } = evData;
|
|
110
|
-
const existingUpserts = Object.values(data.messageUpserts);
|
|
111
|
-
if (existingUpserts.length > 0) {
|
|
112
|
-
const bufferedType = existingUpserts[0].type;
|
|
113
|
-
if (bufferedType !== type) {
|
|
114
|
-
logger.debug({ bufferedType, newType: type }, 'messages.upsert type mismatch, emitting buffered messages');
|
|
115
|
-
ev.emit('event', {
|
|
116
|
-
'messages.upsert': {
|
|
117
|
-
messages: existingUpserts.map(m => m.message),
|
|
118
|
-
type: bufferedType
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
data.messageUpserts = {};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (isBuffering && BUFFERABLE_EVENT_SET.has(event)) {
|
|
126
|
-
append(data, historyCache, event, evData, logger);
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
return ev.emit('event', { [event]: evData });
|
|
130
|
-
},
|
|
131
|
-
isBuffering() {
|
|
132
|
-
return isBuffering;
|
|
133
|
-
},
|
|
134
|
-
buffer,
|
|
135
|
-
flush,
|
|
136
|
-
createBufferedFunction(work) {
|
|
137
|
-
return async (...args) => {
|
|
138
|
-
buffer();
|
|
139
|
-
try {
|
|
140
|
-
const result = await work(...args);
|
|
141
|
-
if (bufferCount === 1) {
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
if (isBuffering && bufferCount === 1) {
|
|
144
|
-
flush();
|
|
145
|
-
}
|
|
146
|
-
}, 100);
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
finally {
|
|
154
|
-
bufferCount = Math.max(0, bufferCount - 1);
|
|
155
|
-
if (bufferCount === 0) {
|
|
156
|
-
if (!flushPendingTimeout) {
|
|
157
|
-
flushPendingTimeout = setTimeout(flush, 100);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
on: (...args) => ev.on(...args),
|
|
164
|
-
off: (...args) => ev.off(...args),
|
|
165
|
-
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
|
-
exports.makeEventBuffer = makeEventBuffer;
|
|
169
|
-
const makeBufferData = () => {
|
|
170
|
-
return {
|
|
171
|
-
historySets: {
|
|
172
|
-
chats: {},
|
|
173
|
-
messages: {},
|
|
174
|
-
contacts: {},
|
|
175
|
-
isLatest: false,
|
|
176
|
-
empty: true
|
|
177
|
-
},
|
|
178
|
-
chatUpserts: {},
|
|
179
|
-
chatUpdates: {},
|
|
180
|
-
chatDeletes: new Set(),
|
|
181
|
-
contactUpserts: {},
|
|
182
|
-
contactUpdates: {},
|
|
183
|
-
messageUpserts: {},
|
|
184
|
-
messageUpdates: {},
|
|
185
|
-
messageReactions: {},
|
|
186
|
-
messageDeletes: {},
|
|
187
|
-
messageReceipts: {},
|
|
188
|
-
groupUpdates: {}
|
|
189
|
-
};
|
|
190
|
-
};
|
|
191
|
-
function append(data, historyCache, event, eventData, logger) {
|
|
192
|
-
switch (event) {
|
|
193
|
-
case 'messaging-history.set':
|
|
194
|
-
for (const chat of eventData.chats) {
|
|
195
|
-
const id = chat.id || '';
|
|
196
|
-
const existingChat = data.historySets.chats[id];
|
|
197
|
-
if (existingChat) {
|
|
198
|
-
existingChat.endOfHistoryTransferType = chat.endOfHistoryTransferType;
|
|
199
|
-
}
|
|
200
|
-
if (!existingChat && !historyCache.has(id)) {
|
|
201
|
-
data.historySets.chats[id] = chat;
|
|
202
|
-
historyCache.add(id);
|
|
203
|
-
absorbingChatUpdate(chat);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
for (const contact of eventData.contacts) {
|
|
207
|
-
const existingContact = data.historySets.contacts[contact.id];
|
|
208
|
-
if (existingContact) {
|
|
209
|
-
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
const historyContactId = `c:${contact.id}`;
|
|
213
|
-
const hasAnyName = contact.notify || contact.name || contact.verifiedName;
|
|
214
|
-
if (!historyCache.has(historyContactId) || hasAnyName) {
|
|
215
|
-
data.historySets.contacts[contact.id] = contact;
|
|
216
|
-
historyCache.add(historyContactId);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
for (const message of eventData.messages) {
|
|
221
|
-
const key = stringifyMessageKey(message.key);
|
|
222
|
-
const existingMsg = data.historySets.messages[key];
|
|
223
|
-
if (!existingMsg && !historyCache.has(key)) {
|
|
224
|
-
data.historySets.messages[key] = message;
|
|
225
|
-
historyCache.add(key);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
data.historySets.empty = false;
|
|
229
|
-
data.historySets.syncType = eventData.syncType;
|
|
230
|
-
if (eventData.pastParticipants?.length) {
|
|
231
|
-
const merged = new Map();
|
|
232
|
-
const sigOf = p => `${p.userJid || ''}:${p.leaveTs || ''}:${p.leaveReason || ''}`;
|
|
233
|
-
const ingest = entry => {
|
|
234
|
-
const key = entry.groupJid ?? JSON.stringify(entry);
|
|
235
|
-
const existing = merged.get(key);
|
|
236
|
-
if (!existing) {
|
|
237
|
-
merged.set(key, { ...entry, pastParticipants: [...(entry.pastParticipants || [])] });
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const seen = new Set((existing.pastParticipants || []).map(sigOf));
|
|
241
|
-
for (const p of entry.pastParticipants || []) {
|
|
242
|
-
const sig = sigOf(p);
|
|
243
|
-
if (!seen.has(sig)) {
|
|
244
|
-
existing.pastParticipants.push(p);
|
|
245
|
-
seen.add(sig);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
for (const entry of data.historySets.pastParticipants || [])
|
|
250
|
-
ingest(entry);
|
|
251
|
-
for (const entry of eventData.pastParticipants)
|
|
252
|
-
ingest(entry);
|
|
253
|
-
data.historySets.pastParticipants = [...merged.values()];
|
|
254
|
-
}
|
|
255
|
-
data.historySets.chunkOrder = eventData.chunkOrder;
|
|
256
|
-
data.historySets.progress = eventData.progress;
|
|
257
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
258
|
-
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
259
|
-
break;
|
|
260
|
-
case 'chats.upsert':
|
|
261
|
-
for (const chat of eventData) {
|
|
262
|
-
const id = chat.id || '';
|
|
263
|
-
let upsert = data.chatUpserts[id];
|
|
264
|
-
if (id && !upsert) {
|
|
265
|
-
upsert = data.historySets.chats[id];
|
|
266
|
-
if (upsert) {
|
|
267
|
-
logger.debug({ chatId: id }, 'absorbed chat upsert in chat set');
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (upsert) {
|
|
271
|
-
upsert = concatChats(upsert, chat);
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
upsert = chat;
|
|
275
|
-
data.chatUpserts[id] = upsert;
|
|
276
|
-
}
|
|
277
|
-
absorbingChatUpdate(upsert);
|
|
278
|
-
if (data.chatDeletes.has(id)) {
|
|
279
|
-
data.chatDeletes.delete(id);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
case 'chats.update':
|
|
284
|
-
for (const update of eventData) {
|
|
285
|
-
const chatId = update.id;
|
|
286
|
-
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
287
|
-
if (conditionMatches) {
|
|
288
|
-
delete update.conditional;
|
|
289
|
-
const upsert = data.historySets.chats[chatId] || data.chatUpserts[chatId];
|
|
290
|
-
if (upsert) {
|
|
291
|
-
concatChats(upsert, update);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
const chatUpdate = data.chatUpdates[chatId] || {};
|
|
295
|
-
data.chatUpdates[chatId] = concatChats(chatUpdate, update);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else if (conditionMatches === undefined) {
|
|
299
|
-
data.chatUpdates[chatId] = update;
|
|
300
|
-
}
|
|
301
|
-
if (data.chatDeletes.has(chatId)) {
|
|
302
|
-
data.chatDeletes.delete(chatId);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
break;
|
|
306
|
-
case 'chats.delete':
|
|
307
|
-
for (const chatId of eventData) {
|
|
308
|
-
if (!data.chatDeletes.has(chatId)) {
|
|
309
|
-
data.chatDeletes.add(chatId);
|
|
310
|
-
}
|
|
311
|
-
if (data.chatUpdates[chatId]) {
|
|
312
|
-
delete data.chatUpdates[chatId];
|
|
313
|
-
}
|
|
314
|
-
if (data.chatUpserts[chatId]) {
|
|
315
|
-
delete data.chatUpserts[chatId];
|
|
316
|
-
}
|
|
317
|
-
if (data.historySets.chats[chatId]) {
|
|
318
|
-
delete data.historySets.chats[chatId];
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
break;
|
|
322
|
-
case 'contacts.upsert':
|
|
323
|
-
for (const contact of eventData) {
|
|
324
|
-
let upsert = data.contactUpserts[contact.id];
|
|
325
|
-
if (!upsert) {
|
|
326
|
-
upsert = data.historySets.contacts[contact.id];
|
|
327
|
-
if (upsert) {
|
|
328
|
-
logger.debug({ contactId: contact.id }, 'absorbed contact upsert in contact set');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (upsert) {
|
|
332
|
-
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
upsert = contact;
|
|
336
|
-
data.contactUpserts[contact.id] = upsert;
|
|
337
|
-
}
|
|
338
|
-
if (data.contactUpdates[contact.id]) {
|
|
339
|
-
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
340
|
-
delete data.contactUpdates[contact.id];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
|
-
case 'contacts.update':
|
|
345
|
-
const contactUpdates = eventData;
|
|
346
|
-
for (const update of contactUpdates) {
|
|
347
|
-
const id = update.id;
|
|
348
|
-
const upsert = data.historySets.contacts[id] || data.contactUpserts[id];
|
|
349
|
-
if (upsert) {
|
|
350
|
-
Object.assign(upsert, update);
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
const contactUpdate = data.contactUpdates[id] || {};
|
|
354
|
-
data.contactUpdates[id] = Object.assign(contactUpdate, update);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
break;
|
|
358
|
-
case 'messages.upsert':
|
|
359
|
-
const { messages, type } = eventData;
|
|
360
|
-
for (const message of messages) {
|
|
361
|
-
const key = stringifyMessageKey(message.key);
|
|
362
|
-
let existing = data.messageUpserts[key]?.message;
|
|
363
|
-
if (!existing) {
|
|
364
|
-
existing = data.historySets.messages[key];
|
|
365
|
-
if (existing) {
|
|
366
|
-
logger.debug({ messageId: key }, 'absorbed message upsert in message set');
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (existing) {
|
|
370
|
-
message.messageTimestamp = existing.messageTimestamp;
|
|
371
|
-
}
|
|
372
|
-
if (data.messageUpdates[key]) {
|
|
373
|
-
logger.debug('absorbed prior message update in message upsert');
|
|
374
|
-
Object.assign(message, data.messageUpdates[key].update);
|
|
375
|
-
delete data.messageUpdates[key];
|
|
376
|
-
}
|
|
377
|
-
if (data.historySets.messages[key]) {
|
|
378
|
-
data.historySets.messages[key] = message;
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
data.messageUpserts[key] = {
|
|
382
|
-
message,
|
|
383
|
-
type: type === 'notify' || data.messageUpserts[key]?.type === 'notify' ? 'notify' : type
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
break;
|
|
388
|
-
case 'messages.update':
|
|
389
|
-
const msgUpdates = eventData;
|
|
390
|
-
for (const { key, update } of msgUpdates) {
|
|
391
|
-
const keyStr = stringifyMessageKey(key);
|
|
392
|
-
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]?.message;
|
|
393
|
-
if (existing) {
|
|
394
|
-
Object.assign(existing, update);
|
|
395
|
-
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
396
|
-
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
const msgUpdate = data.messageUpdates[keyStr] || { key, update: {} };
|
|
401
|
-
Object.assign(msgUpdate.update, update);
|
|
402
|
-
data.messageUpdates[keyStr] = msgUpdate;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
break;
|
|
406
|
-
case 'messages.delete':
|
|
407
|
-
const deleteData = eventData;
|
|
408
|
-
if ('keys' in deleteData) {
|
|
409
|
-
const { keys } = deleteData;
|
|
410
|
-
for (const key of keys) {
|
|
411
|
-
const keyStr = stringifyMessageKey(key);
|
|
412
|
-
if (!data.messageDeletes[keyStr]) {
|
|
413
|
-
data.messageDeletes[keyStr] = key;
|
|
414
|
-
}
|
|
415
|
-
if (data.messageUpserts[keyStr]) {
|
|
416
|
-
delete data.messageUpserts[keyStr];
|
|
417
|
-
}
|
|
418
|
-
if (data.messageUpdates[keyStr]) {
|
|
419
|
-
delete data.messageUpdates[keyStr];
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
}
|
|
425
|
-
break;
|
|
426
|
-
case 'messages.reaction':
|
|
427
|
-
const reactions = eventData;
|
|
428
|
-
for (const { key, reaction } of reactions) {
|
|
429
|
-
const keyStr = stringifyMessageKey(key);
|
|
430
|
-
const existing = data.messageUpserts[keyStr];
|
|
431
|
-
if (existing) {
|
|
432
|
-
;
|
|
433
|
-
(0, messages_1.updateMessageWithReaction)(existing.message, reaction);
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
data.messageReactions[keyStr] = data.messageReactions[keyStr] || { key, reactions: [] };
|
|
437
|
-
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
break;
|
|
441
|
-
case 'message-receipt.update':
|
|
442
|
-
const receipts = eventData;
|
|
443
|
-
for (const { key, receipt } of receipts) {
|
|
444
|
-
const keyStr = stringifyMessageKey(key);
|
|
445
|
-
const existing = data.messageUpserts[keyStr];
|
|
446
|
-
if (existing) {
|
|
447
|
-
;
|
|
448
|
-
(0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
data.messageReceipts[keyStr] = data.messageReceipts[keyStr] || { key, userReceipt: [] };
|
|
452
|
-
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
break;
|
|
456
|
-
case 'groups.update':
|
|
457
|
-
const groupUpdates = eventData;
|
|
458
|
-
for (const update of groupUpdates) {
|
|
459
|
-
const id = update.id;
|
|
460
|
-
const groupUpdate = data.groupUpdates[id] || {};
|
|
461
|
-
if (!data.groupUpdates[id]) {
|
|
462
|
-
data.groupUpdates[id] = Object.assign(groupUpdate, update);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
break;
|
|
466
|
-
default:
|
|
467
|
-
throw new Error(`"${event}" cannot be buffered`);
|
|
468
|
-
}
|
|
469
|
-
function absorbingChatUpdate(existing) {
|
|
470
|
-
const chatId = existing.id || '';
|
|
471
|
-
const update = data.chatUpdates[chatId];
|
|
472
|
-
if (update) {
|
|
473
|
-
const conditionMatches = update.conditional ? update.conditional(data) : true;
|
|
474
|
-
if (conditionMatches) {
|
|
475
|
-
delete update.conditional;
|
|
476
|
-
logger.debug({ chatId }, 'absorbed chat update in existing chat');
|
|
477
|
-
Object.assign(existing, concatChats(update, existing));
|
|
478
|
-
delete data.chatUpdates[chatId];
|
|
479
|
-
}
|
|
480
|
-
else if (conditionMatches === false) {
|
|
481
|
-
logger.debug({ chatId }, 'chat update condition fail, removing');
|
|
482
|
-
delete data.chatUpdates[chatId];
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function decrementChatReadCounterIfMsgDidUnread(message) {
|
|
487
|
-
const chatId = message.key.remoteJid;
|
|
488
|
-
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
489
|
-
if ((0, process_message_1.isRealMessage)(message) &&
|
|
490
|
-
(0, process_message_1.shouldIncrementChatUnread)(message) &&
|
|
491
|
-
typeof chat?.unreadCount === 'number' &&
|
|
492
|
-
chat.unreadCount > 0) {
|
|
493
|
-
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
494
|
-
chat.unreadCount -= 1;
|
|
495
|
-
if (chat.unreadCount === 0) {
|
|
496
|
-
delete chat.unreadCount;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function consolidateEvents(data) {
|
|
502
|
-
const map = {};
|
|
503
|
-
if (!data.historySets.empty) {
|
|
504
|
-
map['messaging-history.set'] = {
|
|
505
|
-
chats: Object.values(data.historySets.chats),
|
|
506
|
-
messages: Object.values(data.historySets.messages),
|
|
507
|
-
contacts: Object.values(data.historySets.contacts),
|
|
508
|
-
pastParticipants: data.historySets.pastParticipants,
|
|
509
|
-
syncType: data.historySets.syncType,
|
|
510
|
-
progress: data.historySets.progress,
|
|
511
|
-
isLatest: data.historySets.isLatest,
|
|
512
|
-
chunkOrder: data.historySets.chunkOrder,
|
|
513
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
const chatUpsertList = Object.values(data.chatUpserts);
|
|
517
|
-
if (chatUpsertList.length) {
|
|
518
|
-
map['chats.upsert'] = chatUpsertList;
|
|
519
|
-
}
|
|
520
|
-
const chatUpdateList = Object.values(data.chatUpdates);
|
|
521
|
-
if (chatUpdateList.length) {
|
|
522
|
-
map['chats.update'] = chatUpdateList;
|
|
523
|
-
}
|
|
524
|
-
const chatDeleteList = Array.from(data.chatDeletes);
|
|
525
|
-
if (chatDeleteList.length) {
|
|
526
|
-
map['chats.delete'] = chatDeleteList;
|
|
527
|
-
}
|
|
528
|
-
const messageUpsertList = Object.values(data.messageUpserts);
|
|
529
|
-
if (messageUpsertList.length) {
|
|
530
|
-
const type = messageUpsertList[0].type;
|
|
531
|
-
map['messages.upsert'] = {
|
|
532
|
-
messages: messageUpsertList.map(m => m.message),
|
|
533
|
-
type
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
const messageUpdateList = Object.values(data.messageUpdates);
|
|
537
|
-
if (messageUpdateList.length) {
|
|
538
|
-
map['messages.update'] = messageUpdateList;
|
|
539
|
-
}
|
|
540
|
-
const messageDeleteList = Object.values(data.messageDeletes);
|
|
541
|
-
if (messageDeleteList.length) {
|
|
542
|
-
map['messages.delete'] = { keys: messageDeleteList };
|
|
543
|
-
}
|
|
544
|
-
const messageReactionList = Object.values(data.messageReactions).flatMap(({ key, reactions }) => reactions.flatMap(reaction => ({ key, reaction })));
|
|
545
|
-
if (messageReactionList.length) {
|
|
546
|
-
map['messages.reaction'] = messageReactionList;
|
|
547
|
-
}
|
|
548
|
-
const messageReceiptList = Object.values(data.messageReceipts).flatMap(({ key, userReceipt }) => userReceipt.flatMap(receipt => ({ key, receipt })));
|
|
549
|
-
if (messageReceiptList.length) {
|
|
550
|
-
map['message-receipt.update'] = messageReceiptList;
|
|
551
|
-
}
|
|
552
|
-
const contactUpsertList = Object.values(data.contactUpserts);
|
|
553
|
-
if (contactUpsertList.length) {
|
|
554
|
-
map['contacts.upsert'] = contactUpsertList;
|
|
555
|
-
}
|
|
556
|
-
const contactUpdateList = Object.values(data.contactUpdates);
|
|
557
|
-
if (contactUpdateList.length) {
|
|
558
|
-
map['contacts.update'] = contactUpdateList;
|
|
559
|
-
}
|
|
560
|
-
const groupUpdateList = Object.values(data.groupUpdates);
|
|
561
|
-
if (groupUpdateList.length) {
|
|
562
|
-
map['groups.update'] = groupUpdateList;
|
|
563
|
-
}
|
|
564
|
-
return map;
|
|
565
|
-
}
|
|
566
|
-
function concatChats(a, b) {
|
|
567
|
-
if (b.unreadCount === null &&
|
|
568
|
-
a.unreadCount < 0) {
|
|
569
|
-
a.unreadCount = undefined;
|
|
570
|
-
b.unreadCount = undefined;
|
|
571
|
-
}
|
|
572
|
-
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
573
|
-
b = { ...b };
|
|
574
|
-
if (b.unreadCount >= 0) {
|
|
575
|
-
b.unreadCount = Math.max(b.unreadCount, 0) + Math.max(a.unreadCount, 0);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
return Object.assign(a, b);
|
|
579
|
-
}
|
|
580
|
-
const stringifyMessageKey = key => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|