phantom-baileys 0.0.9 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +592 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +5147 -41513
- package/WAProto/index.js +84008 -142014
- package/lib/Defaults/index.d.ts +29 -8
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +80 -60
- 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 +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -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 +18 -0
- package/lib/Signal/Group/keyhelper.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 +26 -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 +66 -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 +41 -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 +84 -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} +3 -16
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -3
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +331 -80
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +271 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +3 -2
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +184 -101
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +72 -42
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +340 -299
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +309 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/dugong.d.ts +79 -0
- package/lib/Socket/dugong.d.ts.map +1 -0
- package/lib/Socket/dugong.js +527 -0
- package/lib/Socket/dugong.js.map +1 -0
- package/lib/Socket/groups.d.ts +93 -58
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +96 -84
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +232 -107
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +13 -10
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +170 -90
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +798 -462
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +180 -99
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +833 -709
- 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 +120 -75
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +227 -198
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +31 -20
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +508 -215
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +18 -11
- 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/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +2 -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 +24 -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 +6 -1
- 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 +82 -17
- 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 +15 -3
- 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 +77 -202
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +128 -85
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +25 -26
- 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 +20 -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 +41 -24
- 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 -16
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -31
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +7 -6
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +228 -165
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +4 -3
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +16 -16
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +299 -232
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +18 -21
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +44 -125
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +20 -8
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +139 -90
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +7 -8
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +129 -72
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +25 -22
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +157 -175
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +14 -11
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +83 -46
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +22 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +14 -22
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -1
- 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 +8 -12
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +2 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +225 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +59 -42
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +411 -356
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +32 -18
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +412 -723
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +13 -13
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +149 -108
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +30 -11
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +321 -166
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-messages.d.ts +129 -0
- package/lib/Utils/rich-messages.d.ts.map +1 -0
- package/lib/Utils/rich-messages.js +455 -0
- package/lib/Utils/rich-messages.js.map +1 -0
- package/lib/Utils/signal.d.ts +7 -6
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +65 -65
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +18 -0
- package/lib/Utils/tc-token-utils.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 +79 -253
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +6 -6
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +111 -116
- 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 +1281 -20
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +51 -53
- 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 +12 -44
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +9 -6
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +124 -43
- 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 +24 -7
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +74 -40
- 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 +5 -3
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -2
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +17 -22
- 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/WAProto/fix-imports.d.ts +1 -0
- package/lib/WAProto/fix-imports.js +71 -0
- package/lib/WAProto/index.js +89345 -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 +5 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- 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 +5 -4
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +40 -35
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +7 -4
- 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 +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -31
- package/lib/index.js.map +1 -0
- package/package.json +35 -75
- package/Readme.md +0 -1
- 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/Defaults/baileys-version.json +0 -3
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/index.js +0 -10
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -431
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
package/lib/Socket/chats.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 { buildTcTokenFromJid } from '../Utils/tc-token-utils.js';
|
|
11
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
12
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
13
|
+
import { makeSocket } from './socket.js';
|
|
18
14
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
|
-
const makeChatsSocket = (config) => {
|
|
20
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
21
|
-
const sock = (
|
|
22
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
15
|
+
export const makeChatsSocket = (config) => {
|
|
16
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, getMessage } = config;
|
|
17
|
+
const sock = makeSocket(config);
|
|
18
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession } = sock;
|
|
23
19
|
let privacySettings;
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
let syncState = SyncState.Connecting;
|
|
21
|
+
/** this mutex ensures that messages are processed in order */
|
|
22
|
+
const messageMutex = makeMutex();
|
|
23
|
+
/** this mutex ensures that receipts are processed in order */
|
|
24
|
+
const receiptMutex = makeMutex();
|
|
25
|
+
/** this mutex ensures that app state patches are processed in order */
|
|
26
|
+
const appStatePatchMutex = makeMutex();
|
|
27
|
+
/** this mutex ensures that notifications are processed in order */
|
|
28
|
+
const notificationMutex = makeMutex();
|
|
29
|
+
// Timeout for AwaitingInitialSync state
|
|
30
|
+
let awaitingSyncTimeout;
|
|
31
|
+
const placeholderResendCache = config.placeholderResendCache ||
|
|
32
|
+
new NodeCache({
|
|
33
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
34
|
+
useClones: false
|
|
35
|
+
});
|
|
32
36
|
if (!config.placeholderResendCache) {
|
|
33
37
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
38
|
}
|
|
@@ -43,14 +47,12 @@ const makeChatsSocket = (config) => {
|
|
|
43
47
|
tag: 'iq',
|
|
44
48
|
attrs: {
|
|
45
49
|
xmlns: 'privacy',
|
|
46
|
-
to:
|
|
50
|
+
to: S_WHATSAPP_NET,
|
|
47
51
|
type: 'get'
|
|
48
52
|
},
|
|
49
|
-
content: [
|
|
50
|
-
{ tag: 'privacy', attrs: {} }
|
|
51
|
-
]
|
|
53
|
+
content: [{ tag: 'privacy', attrs: {} }]
|
|
52
54
|
});
|
|
53
|
-
privacySettings =
|
|
55
|
+
privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
|
|
54
56
|
}
|
|
55
57
|
return privacySettings;
|
|
56
58
|
};
|
|
@@ -60,10 +62,11 @@ const makeChatsSocket = (config) => {
|
|
|
60
62
|
tag: 'iq',
|
|
61
63
|
attrs: {
|
|
62
64
|
xmlns: 'privacy',
|
|
63
|
-
to:
|
|
65
|
+
to: S_WHATSAPP_NET,
|
|
64
66
|
type: 'set'
|
|
65
67
|
},
|
|
66
|
-
content: [
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
67
70
|
tag: 'privacy',
|
|
68
71
|
attrs: {},
|
|
69
72
|
content: [
|
|
@@ -72,7 +75,8 @@ const makeChatsSocket = (config) => {
|
|
|
72
75
|
attrs: { name, value }
|
|
73
76
|
}
|
|
74
77
|
]
|
|
75
|
-
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
76
80
|
});
|
|
77
81
|
};
|
|
78
82
|
const updateMessagesPrivacy = async (value) => {
|
|
@@ -104,15 +108,17 @@ const makeChatsSocket = (config) => {
|
|
|
104
108
|
tag: 'iq',
|
|
105
109
|
attrs: {
|
|
106
110
|
xmlns: 'disappearing_mode',
|
|
107
|
-
to:
|
|
111
|
+
to: S_WHATSAPP_NET,
|
|
108
112
|
type: 'set'
|
|
109
113
|
},
|
|
110
|
-
content: [
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
111
116
|
tag: 'disappearing_mode',
|
|
112
117
|
attrs: {
|
|
113
118
|
duration: duration.toString()
|
|
114
119
|
}
|
|
115
|
-
}
|
|
120
|
+
}
|
|
121
|
+
]
|
|
116
122
|
});
|
|
117
123
|
};
|
|
118
124
|
const getBotListV2 = async () => {
|
|
@@ -120,21 +126,23 @@ const makeChatsSocket = (config) => {
|
|
|
120
126
|
tag: 'iq',
|
|
121
127
|
attrs: {
|
|
122
128
|
xmlns: 'bot',
|
|
123
|
-
to:
|
|
129
|
+
to: S_WHATSAPP_NET,
|
|
124
130
|
type: 'get'
|
|
125
131
|
},
|
|
126
|
-
content: [
|
|
132
|
+
content: [
|
|
133
|
+
{
|
|
127
134
|
tag: 'bot',
|
|
128
135
|
attrs: {
|
|
129
136
|
v: '2'
|
|
130
137
|
}
|
|
131
|
-
}
|
|
138
|
+
}
|
|
139
|
+
]
|
|
132
140
|
});
|
|
133
|
-
const botNode =
|
|
141
|
+
const botNode = getBinaryNodeChild(resp, 'bot');
|
|
134
142
|
const botList = [];
|
|
135
|
-
for (const section of
|
|
143
|
+
for (const section of getBinaryNodeChildren(botNode, 'section')) {
|
|
136
144
|
if (section.attrs.type === 'all') {
|
|
137
|
-
for (const bot of
|
|
145
|
+
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
|
138
146
|
botList.push({
|
|
139
147
|
jid: bot.attrs.jid,
|
|
140
148
|
personaId: bot.attrs['persona_id']
|
|
@@ -144,78 +152,10 @@ const makeChatsSocket = (config) => {
|
|
|
144
152
|
}
|
|
145
153
|
return botList;
|
|
146
154
|
};
|
|
147
|
-
/** helper function to run a generic IQ query */
|
|
148
|
-
const interactiveQuery = async (userNodes, queryNode) => {
|
|
149
|
-
const result = await query({
|
|
150
|
-
tag: 'iq',
|
|
151
|
-
attrs: {
|
|
152
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
153
|
-
type: 'get',
|
|
154
|
-
xmlns: 'usync',
|
|
155
|
-
},
|
|
156
|
-
content: [
|
|
157
|
-
{
|
|
158
|
-
tag: 'usync',
|
|
159
|
-
attrs: {
|
|
160
|
-
sid: generateMessageTag(),
|
|
161
|
-
mode: 'query',
|
|
162
|
-
last: 'true',
|
|
163
|
-
index: '0',
|
|
164
|
-
context: 'interactive',
|
|
165
|
-
},
|
|
166
|
-
content: [
|
|
167
|
-
{
|
|
168
|
-
tag: 'query',
|
|
169
|
-
attrs: {},
|
|
170
|
-
content: [queryNode]
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
tag: 'list',
|
|
174
|
-
attrs: {},
|
|
175
|
-
content: userNodes
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
}
|
|
179
|
-
],
|
|
180
|
-
});
|
|
181
|
-
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
|
182
|
-
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
183
|
-
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
184
|
-
return users;
|
|
185
|
-
};
|
|
186
|
-
const fetchUserLid = async (jid) => {
|
|
187
|
-
const [result] = await interactiveQuery([
|
|
188
|
-
{
|
|
189
|
-
tag: 'user',
|
|
190
|
-
attrs: { jid }
|
|
191
|
-
}
|
|
192
|
-
], {
|
|
193
|
-
tag: 'lid',
|
|
194
|
-
attrs: {}
|
|
195
|
-
});
|
|
196
|
-
if (result) {
|
|
197
|
-
const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
|
|
198
|
-
return lid.attrs.val;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const onWhatsApp = async (...jids) => {
|
|
202
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
203
|
-
.withContactProtocol()
|
|
204
|
-
.withLIDProtocol();
|
|
205
|
-
for (const jid of jids) {
|
|
206
|
-
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
207
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
208
|
-
}
|
|
209
|
-
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
210
|
-
if (results) {
|
|
211
|
-
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
155
|
const fetchStatus = async (...jids) => {
|
|
215
|
-
const usyncQuery = new
|
|
216
|
-
.withStatusProtocol();
|
|
156
|
+
const usyncQuery = new USyncQuery().withStatusProtocol();
|
|
217
157
|
for (const jid of jids) {
|
|
218
|
-
usyncQuery.withUser(new
|
|
158
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
219
159
|
}
|
|
220
160
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
221
161
|
if (result) {
|
|
@@ -223,10 +163,9 @@ const makeChatsSocket = (config) => {
|
|
|
223
163
|
}
|
|
224
164
|
};
|
|
225
165
|
const fetchDisappearingDuration = async (...jids) => {
|
|
226
|
-
const usyncQuery = new
|
|
227
|
-
.withDisappearingModeProtocol();
|
|
166
|
+
const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
|
|
228
167
|
for (const jid of jids) {
|
|
229
|
-
usyncQuery.withUser(new
|
|
168
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
230
169
|
}
|
|
231
170
|
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
232
171
|
if (result) {
|
|
@@ -234,22 +173,25 @@ const makeChatsSocket = (config) => {
|
|
|
234
173
|
}
|
|
235
174
|
};
|
|
236
175
|
/** update the profile picture for yourself or a group */
|
|
237
|
-
const updateProfilePicture = async (jid, content) => {
|
|
176
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
238
177
|
let targetJid;
|
|
239
178
|
if (!jid) {
|
|
240
|
-
throw new
|
|
179
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
241
180
|
}
|
|
242
|
-
if (
|
|
243
|
-
targetJid =
|
|
181
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
182
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
244
183
|
}
|
|
245
|
-
|
|
184
|
+
else {
|
|
185
|
+
targetJid = undefined;
|
|
186
|
+
}
|
|
187
|
+
const { img } = await generateProfilePicture(content, dimensions);
|
|
246
188
|
await query({
|
|
247
189
|
tag: 'iq',
|
|
248
190
|
attrs: {
|
|
249
|
-
|
|
250
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
191
|
+
to: S_WHATSAPP_NET,
|
|
251
192
|
type: 'set',
|
|
252
|
-
xmlns: 'w:profile:picture'
|
|
193
|
+
xmlns: 'w:profile:picture',
|
|
194
|
+
...(targetJid ? { target: targetJid } : {})
|
|
253
195
|
},
|
|
254
196
|
content: [
|
|
255
197
|
{
|
|
@@ -264,18 +206,21 @@ const makeChatsSocket = (config) => {
|
|
|
264
206
|
const removeProfilePicture = async (jid) => {
|
|
265
207
|
let targetJid;
|
|
266
208
|
if (!jid) {
|
|
267
|
-
throw new
|
|
209
|
+
throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
210
|
+
}
|
|
211
|
+
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
|
|
212
|
+
targetJid = jidNormalizedUser(jid); // in case it is someone other than us
|
|
268
213
|
}
|
|
269
|
-
|
|
270
|
-
targetJid =
|
|
214
|
+
else {
|
|
215
|
+
targetJid = undefined;
|
|
271
216
|
}
|
|
272
217
|
await query({
|
|
273
218
|
tag: 'iq',
|
|
274
219
|
attrs: {
|
|
275
|
-
|
|
276
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
220
|
+
to: S_WHATSAPP_NET,
|
|
277
221
|
type: 'set',
|
|
278
|
-
xmlns: 'w:profile:picture'
|
|
222
|
+
xmlns: 'w:profile:picture',
|
|
223
|
+
...(targetJid ? { target: targetJid } : {})
|
|
279
224
|
}
|
|
280
225
|
});
|
|
281
226
|
};
|
|
@@ -284,7 +229,7 @@ const makeChatsSocket = (config) => {
|
|
|
284
229
|
await query({
|
|
285
230
|
tag: 'iq',
|
|
286
231
|
attrs: {
|
|
287
|
-
to:
|
|
232
|
+
to: S_WHATSAPP_NET,
|
|
288
233
|
type: 'set',
|
|
289
234
|
xmlns: 'status'
|
|
290
235
|
},
|
|
@@ -305,20 +250,19 @@ const makeChatsSocket = (config) => {
|
|
|
305
250
|
tag: 'iq',
|
|
306
251
|
attrs: {
|
|
307
252
|
xmlns: 'blocklist',
|
|
308
|
-
to:
|
|
253
|
+
to: S_WHATSAPP_NET,
|
|
309
254
|
type: 'get'
|
|
310
255
|
}
|
|
311
256
|
});
|
|
312
|
-
const listNode =
|
|
313
|
-
return
|
|
314
|
-
.map(n => n.attrs.jid);
|
|
257
|
+
const listNode = getBinaryNodeChild(result, 'list');
|
|
258
|
+
return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
|
|
315
259
|
};
|
|
316
260
|
const updateBlockStatus = async (jid, action) => {
|
|
317
261
|
await query({
|
|
318
262
|
tag: 'iq',
|
|
319
263
|
attrs: {
|
|
320
264
|
xmlns: 'blocklist',
|
|
321
|
-
to:
|
|
265
|
+
to: S_WHATSAPP_NET,
|
|
322
266
|
type: 'set'
|
|
323
267
|
},
|
|
324
268
|
content: [
|
|
@@ -333,7 +277,6 @@ const makeChatsSocket = (config) => {
|
|
|
333
277
|
});
|
|
334
278
|
};
|
|
335
279
|
const getBusinessProfile = async (jid) => {
|
|
336
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
337
280
|
const results = await query({
|
|
338
281
|
tag: 'iq',
|
|
339
282
|
attrs: {
|
|
@@ -341,38 +284,42 @@ const makeChatsSocket = (config) => {
|
|
|
341
284
|
xmlns: 'w:biz',
|
|
342
285
|
type: 'get'
|
|
343
286
|
},
|
|
344
|
-
content: [
|
|
287
|
+
content: [
|
|
288
|
+
{
|
|
345
289
|
tag: 'business_profile',
|
|
346
290
|
attrs: { v: '244' },
|
|
347
|
-
content: [
|
|
291
|
+
content: [
|
|
292
|
+
{
|
|
348
293
|
tag: 'profile',
|
|
349
294
|
attrs: { jid }
|
|
350
|
-
}
|
|
351
|
-
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
}
|
|
298
|
+
]
|
|
352
299
|
});
|
|
353
|
-
const profileNode =
|
|
354
|
-
const profiles =
|
|
300
|
+
const profileNode = getBinaryNodeChild(results, 'business_profile');
|
|
301
|
+
const profiles = getBinaryNodeChild(profileNode, 'profile');
|
|
355
302
|
if (profiles) {
|
|
356
|
-
const address =
|
|
357
|
-
const description =
|
|
358
|
-
const website =
|
|
359
|
-
const email =
|
|
360
|
-
const category =
|
|
361
|
-
const businessHours =
|
|
362
|
-
const businessHoursConfig = businessHours
|
|
363
|
-
|
|
364
|
-
undefined;
|
|
365
|
-
const websiteStr =
|
|
303
|
+
const address = getBinaryNodeChild(profiles, 'address');
|
|
304
|
+
const description = getBinaryNodeChild(profiles, 'description');
|
|
305
|
+
const website = getBinaryNodeChild(profiles, 'website');
|
|
306
|
+
const email = getBinaryNodeChild(profiles, 'email');
|
|
307
|
+
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
|
|
308
|
+
const businessHours = getBinaryNodeChild(profiles, 'business_hours');
|
|
309
|
+
const businessHoursConfig = businessHours
|
|
310
|
+
? getBinaryNodeChildren(businessHours, 'business_hours_config')
|
|
311
|
+
: undefined;
|
|
312
|
+
const websiteStr = website?.content?.toString();
|
|
366
313
|
return {
|
|
367
|
-
wid:
|
|
368
|
-
address:
|
|
369
|
-
description:
|
|
314
|
+
wid: profiles.attrs?.jid,
|
|
315
|
+
address: address?.content?.toString(),
|
|
316
|
+
description: description?.content?.toString() || '',
|
|
370
317
|
website: websiteStr ? [websiteStr] : [],
|
|
371
|
-
email:
|
|
372
|
-
category:
|
|
373
|
-
|
|
374
|
-
timezone:
|
|
375
|
-
|
|
318
|
+
email: email?.content?.toString(),
|
|
319
|
+
category: category?.content?.toString(),
|
|
320
|
+
business_hours: {
|
|
321
|
+
timezone: businessHours?.attrs?.timezone,
|
|
322
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
376
323
|
}
|
|
377
324
|
};
|
|
378
325
|
}
|
|
@@ -382,17 +329,17 @@ const makeChatsSocket = (config) => {
|
|
|
382
329
|
await sendNode({
|
|
383
330
|
tag: 'iq',
|
|
384
331
|
attrs: {
|
|
385
|
-
to:
|
|
332
|
+
to: S_WHATSAPP_NET,
|
|
386
333
|
type: 'set',
|
|
387
334
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
388
|
-
id: generateMessageTag()
|
|
335
|
+
id: generateMessageTag()
|
|
389
336
|
},
|
|
390
337
|
content: [
|
|
391
338
|
{
|
|
392
339
|
tag: 'clean',
|
|
393
340
|
attrs: {
|
|
394
341
|
type,
|
|
395
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
342
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
396
343
|
}
|
|
397
344
|
}
|
|
398
345
|
]
|
|
@@ -401,17 +348,25 @@ const makeChatsSocket = (config) => {
|
|
|
401
348
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
402
349
|
return {
|
|
403
350
|
onMutation(mutation) {
|
|
404
|
-
|
|
351
|
+
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
405
352
|
}
|
|
406
353
|
};
|
|
407
354
|
};
|
|
408
355
|
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
356
|
+
const appStateSyncKeyCache = new Map();
|
|
357
|
+
const getCachedAppStateSyncKey = async (keyId) => {
|
|
358
|
+
if (appStateSyncKeyCache.has(keyId)) {
|
|
359
|
+
return appStateSyncKeyCache.get(keyId) ?? undefined;
|
|
360
|
+
}
|
|
361
|
+
const key = await getAppStateSyncKey(keyId);
|
|
362
|
+
appStateSyncKeyCache.set(keyId, key ?? null);
|
|
363
|
+
return key;
|
|
364
|
+
};
|
|
409
365
|
// we use this to determine which events to fire
|
|
410
366
|
// otherwise when we resync from scratch -- all notifications will fire
|
|
411
367
|
const initialVersionMap = {};
|
|
412
368
|
const globalMutationMap = {};
|
|
413
369
|
await authState.keys.transaction(async () => {
|
|
414
|
-
var _a;
|
|
415
370
|
const collectionsToHandle = new Set(collections);
|
|
416
371
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
417
372
|
const attemptsMap = {};
|
|
@@ -430,7 +385,7 @@ const makeChatsSocket = (config) => {
|
|
|
430
385
|
}
|
|
431
386
|
}
|
|
432
387
|
else {
|
|
433
|
-
state =
|
|
388
|
+
state = newLTHashState();
|
|
434
389
|
}
|
|
435
390
|
states[name] = state;
|
|
436
391
|
logger.info(`resyncing ${name} from v${state.version}`);
|
|
@@ -440,14 +395,14 @@ const makeChatsSocket = (config) => {
|
|
|
440
395
|
name,
|
|
441
396
|
version: state.version.toString(),
|
|
442
397
|
// return snapshot if being synced from scratch
|
|
443
|
-
|
|
398
|
+
return_snapshot: (!state.version).toString()
|
|
444
399
|
}
|
|
445
400
|
});
|
|
446
401
|
}
|
|
447
402
|
const result = await query({
|
|
448
403
|
tag: 'iq',
|
|
449
404
|
attrs: {
|
|
450
|
-
to:
|
|
405
|
+
to: S_WHATSAPP_NET,
|
|
451
406
|
xmlns: 'w:sync:app:state',
|
|
452
407
|
type: 'set'
|
|
453
408
|
},
|
|
@@ -460,26 +415,22 @@ const makeChatsSocket = (config) => {
|
|
|
460
415
|
]
|
|
461
416
|
});
|
|
462
417
|
// extract from binary node
|
|
463
|
-
const decoded = await
|
|
418
|
+
const decoded = await extractSyncdPatches(result, config?.options);
|
|
464
419
|
for (const key in decoded) {
|
|
465
420
|
const name = key;
|
|
466
421
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
467
422
|
try {
|
|
468
423
|
if (snapshot) {
|
|
469
|
-
const { state: newState, mutationMap } = await
|
|
424
|
+
const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
470
425
|
states[name] = newState;
|
|
471
426
|
Object.assign(globalMutationMap, mutationMap);
|
|
472
427
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
473
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
474
|
-
[name]: newState
|
|
475
|
-
} });
|
|
428
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
476
429
|
}
|
|
477
430
|
// only process if there are syncd patches
|
|
478
431
|
if (patches.length) {
|
|
479
|
-
const { state: newState, mutationMap } = await
|
|
480
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
481
|
-
[name]: newState
|
|
482
|
-
} });
|
|
432
|
+
const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getCachedAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
433
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
483
434
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
484
435
|
initialVersionMap[name] = newState.version;
|
|
485
436
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -487,7 +438,8 @@ const makeChatsSocket = (config) => {
|
|
|
487
438
|
if (hasMorePatches) {
|
|
488
439
|
logger.info(`${name} has more patches...`);
|
|
489
440
|
}
|
|
490
|
-
else {
|
|
441
|
+
else {
|
|
442
|
+
// collection is done with sync
|
|
491
443
|
collectionsToHandle.delete(name);
|
|
492
444
|
}
|
|
493
445
|
}
|
|
@@ -495,12 +447,10 @@ const makeChatsSocket = (config) => {
|
|
|
495
447
|
// if retry attempts overshoot
|
|
496
448
|
// or key not found
|
|
497
449
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
498
|
-
|
|
450
|
+
error.output?.statusCode === 404 ||
|
|
499
451
|
error.name === 'TypeError';
|
|
500
452
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
501
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
502
|
-
[name]: null
|
|
503
|
-
} });
|
|
453
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
504
454
|
// increment number of retries
|
|
505
455
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
506
456
|
if (isIrrecoverableError) {
|
|
@@ -510,7 +460,7 @@ const makeChatsSocket = (config) => {
|
|
|
510
460
|
}
|
|
511
461
|
}
|
|
512
462
|
}
|
|
513
|
-
});
|
|
463
|
+
}, authState?.creds?.me?.id || 'resync-app-state');
|
|
514
464
|
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
515
465
|
for (const key in globalMutationMap) {
|
|
516
466
|
onMutation(globalMutationMap[key]);
|
|
@@ -520,47 +470,70 @@ const makeChatsSocket = (config) => {
|
|
|
520
470
|
* fetch the profile picture of a user/group
|
|
521
471
|
* type = "preview" for a low res picture
|
|
522
472
|
* type = "image for the high res picture"
|
|
523
|
-
|
|
473
|
+
*/
|
|
524
474
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
525
|
-
|
|
526
|
-
|
|
475
|
+
const baseContent = [{ tag: 'picture', attrs: { type, query: 'url' } }];
|
|
476
|
+
const tcTokenContent = await buildTcTokenFromJid({ authState, jid, baseContent });
|
|
477
|
+
jid = jidNormalizedUser(jid);
|
|
527
478
|
const result = await query({
|
|
528
479
|
tag: 'iq',
|
|
529
480
|
attrs: {
|
|
530
481
|
target: jid,
|
|
531
|
-
to:
|
|
482
|
+
to: S_WHATSAPP_NET,
|
|
532
483
|
type: 'get',
|
|
533
484
|
xmlns: 'w:profile:picture'
|
|
534
485
|
},
|
|
486
|
+
content: tcTokenContent
|
|
487
|
+
}, timeoutMs);
|
|
488
|
+
const child = getBinaryNodeChild(result, 'picture');
|
|
489
|
+
return child?.attrs?.url;
|
|
490
|
+
};
|
|
491
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
492
|
+
const result = await query({
|
|
493
|
+
tag: 'call',
|
|
494
|
+
attrs: {
|
|
495
|
+
id: generateMessageTag(),
|
|
496
|
+
to: '@call'
|
|
497
|
+
},
|
|
535
498
|
content: [
|
|
536
|
-
{
|
|
499
|
+
{
|
|
500
|
+
tag: 'link_create',
|
|
501
|
+
attrs: { media: type },
|
|
502
|
+
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
503
|
+
}
|
|
537
504
|
]
|
|
538
505
|
}, timeoutMs);
|
|
539
|
-
const child =
|
|
540
|
-
return
|
|
506
|
+
const child = getBinaryNodeChild(result, 'link_create');
|
|
507
|
+
return child?.attrs?.token;
|
|
541
508
|
};
|
|
542
509
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
543
510
|
const me = authState.creds.me;
|
|
544
|
-
|
|
511
|
+
const isAvailableType = type === 'available';
|
|
512
|
+
if (isAvailableType || type === 'unavailable') {
|
|
545
513
|
if (!me.name) {
|
|
546
514
|
logger.warn('no name present, ignoring presence update request...');
|
|
547
515
|
return;
|
|
548
516
|
}
|
|
549
|
-
ev.emit('connection.update', { isOnline:
|
|
517
|
+
ev.emit('connection.update', { isOnline: isAvailableType });
|
|
518
|
+
if (isAvailableType) {
|
|
519
|
+
void sendUnifiedSession();
|
|
520
|
+
}
|
|
550
521
|
await sendNode({
|
|
551
522
|
tag: 'presence',
|
|
552
523
|
attrs: {
|
|
553
|
-
name: me.name,
|
|
524
|
+
name: me.name.replace(/@/g, ''),
|
|
554
525
|
type
|
|
555
526
|
}
|
|
556
527
|
});
|
|
557
528
|
}
|
|
558
529
|
else {
|
|
530
|
+
const { server } = jidDecode(toJid);
|
|
531
|
+
const isLid = server === 'lid';
|
|
559
532
|
await sendNode({
|
|
560
533
|
tag: 'chatstate',
|
|
561
534
|
attrs: {
|
|
562
|
-
from: me.id,
|
|
563
|
-
to: toJid
|
|
535
|
+
from: isLid ? me.lid : me.id,
|
|
536
|
+
to: toJid
|
|
564
537
|
},
|
|
565
538
|
content: [
|
|
566
539
|
{
|
|
@@ -575,29 +548,23 @@ const makeChatsSocket = (config) => {
|
|
|
575
548
|
* @param toJid the jid to subscribe to
|
|
576
549
|
* @param tcToken token for subscription, use if present
|
|
577
550
|
*/
|
|
578
|
-
const presenceSubscribe = (toJid
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
content: tcToken
|
|
591
|
-
}
|
|
592
|
-
] :
|
|
593
|
-
undefined
|
|
594
|
-
}));
|
|
551
|
+
const presenceSubscribe = async (toJid) => {
|
|
552
|
+
const tcTokenContent = await buildTcTokenFromJid({ authState, jid: toJid });
|
|
553
|
+
return sendNode({
|
|
554
|
+
tag: 'presence',
|
|
555
|
+
attrs: {
|
|
556
|
+
to: toJid,
|
|
557
|
+
id: generateMessageTag(),
|
|
558
|
+
type: 'subscribe'
|
|
559
|
+
},
|
|
560
|
+
content: tcTokenContent
|
|
561
|
+
});
|
|
562
|
+
};
|
|
595
563
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
596
|
-
var _a;
|
|
597
564
|
let presence;
|
|
598
565
|
const jid = attrs.from;
|
|
599
566
|
const participant = attrs.participant || attrs.from;
|
|
600
|
-
if (shouldIgnoreJid(jid) && jid !==
|
|
567
|
+
if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
|
|
601
568
|
return;
|
|
602
569
|
}
|
|
603
570
|
if (tag === 'presence') {
|
|
@@ -612,7 +579,7 @@ const makeChatsSocket = (config) => {
|
|
|
612
579
|
if (type === 'paused') {
|
|
613
580
|
type = 'available';
|
|
614
581
|
}
|
|
615
|
-
if (
|
|
582
|
+
if (firstChild.attrs?.media === 'audio') {
|
|
616
583
|
type = 'recording';
|
|
617
584
|
}
|
|
618
585
|
presence = { lastKnownPresence: type };
|
|
@@ -621,31 +588,29 @@ const makeChatsSocket = (config) => {
|
|
|
621
588
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
622
589
|
}
|
|
623
590
|
if (presence) {
|
|
624
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
625
|
-
[participant]: presence
|
|
626
|
-
} });
|
|
591
|
+
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
|
|
627
592
|
}
|
|
628
593
|
};
|
|
629
594
|
const appPatch = async (patchCreate) => {
|
|
630
595
|
const name = patchCreate.type;
|
|
631
596
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
632
597
|
if (!myAppStateKeyId) {
|
|
633
|
-
throw new
|
|
598
|
+
throw new Boom('App state key not present!', { statusCode: 400 });
|
|
634
599
|
}
|
|
635
600
|
let initial;
|
|
636
601
|
let encodeResult;
|
|
637
|
-
await
|
|
602
|
+
await appStatePatchMutex.mutex(async () => {
|
|
638
603
|
await authState.keys.transaction(async () => {
|
|
639
604
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
640
605
|
await resyncAppState([name], false);
|
|
641
606
|
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
642
|
-
initial = currentSyncVersion ||
|
|
643
|
-
encodeResult = await
|
|
607
|
+
initial = currentSyncVersion || newLTHashState();
|
|
608
|
+
encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
644
609
|
const { patch, state } = encodeResult;
|
|
645
610
|
const node = {
|
|
646
611
|
tag: 'iq',
|
|
647
612
|
attrs: {
|
|
648
|
-
to:
|
|
613
|
+
to: S_WHATSAPP_NET,
|
|
649
614
|
type: 'set',
|
|
650
615
|
xmlns: 'w:sync:app:state'
|
|
651
616
|
},
|
|
@@ -659,13 +624,13 @@ const makeChatsSocket = (config) => {
|
|
|
659
624
|
attrs: {
|
|
660
625
|
name,
|
|
661
626
|
version: (state.version - 1).toString(),
|
|
662
|
-
|
|
627
|
+
return_snapshot: 'false'
|
|
663
628
|
},
|
|
664
629
|
content: [
|
|
665
630
|
{
|
|
666
631
|
tag: 'patch',
|
|
667
632
|
attrs: {},
|
|
668
|
-
content:
|
|
633
|
+
content: proto.SyncdPatch.encode(patch).finish()
|
|
669
634
|
}
|
|
670
635
|
]
|
|
671
636
|
}
|
|
@@ -674,14 +639,12 @@ const makeChatsSocket = (config) => {
|
|
|
674
639
|
]
|
|
675
640
|
};
|
|
676
641
|
await query(node);
|
|
677
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
678
|
-
|
|
679
|
-
} });
|
|
680
|
-
});
|
|
642
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
|
|
643
|
+
}, authState?.creds?.me?.id || 'app-patch');
|
|
681
644
|
});
|
|
682
645
|
if (config.emitOwnEvents) {
|
|
683
646
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
684
|
-
const { mutationMap } = await
|
|
647
|
+
const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
685
648
|
for (const key in mutationMap) {
|
|
686
649
|
onMutation(mutationMap[key]);
|
|
687
650
|
}
|
|
@@ -689,32 +652,33 @@ const makeChatsSocket = (config) => {
|
|
|
689
652
|
};
|
|
690
653
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
691
654
|
const fetchProps = async () => {
|
|
692
|
-
|
|
655
|
+
//TODO: implement both protocol 1 and protocol 2 prop fetching, specially for abKey for WM
|
|
693
656
|
const resultNode = await query({
|
|
694
657
|
tag: 'iq',
|
|
695
658
|
attrs: {
|
|
696
|
-
to:
|
|
659
|
+
to: S_WHATSAPP_NET,
|
|
697
660
|
xmlns: 'w',
|
|
698
|
-
type: 'get'
|
|
661
|
+
type: 'get'
|
|
699
662
|
},
|
|
700
663
|
content: [
|
|
701
664
|
{
|
|
702
665
|
tag: 'props',
|
|
703
666
|
attrs: {
|
|
704
667
|
protocol: '2',
|
|
705
|
-
hash:
|
|
668
|
+
hash: authState?.creds?.lastPropHash || ''
|
|
706
669
|
}
|
|
707
670
|
}
|
|
708
671
|
]
|
|
709
672
|
});
|
|
710
|
-
const propsNode =
|
|
673
|
+
const propsNode = getBinaryNodeChild(resultNode, 'props');
|
|
711
674
|
let props = {};
|
|
712
675
|
if (propsNode) {
|
|
713
|
-
if (
|
|
714
|
-
|
|
676
|
+
if (propsNode.attrs?.hash) {
|
|
677
|
+
// on some clients, the hash is returning as undefined
|
|
678
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
715
679
|
ev.emit('creds.update', authState.creds);
|
|
716
680
|
}
|
|
717
|
-
props =
|
|
681
|
+
props = reduceBinaryNodeToDictionary(propsNode, 'prop');
|
|
718
682
|
}
|
|
719
683
|
logger.debug('fetched props');
|
|
720
684
|
return props;
|
|
@@ -725,9 +689,17 @@ const makeChatsSocket = (config) => {
|
|
|
725
689
|
* requires the last messages till the last message received; required for archive & unread
|
|
726
690
|
*/
|
|
727
691
|
const chatModify = (mod, jid) => {
|
|
728
|
-
const patch =
|
|
692
|
+
const patch = chatModificationToAppPatch(mod, jid);
|
|
729
693
|
return appPatch(patch);
|
|
730
694
|
};
|
|
695
|
+
/**
|
|
696
|
+
* Enable/Disable link preview privacy, not related to baileys link preview generation
|
|
697
|
+
*/
|
|
698
|
+
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
699
|
+
return chatModify({
|
|
700
|
+
disableLinkPreviews: { isPreviewsDisabled }
|
|
701
|
+
}, '');
|
|
702
|
+
};
|
|
731
703
|
/**
|
|
732
704
|
* Star or Unstar a message
|
|
733
705
|
*/
|
|
@@ -739,6 +711,22 @@ const makeChatsSocket = (config) => {
|
|
|
739
711
|
}
|
|
740
712
|
}, jid);
|
|
741
713
|
};
|
|
714
|
+
/**
|
|
715
|
+
* Add or Edit Contact
|
|
716
|
+
*/
|
|
717
|
+
const addOrEditContact = (jid, contact) => {
|
|
718
|
+
return chatModify({
|
|
719
|
+
contact
|
|
720
|
+
}, jid);
|
|
721
|
+
};
|
|
722
|
+
/**
|
|
723
|
+
* Remove Contact
|
|
724
|
+
*/
|
|
725
|
+
const removeContact = (jid) => {
|
|
726
|
+
return chatModify({
|
|
727
|
+
contact: null
|
|
728
|
+
}, jid);
|
|
729
|
+
};
|
|
742
730
|
/**
|
|
743
731
|
* Adds label
|
|
744
732
|
*/
|
|
@@ -791,49 +779,84 @@ const makeChatsSocket = (config) => {
|
|
|
791
779
|
}
|
|
792
780
|
}, jid);
|
|
793
781
|
};
|
|
782
|
+
/**
|
|
783
|
+
* Add or Edit Quick Reply
|
|
784
|
+
*/
|
|
785
|
+
const addOrEditQuickReply = (quickReply) => {
|
|
786
|
+
return chatModify({
|
|
787
|
+
quickReply
|
|
788
|
+
}, '');
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Remove Quick Reply
|
|
792
|
+
*/
|
|
793
|
+
const removeQuickReply = (timestamp) => {
|
|
794
|
+
return chatModify({
|
|
795
|
+
quickReply: { timestamp, deleted: true }
|
|
796
|
+
}, '');
|
|
797
|
+
};
|
|
794
798
|
/**
|
|
795
799
|
* queries need to be fired on connection open
|
|
796
800
|
* help ensure parity with WA Web
|
|
797
801
|
* */
|
|
798
802
|
const executeInitQueries = async () => {
|
|
799
|
-
await Promise.all([
|
|
800
|
-
fetchProps(),
|
|
801
|
-
fetchBlocklist(),
|
|
802
|
-
fetchPrivacySettings(),
|
|
803
|
-
]);
|
|
803
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
804
804
|
};
|
|
805
805
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
806
|
-
var _a, _b, _c;
|
|
807
806
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
808
807
|
if (!!msg.pushName) {
|
|
809
|
-
let jid = msg.key.fromMe ? authState.creds.me.id :
|
|
810
|
-
jid =
|
|
808
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
809
|
+
jid = jidNormalizedUser(jid);
|
|
811
810
|
if (!msg.key.fromMe) {
|
|
812
811
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
813
812
|
}
|
|
814
813
|
// update our pushname too
|
|
815
|
-
if (msg.key.fromMe && msg.pushName &&
|
|
814
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
816
815
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
817
816
|
}
|
|
818
817
|
}
|
|
819
|
-
const historyMsg =
|
|
820
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
false;
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
818
|
+
const historyMsg = getHistoryMsg(msg.message);
|
|
819
|
+
const shouldProcessHistoryMsg = historyMsg
|
|
820
|
+
? shouldSyncHistoryMessage(historyMsg) &&
|
|
821
|
+
PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
822
|
+
: false;
|
|
823
|
+
// State machine: decide on sync and flush
|
|
824
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
825
|
+
if (awaitingSyncTimeout) {
|
|
826
|
+
clearTimeout(awaitingSyncTimeout);
|
|
827
|
+
awaitingSyncTimeout = undefined;
|
|
828
|
+
}
|
|
829
|
+
if (shouldProcessHistoryMsg) {
|
|
830
|
+
syncState = SyncState.Syncing;
|
|
831
|
+
logger.info('Transitioned to Syncing state');
|
|
832
|
+
// Let doAppStateSync handle the final flush after it's done
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
syncState = SyncState.Online;
|
|
836
|
+
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
837
|
+
ev.flush();
|
|
838
|
+
}
|
|
827
839
|
}
|
|
840
|
+
const doAppStateSync = async () => {
|
|
841
|
+
if (syncState === SyncState.Syncing) {
|
|
842
|
+
logger.info('Doing app state sync');
|
|
843
|
+
await resyncAppState(ALL_WA_PATCH_NAMES, true);
|
|
844
|
+
// Sync is complete, go online and flush everything
|
|
845
|
+
syncState = SyncState.Online;
|
|
846
|
+
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
847
|
+
ev.flush();
|
|
848
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
849
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
850
|
+
}
|
|
851
|
+
};
|
|
828
852
|
await Promise.all([
|
|
829
853
|
(async () => {
|
|
830
|
-
if (
|
|
831
|
-
authState.creds.myAppStateKeyId) {
|
|
832
|
-
pendingAppStateSync = false;
|
|
854
|
+
if (shouldProcessHistoryMsg) {
|
|
833
855
|
await doAppStateSync();
|
|
834
856
|
}
|
|
835
857
|
})(),
|
|
836
|
-
(
|
|
858
|
+
processMessage(msg, {
|
|
859
|
+
signalRepository,
|
|
837
860
|
shouldProcessHistoryMsg,
|
|
838
861
|
placeholderResendCache,
|
|
839
862
|
ev,
|
|
@@ -841,31 +864,19 @@ const makeChatsSocket = (config) => {
|
|
|
841
864
|
keyStore: authState.keys,
|
|
842
865
|
logger,
|
|
843
866
|
options: config.options,
|
|
844
|
-
getMessage
|
|
867
|
+
getMessage
|
|
845
868
|
})
|
|
846
869
|
]);
|
|
847
|
-
|
|
848
|
-
|
|
870
|
+
// If the app state key arrives and we are waiting to sync, trigger the sync now.
|
|
871
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
|
|
872
|
+
logger.info('App state sync key arrived, triggering app state sync');
|
|
849
873
|
await doAppStateSync();
|
|
850
|
-
pendingAppStateSync = false;
|
|
851
|
-
}
|
|
852
|
-
async function doAppStateSync() {
|
|
853
|
-
if (!authState.creds.accountSyncCounter) {
|
|
854
|
-
logger.info('doing initial app state sync');
|
|
855
|
-
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
856
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
857
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
858
|
-
if (needToFlushWithAppStateSync) {
|
|
859
|
-
logger.debug('flushing with app state sync');
|
|
860
|
-
ev.flush();
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
874
|
}
|
|
864
875
|
});
|
|
865
876
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
866
877
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
867
878
|
ws.on('CB:ib,,dirty', async (node) => {
|
|
868
|
-
const { attrs } =
|
|
879
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
869
880
|
const type = attrs.type;
|
|
870
881
|
switch (type) {
|
|
871
882
|
case 'account_sync':
|
|
@@ -887,37 +898,62 @@ const makeChatsSocket = (config) => {
|
|
|
887
898
|
}
|
|
888
899
|
});
|
|
889
900
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
890
|
-
var _a;
|
|
891
901
|
if (connection === 'open') {
|
|
892
902
|
if (fireInitQueries) {
|
|
893
|
-
executeInitQueries()
|
|
894
|
-
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
903
|
+
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
895
904
|
}
|
|
896
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
897
|
-
|
|
905
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
906
|
+
}
|
|
907
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
syncState = SyncState.AwaitingInitialSync;
|
|
911
|
+
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
912
|
+
ev.buffer();
|
|
913
|
+
const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
|
|
914
|
+
syncType: proto.HistorySync.HistorySyncType.RECENT
|
|
915
|
+
}));
|
|
916
|
+
if (!willSyncHistory) {
|
|
917
|
+
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
918
|
+
syncState = SyncState.Online;
|
|
919
|
+
setTimeout(() => ev.flush(), 0);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
923
|
+
if (awaitingSyncTimeout) {
|
|
924
|
+
clearTimeout(awaitingSyncTimeout);
|
|
925
|
+
}
|
|
926
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
927
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
928
|
+
// TODO: investigate
|
|
929
|
+
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
930
|
+
syncState = SyncState.Online;
|
|
931
|
+
ev.flush();
|
|
932
|
+
}
|
|
933
|
+
}, 20000);
|
|
934
|
+
});
|
|
935
|
+
ev.on('lid-mapping.update', async ({ lid, pn }) => {
|
|
936
|
+
try {
|
|
937
|
+
await signalRepository.lidMapping.storeLIDPNMappings([{ lid, pn }]);
|
|
898
938
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
// the key and can sync the messages
|
|
902
|
-
// todo scrutinize
|
|
903
|
-
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
904
|
-
ev.buffer();
|
|
905
|
-
needToFlushWithAppStateSync = true;
|
|
939
|
+
catch (error) {
|
|
940
|
+
logger.warn({ lid, pn, error }, 'Failed to store LID-PN mapping');
|
|
906
941
|
}
|
|
907
942
|
});
|
|
908
943
|
return {
|
|
909
944
|
...sock,
|
|
910
|
-
|
|
945
|
+
createCallLink,
|
|
911
946
|
getBotListV2,
|
|
912
|
-
|
|
947
|
+
messageMutex,
|
|
948
|
+
receiptMutex,
|
|
949
|
+
appStatePatchMutex,
|
|
950
|
+
notificationMutex,
|
|
913
951
|
fetchPrivacySettings,
|
|
914
952
|
upsertMessage,
|
|
915
953
|
appPatch,
|
|
916
|
-
fetchUserLid,
|
|
917
954
|
sendPresenceUpdate,
|
|
918
955
|
presenceSubscribe,
|
|
919
956
|
profilePictureUrl,
|
|
920
|
-
onWhatsApp,
|
|
921
957
|
fetchBlocklist,
|
|
922
958
|
fetchStatus,
|
|
923
959
|
fetchDisappearingDuration,
|
|
@@ -926,6 +962,7 @@ const makeChatsSocket = (config) => {
|
|
|
926
962
|
updateProfileStatus,
|
|
927
963
|
updateProfileName,
|
|
928
964
|
updateBlockStatus,
|
|
965
|
+
updateDisableLinkPreviewsPrivacy,
|
|
929
966
|
updateCallPrivacy,
|
|
930
967
|
updateMessagesPrivacy,
|
|
931
968
|
updateLastSeenPrivacy,
|
|
@@ -939,12 +976,16 @@ const makeChatsSocket = (config) => {
|
|
|
939
976
|
resyncAppState,
|
|
940
977
|
chatModify,
|
|
941
978
|
cleanDirtyBits,
|
|
979
|
+
addOrEditContact,
|
|
980
|
+
removeContact,
|
|
942
981
|
addLabel,
|
|
943
982
|
addChatLabel,
|
|
944
983
|
removeChatLabel,
|
|
945
984
|
addMessageLabel,
|
|
946
985
|
removeMessageLabel,
|
|
947
|
-
star
|
|
986
|
+
star,
|
|
987
|
+
addOrEditQuickReply,
|
|
988
|
+
removeQuickReply
|
|
948
989
|
};
|
|
949
990
|
};
|
|
950
|
-
|
|
991
|
+
//# sourceMappingURL=chats.js.map
|