@d0v3riz/baileys 6.7.21 → 6.7.22
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/GenerateStatics.sh +2 -3
- package/WAProto/index.js +4138 -4136
- package/lib/Defaults/index.d.ts +2 -3
- package/lib/Defaults/index.js +40 -36
- 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 +2 -3
- package/lib/Signal/Group/group_cipher.js +16 -14
- 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 -8
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
- package/lib/Signal/Group/sender-chain-key.js +9 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -10
- 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 +1 -2
- package/lib/Signal/Group/sender-key-record.js +12 -9
- package/lib/Signal/Group/sender-key-state.d.ts +2 -3
- package/lib/Signal/Group/sender-key-state.js +9 -6
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -5
- package/lib/Signal/libsignal.d.ts +2 -3
- package/lib/Signal/libsignal.js +55 -22
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.d.ts +1 -2
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.d.ts +1 -2
- package/lib/Socket/Client/websocket.js +26 -14
- package/lib/Socket/business.d.ts +64 -66
- package/lib/Socket/business.js +37 -32
- package/lib/Socket/chats.d.ts +19 -21
- package/lib/Socket/chats.js +141 -176
- package/lib/Socket/groups.d.ts +35 -37
- package/lib/Socket/groups.js +63 -56
- package/lib/Socket/index.d.ts +70 -102
- package/lib/Socket/index.js +9 -16
- package/lib/Socket/messages-recv.d.ts +49 -51
- package/lib/Socket/messages-recv.js +173 -180
- package/lib/Socket/messages-send.d.ts +46 -48
- package/lib/Socket/messages-send.js +84 -75
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.js +16 -12
- package/lib/Socket/newsletter.d.ts +44 -46
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.d.ts +12 -13
- package/lib/Socket/socket.js +115 -135
- package/lib/Socket/usync.d.ts +14 -15
- package/lib/Socket/usync.js +11 -9
- package/lib/Types/Auth.d.ts +3 -4
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +0 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +7 -10
- package/lib/Types/Chat.js +4 -2
- package/lib/Types/Contact.d.ts +0 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +10 -11
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- 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 +7 -9
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.d.ts +0 -1
- package/lib/Types/Newsletter.js +7 -5
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +7 -8
- 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 -15
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +2 -3
- package/lib/Utils/auth-utils.js +34 -25
- 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 +70 -61
- package/lib/Utils/chat-utils.d.ts +7 -8
- package/lib/Utils/chat-utils.js +137 -130
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +86 -37
- package/lib/Utils/decode-wa-message.d.ts +4 -5
- package/lib/Utils/decode-wa-message.js +44 -38
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.js +50 -37
- package/lib/Utils/generics.d.ts +8 -9
- package/lib/Utils/generics.js +114 -87
- package/lib/Utils/history.d.ts +3 -4
- package/lib/Utils/history.js +40 -32
- package/lib/Utils/index.d.ts +17 -18
- package/lib/Utils/index.js +33 -18
- package/lib/Utils/link-preview.d.ts +3 -4
- package/lib/Utils/link-preview.js +47 -10
- package/lib/Utils/logger.d.ts +6 -8
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.d.ts +0 -1
- package/lib/Utils/make-mutex.js +9 -5
- package/lib/Utils/messages-media.d.ts +10 -11
- package/lib/Utils/messages-media.js +203 -141
- package/lib/Utils/messages.d.ts +6 -7
- package/lib/Utils/messages.js +199 -190
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +26 -22
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +104 -95
- package/lib/Utils/signal.d.ts +4 -5
- package/lib/Utils/signal.js +52 -47
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +26 -23
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +58 -52
- package/lib/WABinary/constants.d.ts +0 -1
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +51 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +41 -5
- package/lib/WABinary/generic-utils.d.ts +3 -4
- package/lib/WABinary/generic-utils.js +38 -30
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.js +35 -21
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +6 -4
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +14 -12
- 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 +9 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -4
- package/lib/WAUSync/USyncQuery.js +20 -18
- 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 +8 -9
- package/lib/index.js +30 -11
- package/package.json +26 -26
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts.map +0 -1
- package/lib/Signal/Group/queue-job.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -219
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Socket/usync.d.ts.map +0 -1
- package/lib/Socket/usync.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Socket/chats.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.makeChatsSocket = void 0;
|
|
7
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
8
|
+
const boom_1 = require("@hapi/boom");
|
|
9
|
+
const WAProto_1 = require("../../WAProto");
|
|
10
|
+
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const Types_1 = require("../Types");
|
|
12
|
+
const Utils_1 = require("../Utils");
|
|
13
|
+
const make_mutex_1 = require("../Utils/make-mutex");
|
|
14
|
+
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
15
|
+
const WABinary_1 = require("../WABinary");
|
|
16
|
+
const WAUSync_1 = require("../WAUSync");
|
|
17
|
+
const usync_1 = require("./usync");
|
|
13
18
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
14
|
-
|
|
19
|
+
const makeChatsSocket = (config) => {
|
|
15
20
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
16
|
-
const sock = makeUSyncSocket(config);
|
|
21
|
+
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
17
22
|
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
18
23
|
let privacySettings;
|
|
19
|
-
let
|
|
24
|
+
let needToFlushWithAppStateSync = false;
|
|
25
|
+
let pendingAppStateSync = false;
|
|
20
26
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
21
|
-
const processingMutex = makeMutex();
|
|
22
|
-
// Timeout for AwaitingInitialSync state
|
|
23
|
-
let awaitingSyncTimeout;
|
|
27
|
+
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
24
28
|
const placeholderResendCache = config.placeholderResendCache ||
|
|
25
|
-
new
|
|
26
|
-
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
29
|
+
new node_cache_1.default({
|
|
30
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
27
31
|
useClones: false
|
|
28
32
|
});
|
|
29
33
|
if (!config.placeholderResendCache) {
|
|
@@ -40,12 +44,12 @@ export const makeChatsSocket = (config) => {
|
|
|
40
44
|
tag: 'iq',
|
|
41
45
|
attrs: {
|
|
42
46
|
xmlns: 'privacy',
|
|
43
|
-
to: S_WHATSAPP_NET,
|
|
47
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
44
48
|
type: 'get'
|
|
45
49
|
},
|
|
46
50
|
content: [{ tag: 'privacy', attrs: {} }]
|
|
47
51
|
});
|
|
48
|
-
privacySettings = reduceBinaryNodeToDictionary(content
|
|
52
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
49
53
|
}
|
|
50
54
|
return privacySettings;
|
|
51
55
|
};
|
|
@@ -55,7 +59,7 @@ export const makeChatsSocket = (config) => {
|
|
|
55
59
|
tag: 'iq',
|
|
56
60
|
attrs: {
|
|
57
61
|
xmlns: 'privacy',
|
|
58
|
-
to: S_WHATSAPP_NET,
|
|
62
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
59
63
|
type: 'set'
|
|
60
64
|
},
|
|
61
65
|
content: [
|
|
@@ -101,7 +105,7 @@ export const makeChatsSocket = (config) => {
|
|
|
101
105
|
tag: 'iq',
|
|
102
106
|
attrs: {
|
|
103
107
|
xmlns: 'disappearing_mode',
|
|
104
|
-
to: S_WHATSAPP_NET,
|
|
108
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
105
109
|
type: 'set'
|
|
106
110
|
},
|
|
107
111
|
content: [
|
|
@@ -119,7 +123,7 @@ export const makeChatsSocket = (config) => {
|
|
|
119
123
|
tag: 'iq',
|
|
120
124
|
attrs: {
|
|
121
125
|
xmlns: 'bot',
|
|
122
|
-
to: S_WHATSAPP_NET,
|
|
126
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
123
127
|
type: 'get'
|
|
124
128
|
},
|
|
125
129
|
content: [
|
|
@@ -131,11 +135,11 @@ export const makeChatsSocket = (config) => {
|
|
|
131
135
|
}
|
|
132
136
|
]
|
|
133
137
|
});
|
|
134
|
-
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
138
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
135
139
|
const botList = [];
|
|
136
|
-
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
140
|
+
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
|
137
141
|
if (section.attrs.type === 'all') {
|
|
138
|
-
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
142
|
+
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
|
139
143
|
botList.push({
|
|
140
144
|
jid: bot.attrs.jid,
|
|
141
145
|
personaId: bot.attrs['persona_id']
|
|
@@ -146,10 +150,10 @@ export const makeChatsSocket = (config) => {
|
|
|
146
150
|
return botList;
|
|
147
151
|
};
|
|
148
152
|
const onWhatsApp = async (...jids) => {
|
|
149
|
-
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
|
|
153
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withContactProtocol().withLIDProtocol();
|
|
150
154
|
for (const jid of jids) {
|
|
151
|
-
const phone = `+${jid.replace('+', '').split('@')[0]
|
|
152
|
-
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
155
|
+
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
156
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
153
157
|
}
|
|
154
158
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
155
159
|
if (results) {
|
|
@@ -157,9 +161,9 @@ export const makeChatsSocket = (config) => {
|
|
|
157
161
|
}
|
|
158
162
|
};
|
|
159
163
|
const fetchStatus = async (...jids) => {
|
|
160
|
-
const usyncQuery = new USyncQuery().withStatusProtocol();
|
|
164
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol();
|
|
161
165
|
for (const jid of jids) {
|
|
162
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
166
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
163
167
|
}
|
|
164
168
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
165
169
|
if (result) {
|
|
@@ -167,9 +171,9 @@ export const makeChatsSocket = (config) => {
|
|
|
167
171
|
}
|
|
168
172
|
};
|
|
169
173
|
const fetchDisappearingDuration = async (...jids) => {
|
|
170
|
-
const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
|
|
174
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol();
|
|
171
175
|
for (const jid of jids) {
|
|
172
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
176
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
173
177
|
}
|
|
174
178
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
175
179
|
if (result) {
|
|
@@ -180,22 +184,19 @@ export const makeChatsSocket = (config) => {
|
|
|
180
184
|
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
181
185
|
let targetJid;
|
|
182
186
|
if (!jid) {
|
|
183
|
-
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
184
|
-
}
|
|
185
|
-
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
186
|
-
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
187
|
+
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
-
targetJid =
|
|
189
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
190
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
190
191
|
}
|
|
191
|
-
const { img } = await generateProfilePicture(content, dimensions);
|
|
192
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
192
193
|
await query({
|
|
193
194
|
tag: 'iq',
|
|
194
195
|
attrs: {
|
|
195
|
-
|
|
196
|
+
target: targetJid,
|
|
197
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
196
198
|
type: 'set',
|
|
197
|
-
xmlns: 'w:profile:picture'
|
|
198
|
-
...(targetJid ? { target: targetJid } : {})
|
|
199
|
+
xmlns: 'w:profile:picture'
|
|
199
200
|
},
|
|
200
201
|
content: [
|
|
201
202
|
{
|
|
@@ -210,21 +211,18 @@ export const makeChatsSocket = (config) => {
|
|
|
210
211
|
const removeProfilePicture = async (jid) => {
|
|
211
212
|
let targetJid;
|
|
212
213
|
if (!jid) {
|
|
213
|
-
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
214
|
+
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
214
215
|
}
|
|
215
|
-
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
216
|
-
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
targetJid = undefined;
|
|
216
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
217
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
220
218
|
}
|
|
221
219
|
await query({
|
|
222
220
|
tag: 'iq',
|
|
223
221
|
attrs: {
|
|
224
|
-
|
|
222
|
+
target: targetJid,
|
|
223
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
225
224
|
type: 'set',
|
|
226
|
-
xmlns: 'w:profile:picture'
|
|
227
|
-
...(targetJid ? { target: targetJid } : {})
|
|
225
|
+
xmlns: 'w:profile:picture'
|
|
228
226
|
}
|
|
229
227
|
});
|
|
230
228
|
};
|
|
@@ -233,7 +231,7 @@ export const makeChatsSocket = (config) => {
|
|
|
233
231
|
await query({
|
|
234
232
|
tag: 'iq',
|
|
235
233
|
attrs: {
|
|
236
|
-
to: S_WHATSAPP_NET,
|
|
234
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
237
235
|
type: 'set',
|
|
238
236
|
xmlns: 'status'
|
|
239
237
|
},
|
|
@@ -254,19 +252,19 @@ export const makeChatsSocket = (config) => {
|
|
|
254
252
|
tag: 'iq',
|
|
255
253
|
attrs: {
|
|
256
254
|
xmlns: 'blocklist',
|
|
257
|
-
to: S_WHATSAPP_NET,
|
|
255
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
258
256
|
type: 'get'
|
|
259
257
|
}
|
|
260
258
|
});
|
|
261
|
-
const listNode = getBinaryNodeChild(result, 'list');
|
|
262
|
-
return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
|
|
259
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
260
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item').map(n => n.attrs.jid);
|
|
263
261
|
};
|
|
264
262
|
const updateBlockStatus = async (jid, action) => {
|
|
265
263
|
await query({
|
|
266
264
|
tag: 'iq',
|
|
267
265
|
attrs: {
|
|
268
266
|
xmlns: 'blocklist',
|
|
269
|
-
to: S_WHATSAPP_NET,
|
|
267
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
270
268
|
type: 'set'
|
|
271
269
|
},
|
|
272
270
|
content: [
|
|
@@ -281,6 +279,7 @@ export const makeChatsSocket = (config) => {
|
|
|
281
279
|
});
|
|
282
280
|
};
|
|
283
281
|
const getBusinessProfile = async (jid) => {
|
|
282
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
284
283
|
const results = await query({
|
|
285
284
|
tag: 'iq',
|
|
286
285
|
attrs: {
|
|
@@ -301,29 +300,29 @@ export const makeChatsSocket = (config) => {
|
|
|
301
300
|
}
|
|
302
301
|
]
|
|
303
302
|
});
|
|
304
|
-
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
305
|
-
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
303
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
304
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
306
305
|
if (profiles) {
|
|
307
|
-
const address = getBinaryNodeChild(profiles, 'address');
|
|
308
|
-
const description = getBinaryNodeChild(profiles, 'description');
|
|
309
|
-
const website = getBinaryNodeChild(profiles, 'website');
|
|
310
|
-
const email = getBinaryNodeChild(profiles, 'email');
|
|
311
|
-
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
312
|
-
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
306
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
307
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
308
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
309
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
310
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
311
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
313
312
|
const businessHoursConfig = businessHours
|
|
314
|
-
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
313
|
+
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
315
314
|
: undefined;
|
|
316
|
-
const websiteStr = website
|
|
315
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
317
316
|
return {
|
|
318
|
-
wid: profiles.attrs
|
|
319
|
-
address: address
|
|
320
|
-
description: description
|
|
317
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
318
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
319
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
321
320
|
website: websiteStr ? [websiteStr] : [],
|
|
322
|
-
email: email
|
|
323
|
-
category: category
|
|
321
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
322
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
324
323
|
business_hours: {
|
|
325
|
-
timezone: businessHours
|
|
326
|
-
business_config: businessHoursConfig
|
|
324
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
325
|
+
business_config: businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
327
326
|
}
|
|
328
327
|
};
|
|
329
328
|
}
|
|
@@ -333,7 +332,7 @@ export const makeChatsSocket = (config) => {
|
|
|
333
332
|
await sendNode({
|
|
334
333
|
tag: 'iq',
|
|
335
334
|
attrs: {
|
|
336
|
-
to: S_WHATSAPP_NET,
|
|
335
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
337
336
|
type: 'set',
|
|
338
337
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
339
338
|
id: generateMessageTag()
|
|
@@ -352,7 +351,7 @@ export const makeChatsSocket = (config) => {
|
|
|
352
351
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
353
352
|
return {
|
|
354
353
|
onMutation(mutation) {
|
|
355
|
-
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
354
|
+
(0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
356
355
|
}
|
|
357
356
|
};
|
|
358
357
|
};
|
|
@@ -362,6 +361,7 @@ export const makeChatsSocket = (config) => {
|
|
|
362
361
|
const initialVersionMap = {};
|
|
363
362
|
const globalMutationMap = {};
|
|
364
363
|
await authState.keys.transaction(async () => {
|
|
364
|
+
var _a;
|
|
365
365
|
const collectionsToHandle = new Set(collections);
|
|
366
366
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
367
367
|
const attemptsMap = {};
|
|
@@ -380,7 +380,7 @@ export const makeChatsSocket = (config) => {
|
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
else {
|
|
383
|
-
state = newLTHashState();
|
|
383
|
+
state = (0, Utils_1.newLTHashState)();
|
|
384
384
|
}
|
|
385
385
|
states[name] = state;
|
|
386
386
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -397,7 +397,7 @@ export const makeChatsSocket = (config) => {
|
|
|
397
397
|
const result = await query({
|
|
398
398
|
tag: 'iq',
|
|
399
399
|
attrs: {
|
|
400
|
-
to: S_WHATSAPP_NET,
|
|
400
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
401
401
|
xmlns: 'w:sync:app:state',
|
|
402
402
|
type: 'set'
|
|
403
403
|
},
|
|
@@ -410,13 +410,13 @@ export const makeChatsSocket = (config) => {
|
|
|
410
410
|
]
|
|
411
411
|
});
|
|
412
412
|
// extract from binary node
|
|
413
|
-
const decoded = await extractSyncdPatches(result, config
|
|
413
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
414
414
|
for (const key in decoded) {
|
|
415
415
|
const name = key;
|
|
416
416
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
417
417
|
try {
|
|
418
418
|
if (snapshot) {
|
|
419
|
-
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
419
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
420
420
|
states[name] = newState;
|
|
421
421
|
Object.assign(globalMutationMap, mutationMap);
|
|
422
422
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
@@ -424,7 +424,7 @@ export const makeChatsSocket = (config) => {
|
|
|
424
424
|
}
|
|
425
425
|
// only process if there are syncd patches
|
|
426
426
|
if (patches.length) {
|
|
427
|
-
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
427
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
428
428
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
429
429
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
430
430
|
initialVersionMap[name] = newState.version;
|
|
@@ -442,7 +442,7 @@ export const makeChatsSocket = (config) => {
|
|
|
442
442
|
// if retry attempts overshoot
|
|
443
443
|
// or key not found
|
|
444
444
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
445
|
-
error.output
|
|
445
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
446
446
|
error.name === 'TypeError';
|
|
447
447
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
448
448
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
@@ -467,19 +467,20 @@ export const makeChatsSocket = (config) => {
|
|
|
467
467
|
* type = "image for the high res picture"
|
|
468
468
|
*/
|
|
469
469
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
470
|
-
|
|
470
|
+
var _a;
|
|
471
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
471
472
|
const result = await query({
|
|
472
473
|
tag: 'iq',
|
|
473
474
|
attrs: {
|
|
474
475
|
target: jid,
|
|
475
|
-
to: S_WHATSAPP_NET,
|
|
476
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
476
477
|
type: 'get',
|
|
477
478
|
xmlns: 'w:profile:picture'
|
|
478
479
|
},
|
|
479
480
|
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
480
481
|
}, timeoutMs);
|
|
481
|
-
const child = getBinaryNodeChild(result, 'picture');
|
|
482
|
-
return child
|
|
482
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
483
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
483
484
|
};
|
|
484
485
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
485
486
|
const me = authState.creds.me;
|
|
@@ -498,7 +499,7 @@ export const makeChatsSocket = (config) => {
|
|
|
498
499
|
});
|
|
499
500
|
}
|
|
500
501
|
else {
|
|
501
|
-
const { server } = jidDecode(toJid);
|
|
502
|
+
const { server } = (0, WABinary_1.jidDecode)(toJid);
|
|
502
503
|
const isLid = server === 'lid';
|
|
503
504
|
await sendNode({
|
|
504
505
|
tag: 'chatstate',
|
|
@@ -537,6 +538,7 @@ export const makeChatsSocket = (config) => {
|
|
|
537
538
|
: undefined
|
|
538
539
|
});
|
|
539
540
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
541
|
+
var _a;
|
|
540
542
|
let presence;
|
|
541
543
|
const jid = attrs.from;
|
|
542
544
|
const participant = attrs.participant || attrs.from;
|
|
@@ -555,7 +557,7 @@ export const makeChatsSocket = (config) => {
|
|
|
555
557
|
if (type === 'paused') {
|
|
556
558
|
type = 'available';
|
|
557
559
|
}
|
|
558
|
-
if (firstChild.attrs
|
|
560
|
+
if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
|
|
559
561
|
type = 'recording';
|
|
560
562
|
}
|
|
561
563
|
presence = { lastKnownPresence: type };
|
|
@@ -571,7 +573,7 @@ export const makeChatsSocket = (config) => {
|
|
|
571
573
|
const name = patchCreate.type;
|
|
572
574
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
573
575
|
if (!myAppStateKeyId) {
|
|
574
|
-
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
576
|
+
throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
|
|
575
577
|
}
|
|
576
578
|
let initial;
|
|
577
579
|
let encodeResult;
|
|
@@ -580,13 +582,13 @@ export const makeChatsSocket = (config) => {
|
|
|
580
582
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
581
583
|
await resyncAppState([name], false);
|
|
582
584
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
583
|
-
initial = currentSyncVersion || newLTHashState();
|
|
584
|
-
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
585
|
+
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
586
|
+
encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
585
587
|
const { patch, state } = encodeResult;
|
|
586
588
|
const node = {
|
|
587
589
|
tag: 'iq',
|
|
588
590
|
attrs: {
|
|
589
|
-
to: S_WHATSAPP_NET,
|
|
591
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
590
592
|
type: 'set',
|
|
591
593
|
xmlns: 'w:sync:app:state'
|
|
592
594
|
},
|
|
@@ -606,7 +608,7 @@ export const makeChatsSocket = (config) => {
|
|
|
606
608
|
{
|
|
607
609
|
tag: 'patch',
|
|
608
610
|
attrs: {},
|
|
609
|
-
content: proto.SyncdPatch.encode(patch).finish()
|
|
611
|
+
content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
|
|
610
612
|
}
|
|
611
613
|
]
|
|
612
614
|
}
|
|
@@ -620,7 +622,7 @@ export const makeChatsSocket = (config) => {
|
|
|
620
622
|
});
|
|
621
623
|
if (config.emitOwnEvents) {
|
|
622
624
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
623
|
-
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
625
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
624
626
|
for (const key in mutationMap) {
|
|
625
627
|
onMutation(mutationMap[key]);
|
|
626
628
|
}
|
|
@@ -628,10 +630,11 @@ export const makeChatsSocket = (config) => {
|
|
|
628
630
|
};
|
|
629
631
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
630
632
|
const fetchProps = async () => {
|
|
633
|
+
var _a, _b, _c;
|
|
631
634
|
const resultNode = await query({
|
|
632
635
|
tag: 'iq',
|
|
633
636
|
attrs: {
|
|
634
|
-
to: S_WHATSAPP_NET,
|
|
637
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
635
638
|
xmlns: 'w',
|
|
636
639
|
type: 'get'
|
|
637
640
|
},
|
|
@@ -640,20 +643,20 @@ export const makeChatsSocket = (config) => {
|
|
|
640
643
|
tag: 'props',
|
|
641
644
|
attrs: {
|
|
642
645
|
protocol: '2',
|
|
643
|
-
hash: authState
|
|
646
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
644
647
|
}
|
|
645
648
|
}
|
|
646
649
|
]
|
|
647
650
|
});
|
|
648
|
-
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
651
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
649
652
|
let props = {};
|
|
650
653
|
if (propsNode) {
|
|
651
|
-
if (propsNode.attrs
|
|
654
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
652
655
|
// on some clients, the hash is returning as undefined
|
|
653
|
-
authState.creds.lastPropHash = propsNode
|
|
656
|
+
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
654
657
|
ev.emit('creds.update', authState.creds);
|
|
655
658
|
}
|
|
656
|
-
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
659
|
+
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
657
660
|
}
|
|
658
661
|
logger.debug('fetched props');
|
|
659
662
|
return props;
|
|
@@ -664,17 +667,9 @@ export const makeChatsSocket = (config) => {
|
|
|
664
667
|
* requires the last messages till the last message received; required for archive & unread
|
|
665
668
|
*/
|
|
666
669
|
const chatModify = (mod, jid) => {
|
|
667
|
-
const patch = chatModificationToAppPatch(mod, jid);
|
|
670
|
+
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
668
671
|
return appPatch(patch);
|
|
669
672
|
};
|
|
670
|
-
/**
|
|
671
|
-
* Enable/Disable link preview privacy, not related to baileys link preview generation
|
|
672
|
-
*/
|
|
673
|
-
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
674
|
-
return chatModify({
|
|
675
|
-
disableLinkPreviews: { isPreviewsDisabled }
|
|
676
|
-
}, '');
|
|
677
|
-
};
|
|
678
673
|
/**
|
|
679
674
|
* Star or Unstar a message
|
|
680
675
|
*/
|
|
@@ -762,58 +757,35 @@ export const makeChatsSocket = (config) => {
|
|
|
762
757
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
763
758
|
};
|
|
764
759
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
760
|
+
var _a, _b, _c;
|
|
765
761
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
766
762
|
if (!!msg.pushName) {
|
|
767
763
|
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
768
|
-
jid = jidNormalizedUser(jid);
|
|
764
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
769
765
|
if (!msg.key.fromMe) {
|
|
770
766
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
771
767
|
}
|
|
772
768
|
// update our pushname too
|
|
773
|
-
if (msg.key.fromMe && msg.pushName && authState.creds.me
|
|
769
|
+
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
774
770
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
775
771
|
}
|
|
776
772
|
}
|
|
777
|
-
const historyMsg = getHistoryMsg(msg.message);
|
|
773
|
+
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
778
774
|
const shouldProcessHistoryMsg = historyMsg
|
|
779
|
-
? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
775
|
+
? shouldSyncHistoryMessage(historyMsg) && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
780
776
|
: false;
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
clearTimeout(awaitingSyncTimeout);
|
|
785
|
-
awaitingSyncTimeout = undefined;
|
|
786
|
-
}
|
|
787
|
-
if (shouldProcessHistoryMsg) {
|
|
788
|
-
syncState = SyncState.Syncing;
|
|
789
|
-
logger.info('Transitioned to Syncing state');
|
|
790
|
-
// Let doAppStateSync handle the final flush after it's done
|
|
791
|
-
}
|
|
792
|
-
else {
|
|
793
|
-
syncState = SyncState.Online;
|
|
794
|
-
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
795
|
-
ev.flush();
|
|
796
|
-
}
|
|
777
|
+
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
778
|
+
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
779
|
+
pendingAppStateSync = true;
|
|
797
780
|
}
|
|
798
|
-
const doAppStateSync = async () => {
|
|
799
|
-
if (syncState === SyncState.Syncing) {
|
|
800
|
-
logger.info('Doing app state sync');
|
|
801
|
-
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
802
|
-
// Sync is complete, go online and flush everything
|
|
803
|
-
syncState = SyncState.Online;
|
|
804
|
-
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
805
|
-
ev.flush();
|
|
806
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
807
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
781
|
await Promise.all([
|
|
811
782
|
(async () => {
|
|
812
|
-
if (
|
|
783
|
+
if (historyMsg && authState.creds.myAppStateKeyId) {
|
|
784
|
+
pendingAppStateSync = false;
|
|
813
785
|
await doAppStateSync();
|
|
814
786
|
}
|
|
815
787
|
})(),
|
|
816
|
-
|
|
788
|
+
(0, process_message_1.default)(msg, {
|
|
817
789
|
shouldProcessHistoryMsg,
|
|
818
790
|
placeholderResendCache,
|
|
819
791
|
ev,
|
|
@@ -823,16 +795,27 @@ export const makeChatsSocket = (config) => {
|
|
|
823
795
|
options: config.options
|
|
824
796
|
})
|
|
825
797
|
]);
|
|
826
|
-
|
|
827
|
-
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
|
|
828
|
-
logger.info('App state sync key arrived, triggering app state sync');
|
|
798
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) && pendingAppStateSync) {
|
|
829
799
|
await doAppStateSync();
|
|
800
|
+
pendingAppStateSync = false;
|
|
801
|
+
}
|
|
802
|
+
async function doAppStateSync() {
|
|
803
|
+
if (!authState.creds.accountSyncCounter) {
|
|
804
|
+
logger.info('doing initial app state sync');
|
|
805
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
806
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
807
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
808
|
+
if (needToFlushWithAppStateSync) {
|
|
809
|
+
logger.debug('flushing with app state sync');
|
|
810
|
+
ev.flush();
|
|
811
|
+
}
|
|
812
|
+
}
|
|
830
813
|
}
|
|
831
814
|
});
|
|
832
815
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
833
816
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
834
817
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
835
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
818
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
836
819
|
const type = attrs.type;
|
|
837
820
|
switch (type) {
|
|
838
821
|
case 'account_sync':
|
|
@@ -854,38 +837,21 @@ export const makeChatsSocket = (config) => {
|
|
|
854
837
|
}
|
|
855
838
|
});
|
|
856
839
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
840
|
+
var _a;
|
|
857
841
|
if (connection === 'open') {
|
|
858
842
|
if (fireInitQueries) {
|
|
859
843
|
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
860
844
|
}
|
|
861
845
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
862
846
|
}
|
|
863
|
-
if (
|
|
864
|
-
|
|
847
|
+
if (receivedPendingNotifications && // if we don't have the app state key
|
|
848
|
+
// we keep buffering events until we finally have
|
|
849
|
+
// the key and can sync the messages
|
|
850
|
+
// todo scrutinize
|
|
851
|
+
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
852
|
+
ev.buffer();
|
|
853
|
+
needToFlushWithAppStateSync = true;
|
|
865
854
|
}
|
|
866
|
-
syncState = SyncState.AwaitingInitialSync;
|
|
867
|
-
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
868
|
-
ev.buffer();
|
|
869
|
-
const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.fromObject({
|
|
870
|
-
syncType: proto.HistorySync.HistorySyncType.RECENT
|
|
871
|
-
}));
|
|
872
|
-
if (!willSyncHistory) {
|
|
873
|
-
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
874
|
-
syncState = SyncState.Online;
|
|
875
|
-
setTimeout(() => ev.flush(), 0);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
879
|
-
if (awaitingSyncTimeout) {
|
|
880
|
-
clearTimeout(awaitingSyncTimeout);
|
|
881
|
-
}
|
|
882
|
-
awaitingSyncTimeout = setTimeout(() => {
|
|
883
|
-
if (syncState === SyncState.AwaitingInitialSync) {
|
|
884
|
-
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
885
|
-
syncState = SyncState.Online;
|
|
886
|
-
ev.flush();
|
|
887
|
-
}
|
|
888
|
-
}, 20000);
|
|
889
855
|
});
|
|
890
856
|
return {
|
|
891
857
|
...sock,
|
|
@@ -906,7 +872,6 @@ export const makeChatsSocket = (config) => {
|
|
|
906
872
|
updateProfileStatus,
|
|
907
873
|
updateProfileName,
|
|
908
874
|
updateBlockStatus,
|
|
909
|
-
updateDisableLinkPreviewsPrivacy,
|
|
910
875
|
updateCallPrivacy,
|
|
911
876
|
updateMessagesPrivacy,
|
|
912
877
|
updateLastSeenPrivacy,
|
|
@@ -930,4 +895,4 @@ export const makeChatsSocket = (config) => {
|
|
|
930
895
|
star
|
|
931
896
|
};
|
|
932
897
|
};
|
|
933
|
-
|
|
898
|
+
exports.makeChatsSocket = makeChatsSocket;
|