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/Utils/chat-utils.js
CHANGED
|
@@ -1,44 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const expanded = await (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { expandAppStateKeys } from 'whatsapp-rust-bridge';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { aesDecrypt, aesEncrypt, hmacSign } from './crypto.js';
|
|
7
|
+
import { toNumber } from './generics.js';
|
|
8
|
+
import { LT_HASH_ANTI_TAMPERING } from './lt-hash.js';
|
|
9
|
+
import { downloadContentFromMessage } from './messages-media.js';
|
|
10
|
+
import { emitSyncActionResults, processContactAction } from './sync-action-utils.js';
|
|
11
|
+
const mutationKeys = (keydata) => {
|
|
12
|
+
const keys = expandAppStateKeys(keydata);
|
|
14
13
|
return {
|
|
15
|
-
indexKey:
|
|
16
|
-
valueEncryptionKey:
|
|
17
|
-
valueMacKey:
|
|
18
|
-
snapshotMacKey:
|
|
19
|
-
patchMacKey:
|
|
14
|
+
indexKey: keys.indexKey,
|
|
15
|
+
valueEncryptionKey: keys.valueEncryptionKey,
|
|
16
|
+
valueMacKey: keys.valueMacKey,
|
|
17
|
+
snapshotMacKey: keys.snapshotMacKey,
|
|
18
|
+
patchMacKey: keys.patchMacKey
|
|
20
19
|
};
|
|
21
20
|
};
|
|
22
21
|
const generateMac = (operation, data, keyId, key) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const keyData = getKeyData();
|
|
37
|
-
const last = Buffer.alloc(8); // 8 bytes
|
|
38
|
-
last.set([keyData.length], last.length - 1);
|
|
39
|
-
const total = Buffer.concat([keyData, data, last]);
|
|
40
|
-
const hmac = (0, crypto_1.hmacSign)(total, key, 'sha512');
|
|
41
|
-
return hmac.slice(0, 32);
|
|
22
|
+
const opByte = operation === proto.SyncdMutation.SyncdOperation.SET ? 0x01 : 0x02;
|
|
23
|
+
const keyIdBuffer = typeof keyId === 'string' ? Buffer.from(keyId, 'base64') : keyId;
|
|
24
|
+
const keyData = new Uint8Array(1 + keyIdBuffer.length);
|
|
25
|
+
keyData[0] = opByte;
|
|
26
|
+
keyData.set(keyIdBuffer, 1);
|
|
27
|
+
const last = new Uint8Array(8);
|
|
28
|
+
last[7] = keyData.length;
|
|
29
|
+
const total = new Uint8Array(keyData.length + data.length + last.length);
|
|
30
|
+
total.set(keyData, 0);
|
|
31
|
+
total.set(data, keyData.length);
|
|
32
|
+
total.set(last, keyData.length + data.length);
|
|
33
|
+
const hmac = hmacSign(total, key, 'sha512');
|
|
34
|
+
return hmac.subarray(0, 32);
|
|
42
35
|
};
|
|
43
36
|
const to64BitNetworkOrder = (e) => {
|
|
44
37
|
const buff = Buffer.alloc(8);
|
|
@@ -53,75 +46,63 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
53
46
|
mix: ({ indexMac, valueMac, operation }) => {
|
|
54
47
|
const indexMacBase64 = Buffer.from(indexMac).toString('base64');
|
|
55
48
|
const prevOp = indexValueMap[indexMacBase64];
|
|
56
|
-
if (operation ===
|
|
49
|
+
if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
57
50
|
if (!prevOp) {
|
|
58
|
-
throw new
|
|
51
|
+
throw new Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
|
|
59
52
|
}
|
|
60
53
|
// remove from index value mac, since this mutation is erased
|
|
61
54
|
delete indexValueMap[indexMacBase64];
|
|
62
55
|
}
|
|
63
56
|
else {
|
|
64
|
-
addBuffs.push(
|
|
57
|
+
addBuffs.push(valueMac);
|
|
65
58
|
// add this index into the history map
|
|
66
59
|
indexValueMap[indexMacBase64] = { valueMac };
|
|
67
60
|
}
|
|
68
61
|
if (prevOp) {
|
|
69
|
-
subBuffs.push(
|
|
62
|
+
subBuffs.push(prevOp.valueMac);
|
|
70
63
|
}
|
|
71
64
|
},
|
|
72
|
-
finish:
|
|
73
|
-
const
|
|
74
|
-
const result = await lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
75
|
-
const buffer = Buffer.from(result);
|
|
65
|
+
finish: () => {
|
|
66
|
+
const result = LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs);
|
|
76
67
|
return {
|
|
77
|
-
hash:
|
|
68
|
+
hash: Buffer.from(result),
|
|
78
69
|
indexValueMap
|
|
79
70
|
};
|
|
80
71
|
}
|
|
81
72
|
};
|
|
82
73
|
};
|
|
83
74
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
84
|
-
const total = Buffer.concat([
|
|
85
|
-
|
|
86
|
-
to64BitNetworkOrder(version),
|
|
87
|
-
Buffer.from(name, 'utf-8')
|
|
88
|
-
]);
|
|
89
|
-
return (0, crypto_1.hmacSign)(total, key, 'sha256');
|
|
75
|
+
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
76
|
+
return hmacSign(total, key, 'sha256');
|
|
90
77
|
};
|
|
91
78
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
92
|
-
const total = Buffer.concat([
|
|
93
|
-
|
|
94
|
-
...valueMacs,
|
|
95
|
-
to64BitNetworkOrder(version),
|
|
96
|
-
Buffer.from(type, 'utf-8')
|
|
97
|
-
]);
|
|
98
|
-
return (0, crypto_1.hmacSign)(total, key);
|
|
79
|
+
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
80
|
+
return hmacSign(total, key);
|
|
99
81
|
};
|
|
100
|
-
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
101
|
-
|
|
102
|
-
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
82
|
+
export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
83
|
+
export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
103
84
|
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
104
85
|
if (!key) {
|
|
105
|
-
throw new
|
|
86
|
+
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
106
87
|
}
|
|
107
88
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
108
89
|
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
109
90
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
110
|
-
const dataProto =
|
|
91
|
+
const dataProto = proto.SyncActionData.fromObject({
|
|
111
92
|
index: indexBuffer,
|
|
112
93
|
value: syncAction,
|
|
113
94
|
padding: new Uint8Array(0),
|
|
114
95
|
version: apiVersion
|
|
115
96
|
});
|
|
116
|
-
const encoded =
|
|
117
|
-
const keyValue =
|
|
118
|
-
const encValue =
|
|
97
|
+
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
98
|
+
const keyValue = mutationKeys(key.keyData);
|
|
99
|
+
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
119
100
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
120
|
-
const indexMac =
|
|
101
|
+
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
121
102
|
// update LT hash
|
|
122
103
|
const generator = makeLtHashGenerator(state);
|
|
123
104
|
generator.mix({ indexMac, valueMac, operation });
|
|
124
|
-
Object.assign(state,
|
|
105
|
+
Object.assign(state, generator.finish());
|
|
125
106
|
state.version += 1;
|
|
126
107
|
const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
|
|
127
108
|
const patch = {
|
|
@@ -147,33 +128,33 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
147
128
|
state.indexValueMap[base64Index] = { valueMac };
|
|
148
129
|
return { patch, state };
|
|
149
130
|
};
|
|
150
|
-
|
|
151
|
-
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
131
|
+
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
152
132
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
133
|
+
const derivedKeyCache = new Map();
|
|
153
134
|
// indexKey used to HMAC sign record.index.blob
|
|
154
135
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
155
136
|
// the remaining record.value.blob[0:-32] is the mac, it the HMAC sign of key.keyId + decoded proto data + length of bytes in keyId
|
|
156
137
|
for (const msgMutation of msgMutations) {
|
|
157
138
|
// if it's a syncdmutation, get the operation property
|
|
158
139
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
159
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation :
|
|
160
|
-
const record =
|
|
140
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
141
|
+
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
161
142
|
const key = await getKey(record.keyId.id);
|
|
162
|
-
const content =
|
|
163
|
-
const encContent = content.
|
|
164
|
-
const ogValueMac = content.
|
|
143
|
+
const content = record.value.blob;
|
|
144
|
+
const encContent = content.subarray(0, -32);
|
|
145
|
+
const ogValueMac = content.subarray(-32);
|
|
165
146
|
if (validateMacs) {
|
|
166
147
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
167
148
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
168
|
-
throw new
|
|
149
|
+
throw new Boom('HMAC content verification failed');
|
|
169
150
|
}
|
|
170
151
|
}
|
|
171
|
-
const result =
|
|
172
|
-
const syncAction =
|
|
152
|
+
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
153
|
+
const syncAction = proto.SyncActionData.decode(result);
|
|
173
154
|
if (validateMacs) {
|
|
174
|
-
const hmac =
|
|
155
|
+
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
175
156
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
176
|
-
throw new
|
|
157
|
+
throw new Boom('HMAC index verification failed');
|
|
177
158
|
}
|
|
178
159
|
}
|
|
179
160
|
const indexStr = Buffer.from(syncAction.index).toString();
|
|
@@ -184,43 +165,50 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
184
165
|
operation: operation
|
|
185
166
|
});
|
|
186
167
|
}
|
|
187
|
-
return
|
|
168
|
+
return ltGenerator.finish();
|
|
188
169
|
async function getKey(keyId) {
|
|
189
170
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
171
|
+
const cached = derivedKeyCache.get(base64Key);
|
|
172
|
+
if (cached) {
|
|
173
|
+
return cached;
|
|
174
|
+
}
|
|
190
175
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
191
176
|
if (!keyEnc) {
|
|
192
|
-
throw new
|
|
177
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
178
|
+
statusCode: 404,
|
|
179
|
+
data: { msgMutations }
|
|
180
|
+
});
|
|
193
181
|
}
|
|
194
|
-
|
|
182
|
+
const keys = mutationKeys(keyEnc.keyData);
|
|
183
|
+
derivedKeyCache.set(base64Key, keys);
|
|
184
|
+
return keys;
|
|
195
185
|
}
|
|
196
186
|
};
|
|
197
|
-
|
|
198
|
-
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
187
|
+
export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
199
188
|
if (validateMacs) {
|
|
200
189
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
201
190
|
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
202
191
|
if (!mainKeyObj) {
|
|
203
|
-
throw new
|
|
192
|
+
throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
204
193
|
}
|
|
205
|
-
const mainKey =
|
|
194
|
+
const mainKey = mutationKeys(mainKeyObj.keyData);
|
|
206
195
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
207
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs,
|
|
196
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
208
197
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
209
|
-
throw new
|
|
198
|
+
throw new Boom('Invalid patch mac');
|
|
210
199
|
}
|
|
211
200
|
}
|
|
212
|
-
const result = await
|
|
201
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
213
202
|
return result;
|
|
214
203
|
};
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
|
|
204
|
+
export const extractSyncdPatches = async (result, options) => {
|
|
205
|
+
const syncNode = getBinaryNodeChild(result, 'sync');
|
|
206
|
+
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
|
|
219
207
|
const final = {};
|
|
220
208
|
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
221
|
-
const patchesNode =
|
|
222
|
-
const patches =
|
|
223
|
-
const snapshotNode =
|
|
209
|
+
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
210
|
+
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
211
|
+
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
224
212
|
const syncds = [];
|
|
225
213
|
const name = collectionNode.attrs.name;
|
|
226
214
|
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
@@ -229,16 +217,16 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
229
217
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
230
218
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
231
219
|
}
|
|
232
|
-
const blobRef =
|
|
233
|
-
const data = await
|
|
234
|
-
snapshot =
|
|
220
|
+
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
221
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
222
|
+
snapshot = proto.SyncdSnapshot.decode(data);
|
|
235
223
|
}
|
|
236
224
|
for (let { content } of patches) {
|
|
237
225
|
if (content) {
|
|
238
226
|
if (!Buffer.isBuffer(content)) {
|
|
239
227
|
content = Buffer.from(Object.values(content));
|
|
240
228
|
}
|
|
241
|
-
const syncd =
|
|
229
|
+
const syncd = proto.SyncdPatch.decode(content);
|
|
242
230
|
if (!syncd.version) {
|
|
243
231
|
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
244
232
|
}
|
|
@@ -249,32 +237,27 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
249
237
|
}));
|
|
250
238
|
return final;
|
|
251
239
|
};
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
|
|
240
|
+
export const downloadExternalBlob = async (blob, options) => {
|
|
241
|
+
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
|
|
255
242
|
const bufferArray = [];
|
|
256
243
|
for await (const chunk of stream) {
|
|
257
244
|
bufferArray.push(chunk);
|
|
258
245
|
}
|
|
259
246
|
return Buffer.concat(bufferArray);
|
|
260
247
|
};
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
|
|
248
|
+
export const downloadExternalPatch = async (blob, options) => {
|
|
249
|
+
const buffer = await downloadExternalBlob(blob, options);
|
|
250
|
+
const syncData = proto.SyncdMutations.decode(buffer);
|
|
265
251
|
return syncData;
|
|
266
252
|
};
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
newState.version = (0, generics_1.toNumber)(snapshot.version.version);
|
|
253
|
+
export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
254
|
+
const newState = newLTHashState();
|
|
255
|
+
newState.version = toNumber(snapshot.version.version);
|
|
271
256
|
const mutationMap = {};
|
|
272
|
-
const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
var _a;
|
|
277
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
257
|
+
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
258
|
+
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
259
|
+
? mutation => {
|
|
260
|
+
const index = mutation.syncAction.index?.toString();
|
|
278
261
|
mutationMap[index] = mutation;
|
|
279
262
|
}
|
|
280
263
|
: () => { }, validateMacs);
|
|
@@ -284,12 +267,12 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
284
267
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
285
268
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
286
269
|
if (!keyEnc) {
|
|
287
|
-
throw new
|
|
270
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
288
271
|
}
|
|
289
|
-
const result =
|
|
272
|
+
const result = mutationKeys(keyEnc.keyData);
|
|
290
273
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
291
274
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
292
|
-
throw new
|
|
275
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
293
276
|
}
|
|
294
277
|
}
|
|
295
278
|
return {
|
|
@@ -297,9 +280,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
297
280
|
mutationMap
|
|
298
281
|
};
|
|
299
282
|
};
|
|
300
|
-
|
|
301
|
-
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
302
|
-
var _a;
|
|
283
|
+
export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
303
284
|
const newState = {
|
|
304
285
|
...initial,
|
|
305
286
|
indexValueMap: { ...initial.indexValueMap }
|
|
@@ -308,33 +289,32 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
308
289
|
for (const syncd of syncds) {
|
|
309
290
|
const { version, keyId, snapshotMac } = syncd;
|
|
310
291
|
if (syncd.externalMutations) {
|
|
311
|
-
logger
|
|
312
|
-
const ref = await
|
|
313
|
-
logger
|
|
314
|
-
|
|
292
|
+
logger?.trace({ name, version }, 'downloading external patch');
|
|
293
|
+
const ref = await downloadExternalPatch(syncd.externalMutations, options);
|
|
294
|
+
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
|
|
295
|
+
syncd.mutations?.push(...ref.mutations);
|
|
315
296
|
}
|
|
316
|
-
const patchVersion =
|
|
297
|
+
const patchVersion = toNumber(version.version);
|
|
317
298
|
newState.version = patchVersion;
|
|
318
299
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
319
|
-
const decodeResult = await
|
|
300
|
+
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
320
301
|
? mutation => {
|
|
321
|
-
|
|
322
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
302
|
+
const index = mutation.syncAction.index?.toString();
|
|
323
303
|
mutationMap[index] = mutation;
|
|
324
304
|
}
|
|
325
|
-
: (
|
|
305
|
+
: () => { }, true);
|
|
326
306
|
newState.hash = decodeResult.hash;
|
|
327
307
|
newState.indexValueMap = decodeResult.indexValueMap;
|
|
328
308
|
if (validateMacs) {
|
|
329
309
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
330
310
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
331
311
|
if (!keyEnc) {
|
|
332
|
-
throw new
|
|
312
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
333
313
|
}
|
|
334
|
-
const result =
|
|
314
|
+
const result = mutationKeys(keyEnc.keyData);
|
|
335
315
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
336
316
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
337
|
-
throw new
|
|
317
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
338
318
|
}
|
|
339
319
|
}
|
|
340
320
|
// clear memory used up by the mutations
|
|
@@ -342,31 +322,31 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
342
322
|
}
|
|
343
323
|
return { state: newState, mutationMap };
|
|
344
324
|
};
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
325
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
326
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
348
327
|
const getMessageRange = (lastMessages) => {
|
|
349
328
|
let messageRange;
|
|
350
329
|
if (Array.isArray(lastMessages)) {
|
|
351
330
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
352
331
|
messageRange = {
|
|
353
|
-
lastMessageTimestamp: lastMsg
|
|
354
|
-
messages:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
332
|
+
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
333
|
+
messages: lastMessages?.length
|
|
334
|
+
? lastMessages.map(m => {
|
|
335
|
+
if (!m.key?.id || !m.key?.remoteJid) {
|
|
336
|
+
throw new Boom('Incomplete key', { statusCode: 400, data: m });
|
|
337
|
+
}
|
|
338
|
+
if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
339
|
+
throw new Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
|
|
340
|
+
}
|
|
341
|
+
if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
|
|
342
|
+
throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
|
|
343
|
+
}
|
|
344
|
+
if (m.key.participant) {
|
|
345
|
+
m.key.participant = jidNormalizedUser(m.key.participant);
|
|
346
|
+
}
|
|
347
|
+
return m;
|
|
348
|
+
})
|
|
349
|
+
: undefined
|
|
370
350
|
};
|
|
371
351
|
}
|
|
372
352
|
else {
|
|
@@ -435,7 +415,9 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
435
415
|
else if ('clear' in mod) {
|
|
436
416
|
patch = {
|
|
437
417
|
syncAction: {
|
|
438
|
-
clearChatAction: {
|
|
418
|
+
clearChatAction: {
|
|
419
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
420
|
+
}
|
|
439
421
|
},
|
|
440
422
|
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
441
423
|
type: 'regular_high',
|
|
@@ -456,6 +438,28 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
456
438
|
operation: OP.SET
|
|
457
439
|
};
|
|
458
440
|
}
|
|
441
|
+
else if ('contact' in mod) {
|
|
442
|
+
patch = {
|
|
443
|
+
syncAction: {
|
|
444
|
+
contactAction: mod.contact || {}
|
|
445
|
+
},
|
|
446
|
+
index: ['contact', jid],
|
|
447
|
+
type: 'critical_unblock_low',
|
|
448
|
+
apiVersion: 2,
|
|
449
|
+
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
else if ('disableLinkPreviews' in mod) {
|
|
453
|
+
patch = {
|
|
454
|
+
syncAction: {
|
|
455
|
+
privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
|
|
456
|
+
},
|
|
457
|
+
index: ['setting_disableLinkPreviews'],
|
|
458
|
+
type: 'regular',
|
|
459
|
+
apiVersion: 8,
|
|
460
|
+
operation: OP.SET
|
|
461
|
+
};
|
|
462
|
+
}
|
|
459
463
|
else if ('star' in mod) {
|
|
460
464
|
const key = mod.star.messages[0];
|
|
461
465
|
patch = {
|
|
@@ -474,7 +478,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
474
478
|
patch = {
|
|
475
479
|
syncAction: {
|
|
476
480
|
deleteChatAction: {
|
|
477
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
481
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
478
482
|
}
|
|
479
483
|
},
|
|
480
484
|
index: ['deleteChat', jid, '1'],
|
|
@@ -493,7 +497,24 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
493
497
|
index: ['setting_pushName'],
|
|
494
498
|
type: 'critical_block',
|
|
495
499
|
apiVersion: 1,
|
|
496
|
-
operation: OP.SET
|
|
500
|
+
operation: OP.SET
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
else if ('quickReply' in mod) {
|
|
504
|
+
patch = {
|
|
505
|
+
syncAction: {
|
|
506
|
+
quickReplyAction: {
|
|
507
|
+
count: 0,
|
|
508
|
+
deleted: mod.quickReply.deleted || false,
|
|
509
|
+
keywords: [],
|
|
510
|
+
message: mod.quickReply.message || '',
|
|
511
|
+
shortcut: mod.quickReply.shortcut || ''
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
index: ['quick_reply', mod.quickReply.timestamp || String(Math.floor(Date.now() / 1000))],
|
|
515
|
+
type: 'regular',
|
|
516
|
+
apiVersion: 2,
|
|
517
|
+
operation: OP.SET
|
|
497
518
|
};
|
|
498
519
|
}
|
|
499
520
|
else if ('addLabel' in mod) {
|
|
@@ -509,64 +530,57 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
509
530
|
index: ['label_edit', mod.addLabel.id],
|
|
510
531
|
type: 'regular',
|
|
511
532
|
apiVersion: 3,
|
|
512
|
-
operation: OP.SET
|
|
533
|
+
operation: OP.SET
|
|
513
534
|
};
|
|
514
535
|
}
|
|
515
536
|
else if ('addChatLabel' in mod) {
|
|
516
537
|
patch = {
|
|
517
538
|
syncAction: {
|
|
518
539
|
labelAssociationAction: {
|
|
519
|
-
labeled: true
|
|
540
|
+
labeled: true
|
|
520
541
|
}
|
|
521
542
|
},
|
|
522
|
-
index: [
|
|
543
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
523
544
|
type: 'regular',
|
|
524
545
|
apiVersion: 3,
|
|
525
|
-
operation: OP.SET
|
|
546
|
+
operation: OP.SET
|
|
526
547
|
};
|
|
527
548
|
}
|
|
528
549
|
else if ('removeChatLabel' in mod) {
|
|
529
550
|
patch = {
|
|
530
551
|
syncAction: {
|
|
531
552
|
labelAssociationAction: {
|
|
532
|
-
labeled: false
|
|
553
|
+
labeled: false
|
|
533
554
|
}
|
|
534
555
|
},
|
|
535
|
-
index: [
|
|
556
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
536
557
|
type: 'regular',
|
|
537
558
|
apiVersion: 3,
|
|
538
|
-
operation: OP.SET
|
|
559
|
+
operation: OP.SET
|
|
539
560
|
};
|
|
540
561
|
}
|
|
541
562
|
else if ('addMessageLabel' in mod) {
|
|
542
563
|
patch = {
|
|
543
564
|
syncAction: {
|
|
544
565
|
labelAssociationAction: {
|
|
545
|
-
labeled: true
|
|
566
|
+
labeled: true
|
|
546
567
|
}
|
|
547
568
|
},
|
|
548
|
-
index: [
|
|
549
|
-
LabelAssociation_1.LabelAssociationType.Message,
|
|
550
|
-
mod.addMessageLabel.labelId,
|
|
551
|
-
jid,
|
|
552
|
-
mod.addMessageLabel.messageId,
|
|
553
|
-
'0',
|
|
554
|
-
'0'
|
|
555
|
-
],
|
|
569
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
556
570
|
type: 'regular',
|
|
557
571
|
apiVersion: 3,
|
|
558
|
-
operation: OP.SET
|
|
572
|
+
operation: OP.SET
|
|
559
573
|
};
|
|
560
574
|
}
|
|
561
575
|
else if ('removeMessageLabel' in mod) {
|
|
562
576
|
patch = {
|
|
563
577
|
syncAction: {
|
|
564
578
|
labelAssociationAction: {
|
|
565
|
-
labeled: false
|
|
579
|
+
labeled: false
|
|
566
580
|
}
|
|
567
581
|
},
|
|
568
582
|
index: [
|
|
569
|
-
|
|
583
|
+
LabelAssociationType.Message,
|
|
570
584
|
mod.removeMessageLabel.labelId,
|
|
571
585
|
jid,
|
|
572
586
|
mod.removeMessageLabel.messageId,
|
|
@@ -575,34 +589,30 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
575
589
|
],
|
|
576
590
|
type: 'regular',
|
|
577
591
|
apiVersion: 3,
|
|
578
|
-
operation: OP.SET
|
|
592
|
+
operation: OP.SET
|
|
579
593
|
};
|
|
580
594
|
}
|
|
581
595
|
else {
|
|
582
|
-
throw new
|
|
596
|
+
throw new Boom('not supported');
|
|
583
597
|
}
|
|
584
598
|
patch.syncAction.timestamp = Date.now();
|
|
585
599
|
return patch;
|
|
586
600
|
};
|
|
587
|
-
|
|
588
|
-
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
589
|
-
var _a, _b, _c, _d;
|
|
601
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
590
602
|
const isInitialSync = !!initialSyncOpts;
|
|
591
|
-
const accountSettings = initialSyncOpts
|
|
592
|
-
logger
|
|
603
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
604
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
593
605
|
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
594
|
-
if (action
|
|
606
|
+
if (action?.muteAction) {
|
|
595
607
|
ev.emit('chats.update', [
|
|
596
608
|
{
|
|
597
609
|
id,
|
|
598
|
-
muteEndTime:
|
|
599
|
-
? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp)
|
|
600
|
-
: null,
|
|
610
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
601
611
|
conditional: getChatUpdateConditional(id, undefined)
|
|
602
612
|
}
|
|
603
613
|
]);
|
|
604
614
|
}
|
|
605
|
-
else if (
|
|
615
|
+
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
606
616
|
// okay so we've to do some annoying computation here
|
|
607
617
|
// when we're initially syncing the app state
|
|
608
618
|
// there are a few cases we need to handle
|
|
@@ -613,36 +623,38 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
613
623
|
// we compare the timestamp of latest message from the other person to determine this
|
|
614
624
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
615
625
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
616
|
-
const archiveAction = action
|
|
617
|
-
const isArchived = archiveAction
|
|
618
|
-
? archiveAction.archived
|
|
619
|
-
: type === 'archive';
|
|
626
|
+
const archiveAction = action?.archiveChatAction;
|
|
627
|
+
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
620
628
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
621
629
|
// // this only applies for the initial sync
|
|
622
630
|
// if(isInitialSync && !isArchived) {
|
|
623
631
|
// isArchived = false
|
|
624
632
|
// }
|
|
625
|
-
const msgRange = !
|
|
633
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
626
634
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
627
|
-
ev.emit('chats.update', [
|
|
635
|
+
ev.emit('chats.update', [
|
|
636
|
+
{
|
|
628
637
|
id,
|
|
629
638
|
archived: isArchived,
|
|
630
639
|
conditional: getChatUpdateConditional(id, msgRange)
|
|
631
|
-
}
|
|
640
|
+
}
|
|
641
|
+
]);
|
|
632
642
|
}
|
|
633
|
-
else if (action
|
|
643
|
+
else if (action?.markChatAsReadAction) {
|
|
634
644
|
const markReadAction = action.markChatAsReadAction;
|
|
635
645
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
636
646
|
// because the chat is read by default
|
|
637
647
|
// this only applies for the initial sync
|
|
638
648
|
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
639
|
-
ev.emit('chats.update', [
|
|
649
|
+
ev.emit('chats.update', [
|
|
650
|
+
{
|
|
640
651
|
id,
|
|
641
|
-
unreadCount: isNullUpdate ? null : !!
|
|
642
|
-
conditional: getChatUpdateConditional(id, markReadAction
|
|
643
|
-
}
|
|
652
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
653
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
654
|
+
}
|
|
655
|
+
]);
|
|
644
656
|
}
|
|
645
|
-
else if (
|
|
657
|
+
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
646
658
|
ev.emit('messages.delete', {
|
|
647
659
|
keys: [
|
|
648
660
|
{
|
|
@@ -653,32 +665,35 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
653
665
|
]
|
|
654
666
|
});
|
|
655
667
|
}
|
|
656
|
-
else if (action
|
|
657
|
-
|
|
668
|
+
else if (action?.contactAction) {
|
|
669
|
+
const results = processContactAction(action.contactAction, id, logger);
|
|
670
|
+
emitSyncActionResults(ev, results);
|
|
658
671
|
}
|
|
659
|
-
else if (action
|
|
660
|
-
const name =
|
|
661
|
-
if (name &&
|
|
672
|
+
else if (action?.pushNameSetting) {
|
|
673
|
+
const name = action?.pushNameSetting?.name;
|
|
674
|
+
if (name && me?.name !== name) {
|
|
662
675
|
ev.emit('creds.update', { me: { ...me, name } });
|
|
663
676
|
}
|
|
664
677
|
}
|
|
665
|
-
else if (action
|
|
666
|
-
ev.emit('chats.update', [
|
|
678
|
+
else if (action?.pinAction) {
|
|
679
|
+
ev.emit('chats.update', [
|
|
680
|
+
{
|
|
667
681
|
id,
|
|
668
|
-
pinned:
|
|
682
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
669
683
|
conditional: getChatUpdateConditional(id, undefined)
|
|
670
|
-
}
|
|
684
|
+
}
|
|
685
|
+
]);
|
|
671
686
|
}
|
|
672
|
-
else if (action
|
|
687
|
+
else if (action?.unarchiveChatsSetting) {
|
|
673
688
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
674
689
|
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
675
|
-
logger
|
|
690
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
676
691
|
if (accountSettings) {
|
|
677
692
|
accountSettings.unarchiveChats = unarchiveChats;
|
|
678
693
|
}
|
|
679
694
|
}
|
|
680
|
-
else if (
|
|
681
|
-
let starred =
|
|
695
|
+
else if (action?.starAction || type === 'star') {
|
|
696
|
+
let starred = action?.starAction?.starred;
|
|
682
697
|
if (typeof starred !== 'boolean') {
|
|
683
698
|
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
684
699
|
}
|
|
@@ -689,46 +704,98 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
689
704
|
}
|
|
690
705
|
]);
|
|
691
706
|
}
|
|
692
|
-
else if (
|
|
707
|
+
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
693
708
|
if (!isInitialSync) {
|
|
694
709
|
ev.emit('chats.delete', [id]);
|
|
695
710
|
}
|
|
696
711
|
}
|
|
697
|
-
else if (action
|
|
712
|
+
else if (action?.labelEditAction) {
|
|
698
713
|
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
699
714
|
ev.emit('labels.edit', {
|
|
700
|
-
id,
|
|
715
|
+
id: id,
|
|
701
716
|
name: name,
|
|
702
717
|
color: color,
|
|
703
718
|
deleted: deleted,
|
|
704
719
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
705
720
|
});
|
|
706
721
|
}
|
|
707
|
-
else if (action
|
|
722
|
+
else if (action?.labelAssociationAction) {
|
|
708
723
|
ev.emit('labels.association', {
|
|
709
|
-
type: action.labelAssociationAction.labeled
|
|
710
|
-
|
|
711
|
-
: 'remove',
|
|
712
|
-
association: type === LabelAssociation_1.LabelAssociationType.Chat
|
|
724
|
+
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
725
|
+
association: type === LabelAssociationType.Chat
|
|
713
726
|
? {
|
|
714
|
-
type:
|
|
727
|
+
type: LabelAssociationType.Chat,
|
|
715
728
|
chatId: syncAction.index[2],
|
|
716
729
|
labelId: syncAction.index[1]
|
|
717
730
|
}
|
|
718
731
|
: {
|
|
719
|
-
type:
|
|
732
|
+
type: LabelAssociationType.Message,
|
|
720
733
|
chatId: syncAction.index[2],
|
|
721
734
|
messageId: syncAction.index[3],
|
|
722
735
|
labelId: syncAction.index[1]
|
|
723
736
|
}
|
|
724
737
|
});
|
|
725
738
|
}
|
|
739
|
+
else if (action?.localeSetting?.locale) {
|
|
740
|
+
ev.emit('settings.update', { setting: 'locale', value: action.localeSetting.locale });
|
|
741
|
+
}
|
|
742
|
+
else if (action?.timeFormatAction) {
|
|
743
|
+
ev.emit('settings.update', { setting: 'timeFormat', value: action.timeFormatAction });
|
|
744
|
+
}
|
|
745
|
+
else if (action?.pnForLidChatAction) {
|
|
746
|
+
if (action.pnForLidChatAction.pnJid) {
|
|
747
|
+
ev.emit('lid-mapping.update', { lid: id, pn: action.pnForLidChatAction.pnJid });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
else if (action?.privacySettingRelayAllCalls) {
|
|
751
|
+
ev.emit('settings.update', {
|
|
752
|
+
setting: 'privacySettingRelayAllCalls',
|
|
753
|
+
value: action.privacySettingRelayAllCalls
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
else if (action?.statusPrivacy) {
|
|
757
|
+
ev.emit('settings.update', { setting: 'statusPrivacy', value: action.statusPrivacy });
|
|
758
|
+
}
|
|
759
|
+
else if (action?.lockChatAction) {
|
|
760
|
+
ev.emit('chats.lock', { id: id, locked: !!action.lockChatAction.locked });
|
|
761
|
+
}
|
|
762
|
+
else if (action?.privacySettingDisableLinkPreviewsAction) {
|
|
763
|
+
ev.emit('settings.update', {
|
|
764
|
+
setting: 'disableLinkPreviews',
|
|
765
|
+
value: action.privacySettingDisableLinkPreviewsAction
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
else if (action?.notificationActivitySettingAction?.notificationActivitySetting) {
|
|
769
|
+
ev.emit('settings.update', {
|
|
770
|
+
setting: 'notificationActivitySetting',
|
|
771
|
+
value: action.notificationActivitySettingAction.notificationActivitySetting
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
else if (action?.lidContactAction) {
|
|
775
|
+
ev.emit('contacts.upsert', [
|
|
776
|
+
{
|
|
777
|
+
id: id,
|
|
778
|
+
name: action.lidContactAction.fullName ||
|
|
779
|
+
action.lidContactAction.firstName ||
|
|
780
|
+
action.lidContactAction.username ||
|
|
781
|
+
undefined,
|
|
782
|
+
lid: id,
|
|
783
|
+
phoneNumber: undefined
|
|
784
|
+
}
|
|
785
|
+
]);
|
|
786
|
+
}
|
|
787
|
+
else if (action?.privacySettingChannelsPersonalisedRecommendationAction) {
|
|
788
|
+
ev.emit('settings.update', {
|
|
789
|
+
setting: 'channelsPersonalisedRecommendation',
|
|
790
|
+
value: action.privacySettingChannelsPersonalisedRecommendationAction
|
|
791
|
+
});
|
|
792
|
+
}
|
|
726
793
|
else {
|
|
727
|
-
logger
|
|
794
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
728
795
|
}
|
|
729
796
|
function getChatUpdateConditional(id, msgRange) {
|
|
730
797
|
return isInitialSync
|
|
731
|
-
?
|
|
798
|
+
? data => {
|
|
732
799
|
const chat = data.historySets.chats[id] || data.chatUpserts[id];
|
|
733
800
|
if (chat) {
|
|
734
801
|
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
|
@@ -737,9 +804,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
737
804
|
: undefined;
|
|
738
805
|
}
|
|
739
806
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
740
|
-
const lastMsgTimestamp = Number(
|
|
741
|
-
const chatLastMsgTimestamp = Number(
|
|
807
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
808
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
742
809
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
743
810
|
}
|
|
744
811
|
};
|
|
745
|
-
|
|
812
|
+
//# sourceMappingURL=chat-utils.js.map
|