@sanzoffc/baileys 3.0.1 → 3.0.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/WAProto/WAProto.proto +769 -233
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -114
- package/lib/Defaults/index.js.bak +123 -0
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -18
- package/lib/Socket/Client/types.js +12 -12
- package/lib/Socket/Client/websocket.js +51 -71
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +858 -945
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -324
- package/lib/Socket/index.js +15 -9
- package/lib/Socket/messages-recv.js +1105 -1046
- package/lib/Socket/messages-send.js +615 -389
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +224 -227
- package/lib/Socket/socket.js +795 -621
- package/lib/Store/index.js +6 -8
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +286 -435
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -7
- package/lib/Types/Newsletter.js +32 -17
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -191
- package/lib/Utils/baileys-event-stream.js +44 -0
- package/lib/Utils/browser-utils.js +21 -31
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -175
- package/lib/Utils/decode-wa-message.js +254 -194
- package/lib/Utils/event-buffer.js +510 -500
- package/lib/Utils/generics.js +318 -430
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +21 -35
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +33 -48
- package/lib/Utils/messages-media.js +573 -825
- package/lib/Utils/messages.js +349 -489
- package/lib/Utils/noise-handler.js +138 -144
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +321 -384
- package/lib/Utils/signal.js +147 -139
- package/lib/Utils/use-multi-file-auth-state.js +95 -109
- package/lib/Utils/validate-connection.js +183 -212
- package/lib/WABinary/constants.js +1298 -1298
- package/lib/WABinary/decode.js +231 -256
- package/lib/WABinary/encode.js +207 -239
- package/lib/WABinary/generic-utils.js +119 -40
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +87 -79
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +18 -49
- package/package.json +65 -78
- package/README.MD +0 -1295
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/p.html +0 -1
- package/engine-requirements.js +0 -10
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.js +0 -70
- package/lib/Utils/wileys-event-stream.js +0 -63
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const lru_cache_1 = require("lru-cache");
|
|
6
|
-
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { LRUCache } from "lru-cache";
|
|
3
|
+
//=======================================================//
|
|
7
4
|
const RECENT_MESSAGES_SIZE = 512;
|
|
8
|
-
|
|
9
5
|
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000;
|
|
10
|
-
|
|
11
6
|
const PHONE_REQUEST_DELAY = 3000;
|
|
12
|
-
|
|
13
|
-
class MessageRetryManager {
|
|
7
|
+
export class MessageRetryManager {
|
|
14
8
|
constructor(logger, maxMsgRetryCount) {
|
|
15
9
|
this.logger = logger;
|
|
16
|
-
this.
|
|
17
|
-
this._recentMessagesMap = new lru_cache_1.LRUCache({
|
|
10
|
+
this.recentMessagesMap = new LRUCache({
|
|
18
11
|
max: RECENT_MESSAGES_SIZE
|
|
19
12
|
});
|
|
20
|
-
this.
|
|
13
|
+
this.sessionRecreateHistory = new LRUCache({
|
|
21
14
|
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
22
15
|
ttlAutopurge: true
|
|
23
16
|
});
|
|
24
|
-
this.
|
|
17
|
+
this.retryCounters = new LRUCache({
|
|
25
18
|
ttl: 15 * 60 * 1000,
|
|
26
19
|
ttlAutopurge: true,
|
|
27
20
|
updateAgeOnGet: true
|
|
28
21
|
});
|
|
29
|
-
this.
|
|
22
|
+
this.pendingPhoneRequests = {};
|
|
23
|
+
this.maxMsgRetryCount = 5;
|
|
30
24
|
this.statistics = {
|
|
31
25
|
totalRetries: 0,
|
|
32
26
|
successfulRetries: 0,
|
|
@@ -39,8 +33,8 @@ class MessageRetryManager {
|
|
|
39
33
|
}
|
|
40
34
|
addRecentMessage(to, id, message) {
|
|
41
35
|
const key = { to, id };
|
|
42
|
-
const keyStr = this.
|
|
43
|
-
this.
|
|
36
|
+
const keyStr = this.keyToString(key);
|
|
37
|
+
this.recentMessagesMap.set(keyStr, {
|
|
44
38
|
message,
|
|
45
39
|
timestamp: Date.now()
|
|
46
40
|
});
|
|
@@ -48,81 +42,72 @@ class MessageRetryManager {
|
|
|
48
42
|
}
|
|
49
43
|
getRecentMessage(to, id) {
|
|
50
44
|
const key = { to, id };
|
|
51
|
-
const keyStr = this.
|
|
52
|
-
return this.
|
|
45
|
+
const keyStr = this.keyToString(key);
|
|
46
|
+
return this.recentMessagesMap.get(keyStr);
|
|
53
47
|
}
|
|
54
48
|
shouldRecreateSession(jid, retryCount, hasSession) {
|
|
55
49
|
if (!hasSession) {
|
|
56
|
-
this.
|
|
50
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
57
51
|
this.statistics.sessionRecreations++;
|
|
58
52
|
return {
|
|
59
|
-
reason: "we
|
|
53
|
+
reason: "we dont have a Signal session with them",
|
|
60
54
|
recreate: true
|
|
61
55
|
};
|
|
62
56
|
}
|
|
63
57
|
if (retryCount < 2) {
|
|
64
|
-
return { reason:
|
|
58
|
+
return { reason: "", recreate: false };
|
|
65
59
|
}
|
|
66
60
|
const now = Date.now();
|
|
67
|
-
const prevTime = this.
|
|
61
|
+
const prevTime = this.sessionRecreateHistory.get(jid);
|
|
68
62
|
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
69
|
-
this.
|
|
63
|
+
this.sessionRecreateHistory.set(jid, now);
|
|
70
64
|
this.statistics.sessionRecreations++;
|
|
71
65
|
return {
|
|
72
|
-
reason:
|
|
66
|
+
reason: "retry count > 1 and over an hour since last recreation",
|
|
73
67
|
recreate: true
|
|
74
68
|
};
|
|
75
69
|
}
|
|
76
|
-
return { reason:
|
|
70
|
+
return { reason: "", recreate: false };
|
|
77
71
|
}
|
|
78
72
|
incrementRetryCount(messageId) {
|
|
79
|
-
this.
|
|
73
|
+
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
80
74
|
this.statistics.totalRetries++;
|
|
81
|
-
return this.
|
|
75
|
+
return this.retryCounters.get(messageId);
|
|
82
76
|
}
|
|
83
77
|
getRetryCount(messageId) {
|
|
84
|
-
return this.
|
|
78
|
+
return this.retryCounters.get(messageId) || 0;
|
|
85
79
|
}
|
|
86
80
|
hasExceededMaxRetries(messageId) {
|
|
87
81
|
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
88
82
|
}
|
|
89
83
|
markRetrySuccess(messageId) {
|
|
90
84
|
this.statistics.successfulRetries++;
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
85
|
+
this.retryCounters.delete(messageId);
|
|
86
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
93
87
|
}
|
|
94
88
|
markRetryFailed(messageId) {
|
|
95
89
|
this.statistics.failedRetries++;
|
|
96
|
-
this.
|
|
90
|
+
this.retryCounters.delete(messageId);
|
|
97
91
|
}
|
|
98
92
|
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
delete this.
|
|
93
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
94
|
+
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
95
|
+
delete this.pendingPhoneRequests[messageId];
|
|
102
96
|
this.statistics.phoneRequests++;
|
|
103
97
|
callback();
|
|
104
98
|
}, delay);
|
|
105
99
|
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
106
100
|
}
|
|
107
101
|
cancelPendingPhoneRequest(messageId) {
|
|
108
|
-
const timeout = this.
|
|
102
|
+
const timeout = this.pendingPhoneRequests[messageId];
|
|
109
103
|
if (timeout) {
|
|
110
104
|
clearTimeout(timeout);
|
|
111
|
-
delete this.
|
|
105
|
+
delete this.pendingPhoneRequests[messageId];
|
|
112
106
|
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
113
107
|
}
|
|
114
108
|
}
|
|
115
|
-
|
|
109
|
+
keyToString(key) {
|
|
116
110
|
return `${key.to}:${key.id}`;
|
|
117
111
|
}
|
|
118
|
-
_cancelPendingPhoneRequest(messageId) {
|
|
119
|
-
const timeout = this._pendingPhoneRequests[messageId];
|
|
120
|
-
if (timeout) {
|
|
121
|
-
clearTimeout(timeout);
|
|
122
|
-
delete this._pendingPhoneRequests[messageId];
|
|
123
|
-
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
112
|
}
|
|
127
|
-
|
|
128
|
-
exports.MessageRetryManager = MessageRetryManager;
|
|
113
|
+
//=======================================================//
|