@d0v3riz/baileys 6.7.19 → 6.7.21
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 +1263 -4
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +50 -54
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +18 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/queue-job.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +3 -2
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -1
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +15 -27
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +92 -62
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +31 -24
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +251 -198
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +219 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +47 -39
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +91 -82
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +128 -68
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +16 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +79 -49
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +364 -200
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +76 -46
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +144 -120
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +143 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +179 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +15 -14
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +153 -141
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +17 -16
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +19 -26
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +5 -4
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +14 -8
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +38 -11
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +10 -4
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +1 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +21 -9
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +2 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +11 -10
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +15 -13
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -30
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +3 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +30 -40
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +64 -75
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +195 -194
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +40 -95
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +7 -7
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +43 -41
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +6 -6
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +42 -59
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +11 -9
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +105 -130
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +4 -3
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +18 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +18 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -3
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +6 -10
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +20 -11
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +215 -253
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +9 -8
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +259 -228
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +22 -26
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/process-message.d.ts +6 -5
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +109 -123
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +5 -4
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +52 -55
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +64 -75
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +5 -4
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1280 -19
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +7 -43
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +21 -38
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +15 -19
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +4 -3
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -30
- package/lib/index.js.map +1 -0
- package/package.json +36 -31
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
package/lib/Socket/chats.js
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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");
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
|
|
5
|
+
import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
|
|
6
|
+
import { SyncState } from '../Types/State.js';
|
|
7
|
+
import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
|
|
8
|
+
import { makeMutex } from '../Utils/make-mutex.js';
|
|
9
|
+
import processMessage from '../Utils/process-message.js';
|
|
10
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
|
+
import { makeUSyncSocket } from './usync.js';
|
|
18
13
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
|
-
const makeChatsSocket = (config) => {
|
|
20
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage
|
|
21
|
-
const sock =
|
|
22
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError
|
|
14
|
+
export const makeChatsSocket = (config) => {
|
|
15
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
16
|
+
const sock = makeUSyncSocket(config);
|
|
17
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
23
18
|
let privacySettings;
|
|
24
|
-
let
|
|
25
|
-
let pendingAppStateSync = false;
|
|
19
|
+
let syncState = SyncState.Connecting;
|
|
26
20
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
|
-
const processingMutex =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
const processingMutex = makeMutex();
|
|
22
|
+
// Timeout for AwaitingInitialSync state
|
|
23
|
+
let awaitingSyncTimeout;
|
|
24
|
+
const placeholderResendCache = config.placeholderResendCache ||
|
|
25
|
+
new NodeCache({
|
|
26
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
27
|
+
useClones: false
|
|
28
|
+
});
|
|
32
29
|
if (!config.placeholderResendCache) {
|
|
33
30
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
31
|
}
|
|
@@ -43,14 +40,12 @@ const makeChatsSocket = (config) => {
|
|
|
43
40
|
tag: 'iq',
|
|
44
41
|
attrs: {
|
|
45
42
|
xmlns: 'privacy',
|
|
46
|
-
to:
|
|
43
|
+
to: S_WHATSAPP_NET,
|
|
47
44
|
type: 'get'
|
|
48
45
|
},
|
|
49
|
-
content: [
|
|
50
|
-
{ tag: 'privacy', attrs: {} }
|
|
51
|
-
]
|
|
46
|
+
content: [{ tag: 'privacy', attrs: {} }]
|
|
52
47
|
});
|
|
53
|
-
privacySettings =
|
|
48
|
+
privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
|
|
54
49
|
}
|
|
55
50
|
return privacySettings;
|
|
56
51
|
};
|
|
@@ -60,10 +55,11 @@ const makeChatsSocket = (config) => {
|
|
|
60
55
|
tag: 'iq',
|
|
61
56
|
attrs: {
|
|
62
57
|
xmlns: 'privacy',
|
|
63
|
-
to:
|
|
58
|
+
to: S_WHATSAPP_NET,
|
|
64
59
|
type: 'set'
|
|
65
60
|
},
|
|
66
|
-
content: [
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
67
63
|
tag: 'privacy',
|
|
68
64
|
attrs: {},
|
|
69
65
|
content: [
|
|
@@ -72,7 +68,8 @@ const makeChatsSocket = (config) => {
|
|
|
72
68
|
attrs: { name, value }
|
|
73
69
|
}
|
|
74
70
|
]
|
|
75
|
-
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
76
73
|
});
|
|
77
74
|
};
|
|
78
75
|
const updateMessagesPrivacy = async (value) => {
|
|
@@ -104,15 +101,17 @@ const makeChatsSocket = (config) => {
|
|
|
104
101
|
tag: 'iq',
|
|
105
102
|
attrs: {
|
|
106
103
|
xmlns: 'disappearing_mode',
|
|
107
|
-
to:
|
|
104
|
+
to: S_WHATSAPP_NET,
|
|
108
105
|
type: 'set'
|
|
109
106
|
},
|
|
110
|
-
content: [
|
|
107
|
+
content: [
|
|
108
|
+
{
|
|
111
109
|
tag: 'disappearing_mode',
|
|
112
110
|
attrs: {
|
|
113
111
|
duration: duration.toString()
|
|
114
112
|
}
|
|
115
|
-
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
116
115
|
});
|
|
117
116
|
};
|
|
118
117
|
const getBotListV2 = async () => {
|
|
@@ -120,21 +119,23 @@ const makeChatsSocket = (config) => {
|
|
|
120
119
|
tag: 'iq',
|
|
121
120
|
attrs: {
|
|
122
121
|
xmlns: 'bot',
|
|
123
|
-
to:
|
|
122
|
+
to: S_WHATSAPP_NET,
|
|
124
123
|
type: 'get'
|
|
125
124
|
},
|
|
126
|
-
content: [
|
|
125
|
+
content: [
|
|
126
|
+
{
|
|
127
127
|
tag: 'bot',
|
|
128
128
|
attrs: {
|
|
129
129
|
v: '2'
|
|
130
130
|
}
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
132
133
|
});
|
|
133
|
-
const botNode =
|
|
134
|
+
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
134
135
|
const botList = [];
|
|
135
|
-
for (const section of
|
|
136
|
+
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
136
137
|
if (section.attrs.type === 'all') {
|
|
137
|
-
for (const bot of
|
|
138
|
+
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
138
139
|
botList.push({
|
|
139
140
|
jid: bot.attrs.jid,
|
|
140
141
|
personaId: bot.attrs['persona_id']
|
|
@@ -145,23 +146,20 @@ const makeChatsSocket = (config) => {
|
|
|
145
146
|
return botList;
|
|
146
147
|
};
|
|
147
148
|
const onWhatsApp = async (...jids) => {
|
|
148
|
-
const usyncQuery = new
|
|
149
|
-
.withContactProtocol()
|
|
150
|
-
.withLIDProtocol();
|
|
149
|
+
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
|
|
151
150
|
for (const jid of jids) {
|
|
152
|
-
const phone = `+${jid.replace('+', '').split('@')[0]
|
|
153
|
-
usyncQuery.withUser(new
|
|
151
|
+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
152
|
+
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
154
153
|
}
|
|
155
154
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
156
155
|
if (results) {
|
|
157
|
-
return results.list.filter(
|
|
156
|
+
return results.list.filter(a => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
158
157
|
}
|
|
159
158
|
};
|
|
160
159
|
const fetchStatus = async (...jids) => {
|
|
161
|
-
const usyncQuery = new
|
|
162
|
-
.withStatusProtocol();
|
|
160
|
+
const usyncQuery = new USyncQuery().withStatusProtocol();
|
|
163
161
|
for (const jid of jids) {
|
|
164
|
-
usyncQuery.withUser(new
|
|
162
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
165
163
|
}
|
|
166
164
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
167
165
|
if (result) {
|
|
@@ -169,10 +167,9 @@ const makeChatsSocket = (config) => {
|
|
|
169
167
|
}
|
|
170
168
|
};
|
|
171
169
|
const fetchDisappearingDuration = async (...jids) => {
|
|
172
|
-
const usyncQuery = new
|
|
173
|
-
.withDisappearingModeProtocol();
|
|
170
|
+
const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
|
|
174
171
|
for (const jid of jids) {
|
|
175
|
-
usyncQuery.withUser(new
|
|
172
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
176
173
|
}
|
|
177
174
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
178
175
|
if (result) {
|
|
@@ -180,22 +177,25 @@ const makeChatsSocket = (config) => {
|
|
|
180
177
|
}
|
|
181
178
|
};
|
|
182
179
|
/** update the profile picture for yourself or a group */
|
|
183
|
-
const updateProfilePicture = async (jid, content) => {
|
|
180
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
184
181
|
let targetJid;
|
|
185
182
|
if (!jid) {
|
|
186
|
-
throw new
|
|
183
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
187
184
|
}
|
|
188
|
-
if (
|
|
189
|
-
targetJid =
|
|
185
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
186
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
targetJid = undefined;
|
|
190
190
|
}
|
|
191
|
-
const { img } = await (
|
|
191
|
+
const { img } = await generateProfilePicture(content, dimensions);
|
|
192
192
|
await query({
|
|
193
193
|
tag: 'iq',
|
|
194
194
|
attrs: {
|
|
195
|
-
|
|
196
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
195
|
+
to: S_WHATSAPP_NET,
|
|
197
196
|
type: 'set',
|
|
198
|
-
xmlns: 'w:profile:picture'
|
|
197
|
+
xmlns: 'w:profile:picture',
|
|
198
|
+
...(targetJid ? { target: targetJid } : {})
|
|
199
199
|
},
|
|
200
200
|
content: [
|
|
201
201
|
{
|
|
@@ -210,18 +210,21 @@ const makeChatsSocket = (config) => {
|
|
|
210
210
|
const removeProfilePicture = async (jid) => {
|
|
211
211
|
let targetJid;
|
|
212
212
|
if (!jid) {
|
|
213
|
-
throw new
|
|
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
|
+
}
|
|
215
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
216
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
214
217
|
}
|
|
215
|
-
|
|
216
|
-
targetJid =
|
|
218
|
+
else {
|
|
219
|
+
targetJid = undefined;
|
|
217
220
|
}
|
|
218
221
|
await query({
|
|
219
222
|
tag: 'iq',
|
|
220
223
|
attrs: {
|
|
221
|
-
|
|
222
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
224
|
+
to: S_WHATSAPP_NET,
|
|
223
225
|
type: 'set',
|
|
224
|
-
xmlns: 'w:profile:picture'
|
|
226
|
+
xmlns: 'w:profile:picture',
|
|
227
|
+
...(targetJid ? { target: targetJid } : {})
|
|
225
228
|
}
|
|
226
229
|
});
|
|
227
230
|
};
|
|
@@ -230,7 +233,7 @@ const makeChatsSocket = (config) => {
|
|
|
230
233
|
await query({
|
|
231
234
|
tag: 'iq',
|
|
232
235
|
attrs: {
|
|
233
|
-
to:
|
|
236
|
+
to: S_WHATSAPP_NET,
|
|
234
237
|
type: 'set',
|
|
235
238
|
xmlns: 'status'
|
|
236
239
|
},
|
|
@@ -251,20 +254,19 @@ const makeChatsSocket = (config) => {
|
|
|
251
254
|
tag: 'iq',
|
|
252
255
|
attrs: {
|
|
253
256
|
xmlns: 'blocklist',
|
|
254
|
-
to:
|
|
257
|
+
to: S_WHATSAPP_NET,
|
|
255
258
|
type: 'get'
|
|
256
259
|
}
|
|
257
260
|
});
|
|
258
|
-
const listNode =
|
|
259
|
-
return
|
|
260
|
-
.map(n => n.attrs.jid);
|
|
261
|
+
const listNode = getBinaryNodeChild(result, 'list');
|
|
262
|
+
return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
|
|
261
263
|
};
|
|
262
264
|
const updateBlockStatus = async (jid, action) => {
|
|
263
265
|
await query({
|
|
264
266
|
tag: 'iq',
|
|
265
267
|
attrs: {
|
|
266
268
|
xmlns: 'blocklist',
|
|
267
|
-
to:
|
|
269
|
+
to: S_WHATSAPP_NET,
|
|
268
270
|
type: 'set'
|
|
269
271
|
},
|
|
270
272
|
content: [
|
|
@@ -279,7 +281,6 @@ const makeChatsSocket = (config) => {
|
|
|
279
281
|
});
|
|
280
282
|
};
|
|
281
283
|
const getBusinessProfile = async (jid) => {
|
|
282
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
283
284
|
const results = await query({
|
|
284
285
|
tag: 'iq',
|
|
285
286
|
attrs: {
|
|
@@ -287,38 +288,42 @@ const makeChatsSocket = (config) => {
|
|
|
287
288
|
xmlns: 'w:biz',
|
|
288
289
|
type: 'get'
|
|
289
290
|
},
|
|
290
|
-
content: [
|
|
291
|
+
content: [
|
|
292
|
+
{
|
|
291
293
|
tag: 'business_profile',
|
|
292
294
|
attrs: { v: '244' },
|
|
293
|
-
content: [
|
|
295
|
+
content: [
|
|
296
|
+
{
|
|
294
297
|
tag: 'profile',
|
|
295
298
|
attrs: { jid }
|
|
296
|
-
}
|
|
297
|
-
|
|
299
|
+
}
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
]
|
|
298
303
|
});
|
|
299
|
-
const profileNode =
|
|
300
|
-
const profiles =
|
|
304
|
+
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
305
|
+
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
301
306
|
if (profiles) {
|
|
302
|
-
const address =
|
|
303
|
-
const description =
|
|
304
|
-
const website =
|
|
305
|
-
const email =
|
|
306
|
-
const category =
|
|
307
|
-
const businessHours =
|
|
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');
|
|
308
313
|
const businessHoursConfig = businessHours
|
|
309
|
-
?
|
|
314
|
+
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
310
315
|
: undefined;
|
|
311
|
-
const websiteStr =
|
|
316
|
+
const websiteStr = website?.content?.toString();
|
|
312
317
|
return {
|
|
313
|
-
wid:
|
|
314
|
-
address:
|
|
315
|
-
description:
|
|
318
|
+
wid: profiles.attrs?.jid,
|
|
319
|
+
address: address?.content?.toString(),
|
|
320
|
+
description: description?.content?.toString() || '',
|
|
316
321
|
website: websiteStr ? [websiteStr] : [],
|
|
317
|
-
email:
|
|
318
|
-
category:
|
|
319
|
-
|
|
320
|
-
timezone:
|
|
321
|
-
|
|
322
|
+
email: email?.content?.toString(),
|
|
323
|
+
category: category?.content?.toString(),
|
|
324
|
+
business_hours: {
|
|
325
|
+
timezone: businessHours?.attrs?.timezone,
|
|
326
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
322
327
|
}
|
|
323
328
|
};
|
|
324
329
|
}
|
|
@@ -328,17 +333,17 @@ const makeChatsSocket = (config) => {
|
|
|
328
333
|
await sendNode({
|
|
329
334
|
tag: 'iq',
|
|
330
335
|
attrs: {
|
|
331
|
-
to:
|
|
336
|
+
to: S_WHATSAPP_NET,
|
|
332
337
|
type: 'set',
|
|
333
338
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
334
|
-
id: generateMessageTag()
|
|
339
|
+
id: generateMessageTag()
|
|
335
340
|
},
|
|
336
341
|
content: [
|
|
337
342
|
{
|
|
338
343
|
tag: 'clean',
|
|
339
344
|
attrs: {
|
|
340
345
|
type,
|
|
341
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
346
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
]
|
|
@@ -347,7 +352,7 @@ const makeChatsSocket = (config) => {
|
|
|
347
352
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
348
353
|
return {
|
|
349
354
|
onMutation(mutation) {
|
|
350
|
-
|
|
355
|
+
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
351
356
|
}
|
|
352
357
|
};
|
|
353
358
|
};
|
|
@@ -357,7 +362,6 @@ const makeChatsSocket = (config) => {
|
|
|
357
362
|
const initialVersionMap = {};
|
|
358
363
|
const globalMutationMap = {};
|
|
359
364
|
await authState.keys.transaction(async () => {
|
|
360
|
-
var _a;
|
|
361
365
|
const collectionsToHandle = new Set(collections);
|
|
362
366
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
363
367
|
const attemptsMap = {};
|
|
@@ -376,7 +380,7 @@ const makeChatsSocket = (config) => {
|
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
382
|
else {
|
|
379
|
-
state =
|
|
383
|
+
state = newLTHashState();
|
|
380
384
|
}
|
|
381
385
|
states[name] = state;
|
|
382
386
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -386,14 +390,14 @@ const makeChatsSocket = (config) => {
|
|
|
386
390
|
name,
|
|
387
391
|
version: state.version.toString(),
|
|
388
392
|
// return snapshot if being synced from scratch
|
|
389
|
-
|
|
393
|
+
return_snapshot: (!state.version).toString()
|
|
390
394
|
}
|
|
391
395
|
});
|
|
392
396
|
}
|
|
393
397
|
const result = await query({
|
|
394
398
|
tag: 'iq',
|
|
395
399
|
attrs: {
|
|
396
|
-
to:
|
|
400
|
+
to: S_WHATSAPP_NET,
|
|
397
401
|
xmlns: 'w:sync:app:state',
|
|
398
402
|
type: 'set'
|
|
399
403
|
},
|
|
@@ -406,13 +410,13 @@ const makeChatsSocket = (config) => {
|
|
|
406
410
|
]
|
|
407
411
|
});
|
|
408
412
|
// extract from binary node
|
|
409
|
-
const decoded = await
|
|
413
|
+
const decoded = await extractSyncdPatches(result, config?.options);
|
|
410
414
|
for (const key in decoded) {
|
|
411
415
|
const name = key;
|
|
412
416
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
413
417
|
try {
|
|
414
418
|
if (snapshot) {
|
|
415
|
-
const { state: newState, mutationMap } = await
|
|
419
|
+
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
416
420
|
states[name] = newState;
|
|
417
421
|
Object.assign(globalMutationMap, mutationMap);
|
|
418
422
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
@@ -420,7 +424,7 @@ const makeChatsSocket = (config) => {
|
|
|
420
424
|
}
|
|
421
425
|
// only process if there are syncd patches
|
|
422
426
|
if (patches.length) {
|
|
423
|
-
const { state: newState, mutationMap } = await
|
|
427
|
+
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
424
428
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
425
429
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
426
430
|
initialVersionMap[name] = newState.version;
|
|
@@ -429,16 +433,17 @@ const makeChatsSocket = (config) => {
|
|
|
429
433
|
if (hasMorePatches) {
|
|
430
434
|
logger.info(`${name} has more patches...`);
|
|
431
435
|
}
|
|
432
|
-
else {
|
|
436
|
+
else {
|
|
437
|
+
// collection is done with sync
|
|
433
438
|
collectionsToHandle.delete(name);
|
|
434
439
|
}
|
|
435
440
|
}
|
|
436
441
|
catch (error) {
|
|
437
442
|
// if retry attempts overshoot
|
|
438
443
|
// or key not found
|
|
439
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
445
|
+
error.output?.statusCode === 404 ||
|
|
446
|
+
error.name === 'TypeError';
|
|
442
447
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
443
448
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
444
449
|
// increment number of retries
|
|
@@ -462,22 +467,19 @@ const makeChatsSocket = (config) => {
|
|
|
462
467
|
* type = "image for the high res picture"
|
|
463
468
|
*/
|
|
464
469
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
465
|
-
|
|
466
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
470
|
+
jid = jidNormalizedUser(jid);
|
|
467
471
|
const result = await query({
|
|
468
472
|
tag: 'iq',
|
|
469
473
|
attrs: {
|
|
470
474
|
target: jid,
|
|
471
|
-
to:
|
|
475
|
+
to: S_WHATSAPP_NET,
|
|
472
476
|
type: 'get',
|
|
473
477
|
xmlns: 'w:profile:picture'
|
|
474
478
|
},
|
|
475
|
-
content: [
|
|
476
|
-
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
477
|
-
]
|
|
479
|
+
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
478
480
|
}, timeoutMs);
|
|
479
|
-
const child =
|
|
480
|
-
return
|
|
481
|
+
const child = getBinaryNodeChild(result, 'picture');
|
|
482
|
+
return child?.attrs?.url;
|
|
481
483
|
};
|
|
482
484
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
483
485
|
const me = authState.creds.me;
|
|
@@ -490,17 +492,19 @@ const makeChatsSocket = (config) => {
|
|
|
490
492
|
await sendNode({
|
|
491
493
|
tag: 'presence',
|
|
492
494
|
attrs: {
|
|
493
|
-
name: me.name,
|
|
495
|
+
name: me.name.replace(/@/g, ''),
|
|
494
496
|
type
|
|
495
497
|
}
|
|
496
498
|
});
|
|
497
499
|
}
|
|
498
500
|
else {
|
|
501
|
+
const { server } = jidDecode(toJid);
|
|
502
|
+
const isLid = server === 'lid';
|
|
499
503
|
await sendNode({
|
|
500
504
|
tag: 'chatstate',
|
|
501
505
|
attrs: {
|
|
502
|
-
from: me.id,
|
|
503
|
-
to: toJid
|
|
506
|
+
from: isLid ? me.lid : me.id,
|
|
507
|
+
to: toJid
|
|
504
508
|
},
|
|
505
509
|
content: [
|
|
506
510
|
{
|
|
@@ -515,7 +519,7 @@ const makeChatsSocket = (config) => {
|
|
|
515
519
|
* @param toJid the jid to subscribe to
|
|
516
520
|
* @param tcToken token for subscription, use if present
|
|
517
521
|
*/
|
|
518
|
-
const presenceSubscribe = (toJid, tcToken) =>
|
|
522
|
+
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
519
523
|
tag: 'presence',
|
|
520
524
|
attrs: {
|
|
521
525
|
to: toJid,
|
|
@@ -531,9 +535,8 @@ const makeChatsSocket = (config) => {
|
|
|
531
535
|
}
|
|
532
536
|
]
|
|
533
537
|
: undefined
|
|
534
|
-
})
|
|
538
|
+
});
|
|
535
539
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
536
|
-
var _a;
|
|
537
540
|
let presence;
|
|
538
541
|
const jid = attrs.from;
|
|
539
542
|
const participant = attrs.participant || attrs.from;
|
|
@@ -552,7 +555,7 @@ const makeChatsSocket = (config) => {
|
|
|
552
555
|
if (type === 'paused') {
|
|
553
556
|
type = 'available';
|
|
554
557
|
}
|
|
555
|
-
if (
|
|
558
|
+
if (firstChild.attrs?.media === 'audio') {
|
|
556
559
|
type = 'recording';
|
|
557
560
|
}
|
|
558
561
|
presence = { lastKnownPresence: type };
|
|
@@ -568,7 +571,7 @@ const makeChatsSocket = (config) => {
|
|
|
568
571
|
const name = patchCreate.type;
|
|
569
572
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
570
573
|
if (!myAppStateKeyId) {
|
|
571
|
-
throw new
|
|
574
|
+
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
572
575
|
}
|
|
573
576
|
let initial;
|
|
574
577
|
let encodeResult;
|
|
@@ -577,13 +580,13 @@ const makeChatsSocket = (config) => {
|
|
|
577
580
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
578
581
|
await resyncAppState([name], false);
|
|
579
582
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
580
|
-
initial = currentSyncVersion ||
|
|
581
|
-
encodeResult = await
|
|
583
|
+
initial = currentSyncVersion || newLTHashState();
|
|
584
|
+
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
582
585
|
const { patch, state } = encodeResult;
|
|
583
586
|
const node = {
|
|
584
587
|
tag: 'iq',
|
|
585
588
|
attrs: {
|
|
586
|
-
to:
|
|
589
|
+
to: S_WHATSAPP_NET,
|
|
587
590
|
type: 'set',
|
|
588
591
|
xmlns: 'w:sync:app:state'
|
|
589
592
|
},
|
|
@@ -597,13 +600,13 @@ const makeChatsSocket = (config) => {
|
|
|
597
600
|
attrs: {
|
|
598
601
|
name,
|
|
599
602
|
version: (state.version - 1).toString(),
|
|
600
|
-
|
|
603
|
+
return_snapshot: 'false'
|
|
601
604
|
},
|
|
602
605
|
content: [
|
|
603
606
|
{
|
|
604
607
|
tag: 'patch',
|
|
605
608
|
attrs: {},
|
|
606
|
-
content:
|
|
609
|
+
content: proto.SyncdPatch.encode(patch).finish()
|
|
607
610
|
}
|
|
608
611
|
]
|
|
609
612
|
}
|
|
@@ -617,7 +620,7 @@ const makeChatsSocket = (config) => {
|
|
|
617
620
|
});
|
|
618
621
|
if (config.emitOwnEvents) {
|
|
619
622
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
620
|
-
const { mutationMap } = await
|
|
623
|
+
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
621
624
|
for (const key in mutationMap) {
|
|
622
625
|
onMutation(mutationMap[key]);
|
|
623
626
|
}
|
|
@@ -625,29 +628,32 @@ const makeChatsSocket = (config) => {
|
|
|
625
628
|
};
|
|
626
629
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
627
630
|
const fetchProps = async () => {
|
|
628
|
-
var _a, _b, _c;
|
|
629
631
|
const resultNode = await query({
|
|
630
632
|
tag: 'iq',
|
|
631
633
|
attrs: {
|
|
632
|
-
to:
|
|
634
|
+
to: S_WHATSAPP_NET,
|
|
633
635
|
xmlns: 'w',
|
|
634
|
-
type: 'get'
|
|
636
|
+
type: 'get'
|
|
635
637
|
},
|
|
636
638
|
content: [
|
|
637
|
-
{
|
|
639
|
+
{
|
|
640
|
+
tag: 'props',
|
|
641
|
+
attrs: {
|
|
638
642
|
protocol: '2',
|
|
639
|
-
hash:
|
|
640
|
-
}
|
|
643
|
+
hash: authState?.creds?.lastPropHash || ''
|
|
644
|
+
}
|
|
645
|
+
}
|
|
641
646
|
]
|
|
642
647
|
});
|
|
643
|
-
const propsNode =
|
|
648
|
+
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
644
649
|
let props = {};
|
|
645
650
|
if (propsNode) {
|
|
646
|
-
if (
|
|
647
|
-
|
|
651
|
+
if (propsNode.attrs?.hash) {
|
|
652
|
+
// on some clients, the hash is returning as undefined
|
|
653
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
648
654
|
ev.emit('creds.update', authState.creds);
|
|
649
655
|
}
|
|
650
|
-
props =
|
|
656
|
+
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
651
657
|
}
|
|
652
658
|
logger.debug('fetched props');
|
|
653
659
|
return props;
|
|
@@ -656,11 +662,19 @@ const makeChatsSocket = (config) => {
|
|
|
656
662
|
* modify a chat -- mark unread, read etc.
|
|
657
663
|
* lastMessages must be sorted in reverse chronologically
|
|
658
664
|
* requires the last messages till the last message received; required for archive & unread
|
|
659
|
-
|
|
665
|
+
*/
|
|
660
666
|
const chatModify = (mod, jid) => {
|
|
661
|
-
const patch =
|
|
667
|
+
const patch = chatModificationToAppPatch(mod, jid);
|
|
662
668
|
return appPatch(patch);
|
|
663
669
|
};
|
|
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
|
+
};
|
|
664
678
|
/**
|
|
665
679
|
* Star or Unstar a message
|
|
666
680
|
*/
|
|
@@ -672,6 +686,22 @@ const makeChatsSocket = (config) => {
|
|
|
672
686
|
}
|
|
673
687
|
}, jid);
|
|
674
688
|
};
|
|
689
|
+
/**
|
|
690
|
+
* Add or Edit Contact
|
|
691
|
+
*/
|
|
692
|
+
const addOrEditContact = (jid, contact) => {
|
|
693
|
+
return chatModify({
|
|
694
|
+
contact
|
|
695
|
+
}, jid);
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Remove Contact
|
|
699
|
+
*/
|
|
700
|
+
const removeContact = (jid) => {
|
|
701
|
+
return chatModify({
|
|
702
|
+
contact: null
|
|
703
|
+
}, jid);
|
|
704
|
+
};
|
|
675
705
|
/**
|
|
676
706
|
* Adds label
|
|
677
707
|
*/
|
|
@@ -729,75 +759,80 @@ const makeChatsSocket = (config) => {
|
|
|
729
759
|
* help ensure parity with WA Web
|
|
730
760
|
* */
|
|
731
761
|
const executeInitQueries = async () => {
|
|
732
|
-
await Promise.all([
|
|
733
|
-
fetchProps(),
|
|
734
|
-
fetchBlocklist(),
|
|
735
|
-
fetchPrivacySettings(),
|
|
736
|
-
]);
|
|
762
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
737
763
|
};
|
|
738
764
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
739
|
-
var _a, _b, _c;
|
|
740
765
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
741
766
|
if (!!msg.pushName) {
|
|
742
|
-
let jid = msg.key.fromMe ? authState.creds.me.id :
|
|
743
|
-
jid =
|
|
767
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
768
|
+
jid = jidNormalizedUser(jid);
|
|
744
769
|
if (!msg.key.fromMe) {
|
|
745
770
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
746
771
|
}
|
|
747
772
|
// update our pushname too
|
|
748
|
-
if (msg.key.fromMe && msg.pushName &&
|
|
773
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
749
774
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
750
775
|
}
|
|
751
776
|
}
|
|
752
|
-
const historyMsg =
|
|
777
|
+
const historyMsg = getHistoryMsg(msg.message);
|
|
753
778
|
const shouldProcessHistoryMsg = historyMsg
|
|
754
|
-
?
|
|
755
|
-
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
779
|
+
? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
756
780
|
: false;
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
781
|
+
// State machine: decide on sync and flush
|
|
782
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
783
|
+
if (awaitingSyncTimeout) {
|
|
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
|
+
}
|
|
760
797
|
}
|
|
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
|
+
};
|
|
761
810
|
await Promise.all([
|
|
762
811
|
(async () => {
|
|
763
|
-
if (
|
|
764
|
-
&& authState.creds.myAppStateKeyId) {
|
|
765
|
-
pendingAppStateSync = false;
|
|
812
|
+
if (shouldProcessHistoryMsg) {
|
|
766
813
|
await doAppStateSync();
|
|
767
814
|
}
|
|
768
815
|
})(),
|
|
769
|
-
(
|
|
816
|
+
processMessage(msg, {
|
|
770
817
|
shouldProcessHistoryMsg,
|
|
771
818
|
placeholderResendCache,
|
|
772
819
|
ev,
|
|
773
820
|
creds: authState.creds,
|
|
774
821
|
keyStore: authState.keys,
|
|
775
822
|
logger,
|
|
776
|
-
options: config.options
|
|
823
|
+
options: config.options
|
|
777
824
|
})
|
|
778
825
|
]);
|
|
779
|
-
|
|
780
|
-
|
|
826
|
+
// If the app state key arrives and we are waiting to sync, trigger the sync now.
|
|
827
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
|
|
828
|
+
logger.info('App state sync key arrived, triggering app state sync');
|
|
781
829
|
await doAppStateSync();
|
|
782
|
-
pendingAppStateSync = false;
|
|
783
|
-
}
|
|
784
|
-
async function doAppStateSync() {
|
|
785
|
-
if (!authState.creds.accountSyncCounter) {
|
|
786
|
-
logger.info('doing initial app state sync');
|
|
787
|
-
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
788
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
789
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
790
|
-
if (needToFlushWithAppStateSync) {
|
|
791
|
-
logger.debug('flushing with app state sync');
|
|
792
|
-
ev.flush();
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
830
|
}
|
|
796
831
|
});
|
|
797
832
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
798
833
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
799
834
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
800
|
-
const { attrs } =
|
|
835
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
801
836
|
const type = attrs.type;
|
|
802
837
|
switch (type) {
|
|
803
838
|
case 'account_sync':
|
|
@@ -819,23 +854,38 @@ const makeChatsSocket = (config) => {
|
|
|
819
854
|
}
|
|
820
855
|
});
|
|
821
856
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
822
|
-
var _a;
|
|
823
857
|
if (connection === 'open') {
|
|
824
858
|
if (fireInitQueries) {
|
|
825
|
-
executeInitQueries()
|
|
826
|
-
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
859
|
+
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
827
860
|
}
|
|
828
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
829
|
-
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
861
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
830
862
|
}
|
|
831
|
-
if (receivedPendingNotifications
|
|
832
|
-
|
|
833
|
-
// the key and can sync the messages
|
|
834
|
-
// todo scrutinize
|
|
835
|
-
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
836
|
-
ev.buffer();
|
|
837
|
-
needToFlushWithAppStateSync = true;
|
|
863
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
864
|
+
return;
|
|
838
865
|
}
|
|
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);
|
|
839
889
|
});
|
|
840
890
|
return {
|
|
841
891
|
...sock,
|
|
@@ -856,6 +906,7 @@ const makeChatsSocket = (config) => {
|
|
|
856
906
|
updateProfileStatus,
|
|
857
907
|
updateProfileName,
|
|
858
908
|
updateBlockStatus,
|
|
909
|
+
updateDisableLinkPreviewsPrivacy,
|
|
859
910
|
updateCallPrivacy,
|
|
860
911
|
updateMessagesPrivacy,
|
|
861
912
|
updateLastSeenPrivacy,
|
|
@@ -869,6 +920,8 @@ const makeChatsSocket = (config) => {
|
|
|
869
920
|
resyncAppState,
|
|
870
921
|
chatModify,
|
|
871
922
|
cleanDirtyBits,
|
|
923
|
+
addOrEditContact,
|
|
924
|
+
removeContact,
|
|
872
925
|
addLabel,
|
|
873
926
|
addChatLabel,
|
|
874
927
|
removeChatLabel,
|
|
@@ -877,4 +930,4 @@ const makeChatsSocket = (config) => {
|
|
|
877
930
|
star
|
|
878
931
|
};
|
|
879
932
|
};
|
|
880
|
-
|
|
933
|
+
//# sourceMappingURL=chats.js.map
|