zapo-js 0.3.0 → 1.0.0
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 +97 -177
- package/dist/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/appstate/index.js +7 -6
- package/dist/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -53
- package/dist/appstate/utils.js +16 -0
- package/dist/appstate-spec.js +89 -0
- package/dist/auth/WaAuthClient.js +100 -5
- package/dist/auth/credentials-flow.js +19 -7
- package/dist/auth/pairing/WaPairingFlow.js +33 -24
- package/dist/auth/pairing/pairing-code-crypto.js +16 -18
- package/dist/client/WaClient.js +342 -473
- package/dist/client/WaClientFactory.js +279 -78
- package/dist/client/connection/WaConnectionManager.js +28 -11
- package/dist/client/coordinators/WaAbPropsCoordinator.js +1 -2
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +663 -143
- package/dist/client/coordinators/WaBotCoordinator.js +345 -0
- package/dist/client/coordinators/WaBroadcastListCoordinator.js +20 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +81 -171
- package/dist/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +529 -52
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +97 -12
- package/dist/client/coordinators/WaLowLevelCoordinator.js +41 -0
- package/dist/client/coordinators/WaMessageCoordinator.js +365 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +682 -204
- package/dist/client/coordinators/WaNewsletterCoordinator.js +18 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +17 -4
- package/dist/client/coordinators/WaPresenceCoordinator.js +21 -0
- package/dist/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/client/coordinators/WaProfileCoordinator.js +220 -49
- package/dist/client/coordinators/WaRetryCoordinator.js +256 -125
- package/dist/client/coordinators/WaStatusCoordinator.js +49 -0
- package/dist/client/coordinators/WaStreamControlCoordinator.js +6 -6
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/client/events/appstate-mutation.js +133 -0
- package/dist/client/events/business.js +375 -0
- package/dist/client/events/call.js +58 -0
- package/dist/client/events/chatstate.js +23 -0
- package/dist/client/events/devices.js +15 -16
- package/dist/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/client/events/group.js +13 -24
- package/dist/client/events/identity.js +2 -1
- package/dist/client/events/incoming.js +502 -0
- package/dist/client/events/mex-notification.js +181 -0
- package/dist/client/events/picture.js +33 -0
- package/dist/client/events/presence.js +44 -0
- package/dist/client/events/receipt.js +26 -0
- package/dist/client/media.js +161 -4
- package/dist/client/messaging/fanout.js +9 -10
- package/dist/client/messaging/{participants.js → group-metadata.js} +73 -35
- package/dist/client/messaging/ignore-key.js +132 -0
- package/dist/client/messaging/key-protocol.js +3 -17
- package/dist/client/messaging/link-preview.js +159 -0
- package/dist/client/messaging/messages.js +671 -0
- package/dist/client/newsletter/admin.js +165 -0
- package/dist/client/newsletter/content.js +253 -0
- package/dist/client/newsletter/discovery.js +115 -0
- package/dist/client/newsletter/messaging.js +197 -0
- package/dist/client/newsletter/mex.js +41 -0
- package/dist/client/newsletter/parse.js +217 -0
- package/dist/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/client/{history-sync.js → persistence/history-sync.js} +125 -18
- package/dist/client/persistence/mailbox.js +104 -0
- package/dist/client/tokens/cs-token.js +11 -17
- package/dist/crypto/core/hkdf.js +12 -12
- package/dist/crypto/core/index.js +6 -8
- package/dist/crypto/core/keys.js +1 -8
- package/dist/crypto/core/nonce.js +12 -12
- package/dist/crypto/core/primitives.js +123 -93
- package/dist/crypto/core/random.js +6 -0
- package/dist/crypto/core/xeddsa.js +11 -9
- package/dist/crypto/curves/Ed25519.js +32 -21
- package/dist/crypto/curves/X25519.js +70 -34
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/crypto/math/constants.js +1 -2
- package/dist/crypto/math/mod.js +0 -33
- package/dist/esm/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/esm/appstate/index.js +5 -5
- package/dist/esm/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/esm/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/esm/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -52
- package/dist/esm/appstate/utils.js +16 -0
- package/dist/esm/appstate-spec.js +79 -0
- package/dist/esm/auth/WaAuthClient.js +100 -5
- package/dist/esm/auth/credentials-flow.js +18 -6
- package/dist/esm/auth/pairing/WaPairingFlow.js +34 -25
- package/dist/esm/auth/pairing/pairing-code-crypto.js +12 -14
- package/dist/esm/client/WaClient.js +345 -476
- package/dist/esm/client/WaClientFactory.js +280 -79
- package/dist/esm/client/connection/WaConnectionManager.js +28 -11
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +2 -3
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +665 -145
- package/dist/esm/client/coordinators/WaBotCoordinator.js +342 -0
- package/dist/esm/client/coordinators/WaBroadcastListCoordinator.js +17 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +79 -169
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +532 -55
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +98 -13
- package/dist/esm/client/coordinators/WaLowLevelCoordinator.js +38 -0
- package/dist/esm/client/coordinators/WaMessageCoordinator.js +361 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +686 -208
- package/dist/esm/client/coordinators/WaNewsletterCoordinator.js +13 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +18 -5
- package/dist/esm/client/coordinators/WaPresenceCoordinator.js +18 -0
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +223 -52
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +258 -127
- package/dist/esm/client/coordinators/WaStatusCoordinator.js +46 -0
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +6 -6
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/esm/client/events/appstate-mutation.js +130 -0
- package/dist/esm/client/events/business.js +370 -0
- package/dist/esm/client/events/call.js +55 -0
- package/dist/esm/client/events/chatstate.js +20 -0
- package/dist/esm/client/events/devices.js +15 -16
- package/dist/esm/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/esm/client/events/group.js +14 -25
- package/dist/esm/client/events/identity.js +2 -1
- package/dist/esm/client/events/incoming.js +487 -0
- package/dist/esm/client/events/mex-notification.js +178 -0
- package/dist/esm/client/events/picture.js +30 -0
- package/dist/esm/client/events/presence.js +41 -0
- package/dist/esm/client/events/receipt.js +23 -0
- package/dist/esm/client/media.js +156 -6
- package/dist/esm/client/messaging/fanout.js +10 -11
- package/dist/esm/client/messaging/{participants.js → group-metadata.js} +72 -34
- package/dist/esm/client/messaging/ignore-key.js +126 -0
- package/dist/esm/client/messaging/key-protocol.js +3 -17
- package/dist/esm/client/messaging/link-preview.js +156 -0
- package/dist/esm/client/messaging/messages.js +667 -0
- package/dist/esm/client/newsletter/admin.js +162 -0
- package/dist/esm/client/newsletter/content.js +249 -0
- package/dist/esm/client/newsletter/discovery.js +112 -0
- package/dist/esm/client/newsletter/messaging.js +194 -0
- package/dist/esm/client/newsletter/mex.js +37 -0
- package/dist/esm/client/newsletter/parse.js +200 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/esm/client/{history-sync.js → persistence/history-sync.js} +124 -18
- package/dist/esm/client/persistence/mailbox.js +101 -0
- package/dist/esm/client/tokens/cs-token.js +12 -18
- package/dist/esm/crypto/core/hkdf.js +14 -14
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -7
- package/dist/esm/crypto/core/nonce.js +11 -11
- package/dist/esm/crypto/core/primitives.js +121 -88
- package/dist/esm/crypto/core/random.js +6 -0
- package/dist/esm/crypto/core/xeddsa.js +11 -9
- package/dist/esm/crypto/curves/Ed25519.js +35 -24
- package/dist/esm/crypto/curves/X25519.js +72 -36
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/crypto/math/constants.js +1 -2
- package/dist/esm/crypto/math/mod.js +0 -32
- package/dist/esm/index.js +7 -2
- package/dist/esm/infra/log/ConsoleLogger.js +30 -6
- package/dist/esm/infra/log/PinoLogger.js +64 -0
- package/dist/esm/infra/log/types.js +4 -2
- package/dist/esm/infra/perf/BackgroundQueue.js +55 -13
- package/dist/esm/media/constants.js +33 -2
- package/dist/esm/media/crypto/WaMediaCrypto.js +374 -0
- package/dist/esm/media/index.js +4 -3
- package/dist/esm/media/sticker/sticker-pack.js +133 -0
- package/dist/esm/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/esm/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/esm/message/WaMessageClient.js +46 -15
- package/dist/esm/message/addons/link-preview/builder.js +36 -0
- package/dist/esm/message/addons/link-preview/detect.js +55 -0
- package/dist/esm/message/addons/link-preview/fetcher.js +391 -0
- package/dist/esm/message/addons/link-preview/types.js +1 -0
- package/dist/esm/message/context-info.js +123 -0
- package/dist/esm/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/esm/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/esm/message/crypto/phash.js +133 -0
- package/dist/esm/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/esm/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/esm/message/{content.js → encode/content.js} +176 -7
- package/dist/esm/message/encode/media-payload.js +42 -0
- package/dist/esm/message/{padding.js → encode/padding.js} +9 -3
- package/dist/esm/message/index.js +2 -2
- package/dist/esm/message/kinds/bot.js +111 -0
- package/dist/esm/message/kinds/newsletter.js +244 -0
- package/dist/esm/message/kinds/sticker-pack.js +29 -0
- package/dist/esm/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/esm/message/{incoming.js → primitives/incoming.js} +215 -31
- package/dist/esm/message/primitives/peer-data-operation.js +93 -0
- package/dist/esm/mex.js +1 -0
- package/dist/esm/protocol/abprops.js +10 -0
- package/dist/esm/protocol/appstate.js +6 -30
- package/dist/esm/protocol/auth.js +3 -2
- package/dist/esm/protocol/bot.js +77 -0
- package/dist/esm/protocol/browser.js +8 -0
- package/dist/esm/protocol/business.js +19 -0
- package/dist/esm/protocol/call.js +48 -0
- package/dist/esm/protocol/constants.js +8 -2
- package/dist/esm/protocol/defaults.js +3 -0
- package/dist/esm/protocol/index.js +1 -1
- package/dist/esm/protocol/jid.js +102 -5
- package/dist/esm/protocol/media.js +25 -12
- package/dist/esm/protocol/message.js +4 -1
- package/dist/esm/protocol/newsletter.js +61 -0
- package/dist/esm/protocol/nodes.js +22 -2
- package/dist/esm/protocol/notification.js +18 -2
- package/dist/esm/protocol/presence.js +13 -0
- package/dist/esm/protocol/status.js +6 -0
- package/dist/esm/retry/codec.js +5 -0
- package/dist/esm/retry/parse.js +20 -38
- package/dist/esm/retry/reason.js +5 -0
- package/dist/esm/retry/replay.js +131 -37
- package/dist/esm/retry/tracker.js +4 -8
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +66 -19
- package/dist/esm/signal/api/SignalDigestSyncApi.js +7 -2
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +24 -63
- package/dist/esm/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/esm/signal/api/SignalSessionSyncApi.js +23 -51
- package/dist/esm/signal/api/codec.js +52 -1
- package/dist/esm/signal/api/prekeys.js +4 -0
- package/dist/esm/signal/{crypto → attestation}/WaAdvSignature.js +5 -6
- package/dist/esm/signal/constants.js +3 -0
- package/dist/esm/signal/encoding.js +6 -289
- package/dist/esm/signal/group/SenderKeyChain.js +18 -33
- package/dist/esm/signal/group/SenderKeyManager.js +25 -8
- package/dist/esm/signal/group/encoding.js +96 -0
- package/dist/esm/signal/index.js +4 -1
- package/dist/esm/signal/registration/encoding.js +34 -0
- package/dist/esm/signal/registration/keygen.js +10 -0
- package/dist/esm/signal/registration/utils.js +6 -0
- package/dist/esm/signal/session/SignalProtocol.js +113 -11
- package/dist/esm/signal/session/SignalRatchet.js +29 -58
- package/dist/esm/signal/session/SignalSession.js +7 -14
- package/dist/esm/signal/session/encoding.js +173 -0
- package/dist/esm/signal/session/resolver.js +139 -30
- package/dist/esm/store/cache/identity.cache.js +75 -0
- package/dist/esm/store/cache/privacy-token.cache.js +57 -0
- package/dist/esm/store/cache/sender-key.cache.js +101 -0
- package/dist/esm/store/cache/session.cache.js +92 -0
- package/dist/esm/store/contracts/group-metadata.store.js +1 -0
- package/dist/esm/store/createStore.js +91 -37
- package/dist/esm/store/index.js +15 -14
- package/dist/esm/store/locks/contact.lock.js +1 -0
- package/dist/esm/store/locks/device-list.lock.js +1 -0
- package/dist/esm/store/locks/group-metadata.lock.js +20 -0
- package/dist/esm/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/esm/store/memory/auth.store.js +24 -0
- package/dist/esm/store/memory/contact.store.js +79 -0
- package/dist/esm/store/memory/device-list.store.js +103 -0
- package/dist/esm/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +22 -13
- package/dist/esm/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/esm/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/esm/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/esm/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/esm/store/noop.store.js +6 -4
- package/dist/esm/transport/WaComms.js +14 -5
- package/dist/esm/transport/WaWebSocket.js +32 -8
- package/dist/esm/transport/binary/constants.js +10 -4
- package/dist/esm/transport/binary/decoder.js +21 -15
- package/dist/esm/transport/binary/encoder.js +96 -21
- package/dist/esm/transport/binary/tokens.js +12 -12
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/esm/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/esm/transport/node/WaNodeTransport.js +13 -0
- package/dist/esm/transport/node/builders/abprops.js +2 -2
- package/dist/esm/transport/node/builders/account-sync.js +7 -15
- package/dist/esm/transport/node/builders/bot.js +38 -0
- package/dist/esm/transport/node/builders/business.js +30 -30
- package/dist/esm/transport/node/builders/chatstate.js +28 -0
- package/dist/esm/transport/node/builders/community.js +53 -0
- package/dist/esm/transport/node/builders/device.js +2 -2
- package/dist/esm/transport/node/builders/email.js +6 -5
- package/dist/esm/transport/node/builders/global.js +1 -1
- package/dist/esm/transport/node/builders/group.js +114 -4
- package/dist/esm/transport/node/builders/media.js +2 -2
- package/dist/esm/transport/node/builders/message.js +83 -49
- package/dist/esm/transport/node/builders/newsletter.js +176 -0
- package/dist/esm/transport/node/builders/passive.js +7 -0
- package/dist/esm/transport/node/builders/prekeys.js +4 -4
- package/dist/esm/transport/node/builders/presence.js +27 -1
- package/dist/esm/transport/node/builders/privacy-token.js +2 -2
- package/dist/esm/transport/node/builders/privacy.js +6 -6
- package/dist/esm/transport/node/builders/profile.js +28 -8
- package/dist/esm/transport/node/builders/tos.js +58 -0
- package/dist/esm/transport/node/builders/usync.js +51 -2
- package/dist/esm/transport/node/helpers.js +3 -1
- package/dist/esm/transport/node/mex/argo-decoder.js +2 -2
- package/dist/esm/transport/node/mex/client.js +22 -0
- package/dist/esm/transport/node/query.js +17 -0
- package/dist/esm/transport/node/usync.js +12 -0
- package/dist/esm/transport/noise/WaClientPayload.js +8 -8
- package/dist/esm/transport/noise/WaMobileClientPayload.js +5 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +5 -0
- package/dist/esm/transport/noise/WaNoiseHandshake.js +27 -25
- package/dist/esm/transport/noise/WaNoiseSession.js +39 -59
- package/dist/esm/transport/noise/WaNoiseSocket.js +19 -13
- package/dist/esm/transport/noise/constants.js +0 -1
- package/dist/esm/transport/proxy.js +5 -0
- package/dist/esm/transport/stream/parse.js +3 -7
- package/dist/esm/transport/wa-web-version-fetcher.js +91 -0
- package/dist/esm/util/async.js +4 -0
- package/dist/esm/util/bytes.js +37 -2
- package/dist/esm/util/clock.js +15 -0
- package/dist/esm/util/coercion.js +45 -3
- package/dist/esm/util/collections.js +11 -0
- package/dist/esm/util/index.js +2 -2
- package/dist/esm/util/primitives.js +19 -0
- package/dist/esm/util/runtime.js +5 -0
- package/dist/esm/version-spec.js +1 -0
- package/dist/index.js +31 -1
- package/dist/infra/log/ConsoleLogger.js +30 -6
- package/dist/infra/log/PinoLogger.js +64 -0
- package/dist/infra/log/types.js +4 -2
- package/dist/infra/perf/BackgroundQueue.js +55 -13
- package/dist/media/constants.js +34 -3
- package/dist/media/crypto/WaMediaCrypto.js +378 -0
- package/dist/media/index.js +9 -4
- package/dist/media/sticker/sticker-pack.js +136 -0
- package/dist/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/message/WaMessageClient.js +46 -15
- package/dist/message/addons/link-preview/builder.js +39 -0
- package/dist/message/addons/link-preview/detect.js +58 -0
- package/dist/message/addons/link-preview/fetcher.js +394 -0
- package/dist/message/addons/link-preview/types.js +2 -0
- package/dist/message/context-info.js +129 -0
- package/dist/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/message/crypto/phash.js +136 -0
- package/dist/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/message/{content.js → encode/content.js} +192 -7
- package/dist/message/encode/media-payload.js +45 -0
- package/dist/message/{padding.js → encode/padding.js} +9 -3
- package/dist/message/index.js +2 -2
- package/dist/message/kinds/bot.js +120 -0
- package/dist/message/kinds/newsletter.js +248 -0
- package/dist/message/kinds/sticker-pack.js +34 -0
- package/dist/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/message/{incoming.js → primitives/incoming.js} +216 -31
- package/dist/message/primitives/peer-data-operation.js +96 -0
- package/dist/mex.js +6 -0
- package/dist/proto.js +1 -1
- package/dist/protocol/abprops.js +10 -0
- package/dist/protocol/appstate.js +7 -31
- package/dist/protocol/auth.js +3 -2
- package/dist/protocol/bot.js +81 -0
- package/dist/protocol/browser.js +8 -0
- package/dist/protocol/business.js +22 -0
- package/dist/protocol/call.js +51 -0
- package/dist/protocol/constants.js +39 -3
- package/dist/protocol/defaults.js +3 -0
- package/dist/protocol/index.js +12 -3
- package/dist/protocol/jid.js +107 -5
- package/dist/protocol/media.js +25 -12
- package/dist/protocol/message.js +4 -1
- package/dist/protocol/newsletter.js +64 -0
- package/dist/protocol/nodes.js +22 -2
- package/dist/protocol/notification.js +19 -3
- package/dist/protocol/presence.js +16 -0
- package/dist/protocol/status.js +9 -0
- package/dist/retry/codec.js +5 -0
- package/dist/retry/parse.js +16 -34
- package/dist/retry/reason.js +5 -0
- package/dist/retry/replay.js +129 -35
- package/dist/retry/tracker.js +3 -7
- package/dist/signal/api/SignalDeviceSyncApi.js +64 -17
- package/dist/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +21 -60
- package/dist/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/signal/api/SignalSessionSyncApi.js +20 -48
- package/dist/signal/api/codec.js +52 -0
- package/dist/signal/api/prekeys.js +4 -0
- package/dist/signal/{crypto → attestation}/WaAdvSignature.js +5 -7
- package/dist/signal/constants.js +4 -1
- package/dist/signal/encoding.js +5 -303
- package/dist/signal/group/SenderKeyChain.js +17 -32
- package/dist/signal/group/SenderKeyManager.js +24 -7
- package/dist/signal/group/encoding.js +101 -0
- package/dist/signal/index.js +13 -10
- package/dist/signal/registration/encoding.js +39 -0
- package/dist/signal/registration/keygen.js +10 -0
- package/dist/signal/registration/utils.js +6 -0
- package/dist/signal/session/SignalProtocol.js +112 -10
- package/dist/signal/session/SignalRatchet.js +24 -54
- package/dist/signal/session/SignalSession.js +6 -14
- package/dist/signal/session/encoding.js +183 -0
- package/dist/signal/session/resolver.js +139 -30
- package/dist/store/cache/identity.cache.js +78 -0
- package/dist/store/cache/privacy-token.cache.js +60 -0
- package/dist/store/cache/sender-key.cache.js +104 -0
- package/dist/store/cache/session.cache.js +95 -0
- package/dist/store/contracts/group-metadata.store.js +2 -0
- package/dist/store/createStore.js +90 -36
- package/dist/store/index.js +18 -16
- package/dist/store/locks/contact.lock.js +1 -0
- package/dist/store/locks/device-list.lock.js +1 -0
- package/dist/store/locks/group-metadata.lock.js +23 -0
- package/dist/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/store/memory/auth.store.js +28 -0
- package/dist/store/memory/contact.store.js +83 -0
- package/dist/store/memory/device-list.store.js +107 -0
- package/dist/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +24 -15
- package/dist/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/store/noop.store.js +7 -5
- package/dist/transport/WaComms.js +14 -5
- package/dist/transport/WaWebSocket.js +32 -8
- package/dist/transport/binary/constants.js +11 -5
- package/dist/transport/binary/decoder.js +24 -18
- package/dist/transport/binary/encoder.js +109 -34
- package/dist/transport/binary/tokens.js +12 -12
- package/dist/transport/index.js +3 -1
- package/dist/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/transport/node/WaNodeTransport.js +13 -0
- package/dist/transport/node/builders/abprops.js +1 -1
- package/dist/transport/node/builders/account-sync.js +7 -16
- package/dist/transport/node/builders/bot.js +43 -0
- package/dist/transport/node/builders/business.js +31 -31
- package/dist/transport/node/builders/chatstate.js +31 -0
- package/dist/transport/node/builders/community.js +59 -0
- package/dist/transport/node/builders/device.js +1 -1
- package/dist/transport/node/builders/email.js +6 -5
- package/dist/transport/node/builders/global.js +1 -1
- package/dist/transport/node/builders/group.js +121 -3
- package/dist/transport/node/builders/media.js +1 -1
- package/dist/transport/node/builders/message.js +84 -49
- package/dist/transport/node/builders/newsletter.js +183 -0
- package/dist/transport/node/builders/passive.js +10 -0
- package/dist/transport/node/builders/prekeys.js +3 -3
- package/dist/transport/node/builders/presence.js +28 -1
- package/dist/transport/node/builders/privacy-token.js +1 -1
- package/dist/transport/node/builders/privacy.js +5 -5
- package/dist/transport/node/builders/profile.js +30 -7
- package/dist/transport/node/builders/tos.js +63 -0
- package/dist/transport/node/builders/usync.js +52 -1
- package/dist/transport/node/helpers.js +2 -1
- package/dist/transport/node/mex/argo-decoder.js +2 -2
- package/dist/transport/node/mex/client.js +23 -0
- package/dist/transport/node/query.js +17 -0
- package/dist/transport/node/usync.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +8 -8
- package/dist/transport/noise/WaMobileClientPayload.js +5 -0
- package/dist/transport/noise/WaNoiseCert.js +5 -0
- package/dist/transport/noise/WaNoiseHandshake.js +25 -23
- package/dist/transport/noise/WaNoiseSession.js +39 -59
- package/dist/transport/noise/WaNoiseSocket.js +18 -12
- package/dist/transport/noise/constants.js +1 -2
- package/dist/transport/proxy.js +5 -0
- package/dist/transport/stream/parse.js +3 -7
- package/dist/transport/wa-web-version-fetcher.js +94 -0
- package/dist/types/appstate/constants.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateCrypto.d.ts → crypto/WaAppStateCrypto.d.ts} +26 -9
- package/dist/types/appstate/index.d.ts +5 -5
- package/dist/types/appstate/{encoding.d.ts → parsers/encoding.d.ts} +8 -1
- package/dist/types/appstate/{response-parser.d.ts → parsers/response-parser.d.ts} +13 -3
- package/dist/types/appstate/sync/WaAppStateSyncClient.d.ts +105 -0
- package/dist/types/appstate/utils.d.ts +17 -1
- package/dist/types/appstate-spec.d.ts +24 -0
- package/dist/types/auth/WaAuthClient.d.ts +89 -3
- package/dist/types/auth/credentials-flow.d.ts +4 -3
- package/dist/types/auth/pairing/pairing-code-crypto.d.ts +0 -1
- package/dist/types/auth/types.d.ts +48 -1
- package/dist/types/client/WaClient.d.ts +178 -71
- package/dist/types/client/WaClientFactory.d.ts +30 -5
- package/dist/types/client/connection/WaConnectionManager.d.ts +4 -2
- package/dist/types/client/connection/WaReceiptQueue.d.ts +1 -1
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +215 -5
- package/dist/types/client/coordinators/WaBotCoordinator.d.ts +117 -0
- package/dist/types/client/coordinators/WaBroadcastListCoordinator.d.ts +39 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +44 -43
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +16 -0
- package/dist/types/client/coordinators/WaGroupCoordinator.d.ts +311 -9
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +11 -4
- package/dist/types/client/coordinators/WaLowLevelCoordinator.d.ts +47 -0
- package/dist/types/client/coordinators/WaMessageCoordinator.d.ts +232 -0
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +54 -31
- package/dist/types/client/coordinators/WaNewsletterCoordinator.d.ts +13 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -3
- package/dist/types/client/coordinators/WaPresenceCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +113 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +19 -17
- package/dist/types/client/coordinators/WaStatusCoordinator.d.ts +42 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +5 -1
- package/dist/types/client/events/abprops.d.ts +2 -1
- package/dist/types/client/events/appstate-mutation.d.ts +3 -0
- package/dist/types/client/events/business.d.ts +10 -0
- package/dist/types/client/events/call.d.ts +31 -0
- package/dist/types/client/events/chatstate.d.ts +9 -0
- package/dist/types/client/events/devices.d.ts +5 -4
- package/dist/types/client/{dirty.d.ts → events/dirty.d.ts} +4 -3
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +2 -1
- package/dist/types/client/{incoming.d.ts → events/incoming.d.ts} +27 -4
- package/dist/types/client/events/mex-notification.d.ts +6 -0
- package/dist/types/client/events/picture.d.ts +8 -0
- package/dist/types/client/events/presence.d.ts +28 -0
- package/dist/types/client/events/receipt.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +4 -3
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/media.d.ts +35 -1
- package/dist/types/client/messaging/fanout.d.ts +2 -2
- package/dist/types/client/messaging/group-metadata.d.ts +19 -0
- package/dist/types/client/messaging/ignore-key.d.ts +11 -0
- package/dist/types/client/messaging/key-protocol.d.ts +9 -7
- package/dist/types/client/messaging/link-preview.d.ts +19 -0
- package/dist/types/client/messaging/messages.d.ts +28 -0
- package/dist/types/client/newsletter/admin.d.ts +71 -0
- package/dist/types/client/newsletter/content.d.ts +42 -0
- package/dist/types/client/newsletter/discovery.d.ts +33 -0
- package/dist/types/client/newsletter/messaging.d.ts +66 -0
- package/dist/types/client/newsletter/mex.d.ts +14 -0
- package/dist/types/client/newsletter/parse.d.ts +19 -0
- package/dist/types/client/newsletter/types.d.ts +190 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +12 -1
- package/dist/types/client/persistence/history-sync.d.ts +29 -0
- package/dist/types/client/{mailbox.d.ts → persistence/mailbox.d.ts} +4 -4
- package/dist/types/client/tokens/cs-token.d.ts +1 -3
- package/dist/types/client/types.d.ts +843 -71
- package/dist/types/crypto/core/hkdf.d.ts +10 -2
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/keys.d.ts +0 -4
- package/dist/types/crypto/core/nonce.d.ts +4 -5
- package/dist/types/crypto/core/primitives.d.ts +31 -20
- package/dist/types/crypto/core/random.d.ts +6 -0
- package/dist/types/crypto/core/xeddsa.d.ts +9 -0
- package/dist/types/crypto/curves/Ed25519.d.ts +7 -1
- package/dist/types/crypto/curves/X25519.d.ts +20 -1
- package/dist/types/crypto/curves/constants.d.ts +4 -3
- package/dist/types/crypto/curves/types.d.ts +0 -5
- package/dist/types/crypto/math/constants.d.ts +0 -1
- package/dist/types/crypto/math/mod.d.ts +0 -1
- package/dist/types/index.d.ts +32 -6
- package/dist/types/infra/log/ConsoleLogger.d.ts +18 -1
- package/dist/types/infra/log/PinoLogger.d.ts +55 -1
- package/dist/types/infra/log/types.d.ts +6 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +19 -0
- package/dist/types/media/constants.d.ts +7 -2
- package/dist/types/media/crypto/WaMediaCrypto.d.ts +59 -0
- package/dist/types/media/index.d.ts +7 -5
- package/dist/types/media/processor.d.ts +27 -5
- package/dist/types/media/sticker/sticker-pack.d.ts +6 -0
- package/dist/types/media/{WaMediaTransferClient.d.ts → transfer/WaMediaTransferClient.d.ts} +30 -1
- package/dist/types/media/transfer/conn.d.ts +7 -0
- package/dist/types/media/types.d.ts +1 -2
- package/dist/types/message/WaMessageClient.d.ts +14 -0
- package/dist/types/message/addons/link-preview/builder.d.ts +13 -0
- package/dist/types/message/addons/link-preview/detect.d.ts +5 -0
- package/dist/types/message/addons/link-preview/fetcher.d.ts +13 -0
- package/dist/types/message/addons/link-preview/types.d.ts +51 -0
- package/dist/types/message/context-info.d.ts +66 -0
- package/dist/types/message/{addon-crypto.d.ts → crypto/addon-crypto.d.ts} +27 -5
- package/dist/types/message/{icdc.d.ts → crypto/icdc.d.ts} +4 -4
- package/dist/types/message/{phash.d.ts → crypto/phash.d.ts} +1 -1
- package/dist/types/message/{reporting-token.d.ts → crypto/reporting-token.d.ts} +2 -2
- package/dist/types/message/{use-case-secret.d.ts → crypto/use-case-secret.d.ts} +17 -1
- package/dist/types/message/encode/content.d.ts +43 -0
- package/dist/types/message/{device-sent.d.ts → encode/device-sent.d.ts} +1 -1
- package/dist/types/message/encode/media-payload.d.ts +12 -0
- package/dist/types/message/index.d.ts +2 -2
- package/dist/types/message/kinds/bot.d.ts +31 -0
- package/dist/types/message/kinds/newsletter.d.ts +12 -0
- package/dist/types/message/kinds/sticker-pack.d.ts +6 -0
- package/dist/types/message/{ack.d.ts → primitives/ack.d.ts} +1 -1
- package/dist/types/message/primitives/incoming.d.ts +21 -0
- package/dist/types/message/primitives/peer-data-operation.d.ts +23 -0
- package/dist/types/message/types.d.ts +208 -10
- package/dist/types/mex.d.ts +2 -0
- package/dist/types/proto.d.ts +2 -2
- package/dist/types/protocol/abprops.d.ts +9 -0
- package/dist/types/protocol/appstate.d.ts +4 -49
- package/dist/types/protocol/auth.d.ts +2 -2
- package/dist/types/protocol/bot.d.ts +45 -0
- package/dist/types/protocol/browser.d.ts +8 -0
- package/dist/types/protocol/business.d.ts +21 -0
- package/dist/types/protocol/call.d.ts +44 -0
- package/dist/types/protocol/constants.d.ts +16 -3
- package/dist/types/protocol/defaults.d.ts +3 -0
- package/dist/types/protocol/group.d.ts +1 -1
- package/dist/types/protocol/index.d.ts +2 -1
- package/dist/types/protocol/jid.d.ts +78 -0
- package/dist/types/protocol/media.d.ts +21 -13
- package/dist/types/protocol/message.d.ts +4 -0
- package/dist/types/protocol/newsletter.d.ts +65 -0
- package/dist/types/protocol/nodes.d.ts +20 -0
- package/dist/types/protocol/notification.d.ts +16 -0
- package/dist/types/protocol/presence.d.ts +16 -0
- package/dist/types/protocol/status.d.ts +7 -0
- package/dist/types/retry/codec.d.ts +5 -0
- package/dist/types/retry/index.d.ts +1 -1
- package/dist/types/retry/parse.d.ts +9 -0
- package/dist/types/retry/reason.d.ts +5 -0
- package/dist/types/retry/replay.d.ts +19 -5
- package/dist/types/retry/tracker.d.ts +10 -3
- package/dist/types/retry/types.d.ts +3 -8
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +20 -0
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +10 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +9 -0
- package/dist/types/signal/api/SignalMissingPreKeysSyncApi.d.ts +8 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +10 -0
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +13 -0
- package/dist/types/signal/api/codec.d.ts +20 -0
- package/dist/types/signal/api/constants.d.ts +1 -1
- package/dist/types/signal/api/prekeys.d.ts +4 -0
- package/dist/types/signal/{crypto → attestation}/WaAdvSignature.d.ts +2 -2
- package/dist/types/signal/attestation/constants.d.ts +4 -0
- package/dist/types/signal/constants.d.ts +7 -4
- package/dist/types/signal/encoding.d.ts +6 -68
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +17 -0
- package/dist/types/signal/group/encoding.d.ts +25 -0
- package/dist/types/signal/index.d.ts +4 -1
- package/dist/types/signal/registration/encoding.d.ts +30 -0
- package/dist/types/signal/registration/keygen.d.ts +10 -0
- package/dist/types/signal/registration/utils.d.ts +5 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +55 -0
- package/dist/types/signal/session/SignalRatchet.d.ts +2 -3
- package/dist/types/signal/session/SignalSession.d.ts +0 -1
- package/dist/types/signal/session/encoding.d.ts +28 -0
- package/dist/types/signal/session/resolver.d.ts +14 -0
- package/dist/types/store/cache/identity.cache.d.ts +15 -0
- package/dist/types/store/cache/privacy-token.cache.d.ts +15 -0
- package/dist/types/store/cache/sender-key.cache.d.ts +18 -0
- package/dist/types/store/cache/session.cache.d.ts +23 -0
- package/dist/types/store/contracts/contact.store.d.ts +14 -0
- package/dist/types/store/contracts/device-list.store.d.ts +13 -0
- package/dist/types/store/contracts/group-metadata.store.d.ts +14 -0
- package/dist/types/store/contracts/message.store.d.ts +0 -2
- package/dist/types/store/createStore.d.ts +54 -2
- package/dist/types/store/index.d.ts +17 -16
- package/dist/types/store/locks/group-metadata.lock.d.ts +2 -0
- package/dist/types/store/{providers/memory → memory}/appstate.store.d.ts +2 -2
- package/dist/types/store/memory/auth.store.d.ts +18 -0
- package/dist/types/store/{providers/memory → memory}/contact.store.d.ts +6 -1
- package/dist/types/store/{providers/memory → memory}/device-list.store.d.ts +15 -2
- package/dist/types/store/memory/group-metadata.store.d.ts +27 -0
- package/dist/types/store/{providers/memory → memory}/identity.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/message-secret.store.d.ts +12 -2
- package/dist/types/store/{providers/memory → memory}/message.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/pre-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/privacy-token.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/retry.store.d.ts +16 -3
- package/dist/types/store/{providers/memory → memory}/sender-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/session.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/signal.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/thread.store.d.ts +1 -1
- package/dist/types/store/noop.store.d.ts +2 -2
- package/dist/types/store/types.d.ts +250 -6
- package/dist/types/transport/WaComms.d.ts +5 -0
- package/dist/types/transport/WaWebSocket.d.ts +5 -0
- package/dist/types/transport/binary/constants.d.ts +8 -2
- package/dist/types/transport/binary/decoder.d.ts +5 -0
- package/dist/types/transport/binary/encoder.d.ts +5 -0
- package/dist/types/transport/binary/tokens.d.ts +6 -6
- package/dist/types/transport/index.d.ts +3 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +7 -0
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +6 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +5 -0
- package/dist/types/transport/node/WaNodeTransport.d.ts +13 -0
- package/dist/types/transport/node/builders/account-sync.d.ts +1 -2
- package/dist/types/transport/node/builders/bot.d.ts +4 -0
- package/dist/types/transport/node/builders/business.d.ts +21 -4
- package/dist/types/transport/node/builders/chatstate.d.ts +11 -0
- package/dist/types/transport/node/builders/community.d.ts +17 -0
- package/dist/types/transport/node/builders/group.d.ts +44 -2
- package/dist/types/transport/node/builders/message.d.ts +11 -6
- package/dist/types/transport/node/builders/newsletter.d.ts +73 -0
- package/dist/types/transport/node/builders/passive.d.ts +3 -0
- package/dist/types/transport/node/builders/presence.d.ts +8 -1
- package/dist/types/transport/node/builders/profile.d.ts +3 -0
- package/dist/types/transport/node/builders/tos.d.ts +12 -0
- package/dist/types/transport/node/builders/usync.d.ts +16 -0
- package/dist/types/transport/node/helpers.d.ts +1 -2
- package/dist/types/transport/node/mex/client.d.ts +12 -1
- package/dist/types/transport/node/query.d.ts +19 -1
- package/dist/types/transport/node/usync.d.ts +3 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseHandshake.d.ts +12 -6
- package/dist/types/transport/noise/WaNoiseSession.d.ts +0 -1
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +12 -6
- package/dist/types/transport/noise/constants.d.ts +4 -5
- package/dist/types/transport/proxy.d.ts +5 -0
- package/dist/types/transport/types.d.ts +14 -7
- package/dist/types/transport/wa-web-version-fetcher.d.ts +44 -0
- package/dist/types/util/async.d.ts +4 -0
- package/dist/types/util/bytes.d.ts +36 -1
- package/dist/types/util/clock.d.ts +6 -0
- package/dist/types/util/coercion.d.ts +25 -0
- package/dist/types/util/collections.d.ts +8 -0
- package/dist/types/util/index.d.ts +2 -2
- package/dist/types/util/primitives.d.ts +11 -0
- package/dist/types/util/runtime.d.ts +5 -0
- package/dist/types/version-spec.d.ts +1 -0
- package/dist/util/async.js +4 -0
- package/dist/util/bytes.js +37 -2
- package/dist/util/clock.js +18 -0
- package/dist/util/coercion.js +48 -3
- package/dist/util/collections.js +12 -0
- package/dist/util/index.js +7 -1
- package/dist/util/primitives.js +20 -0
- package/dist/util/runtime.js +5 -0
- package/dist/version-spec.js +5 -0
- package/package.json +32 -8
- package/spec/appstate/index.d.ts +188 -0
- package/spec/appstate/index.js +850 -0
- package/spec/mex/index.d.ts +4172 -0
- package/spec/mex/index.js +261 -0
- package/spec/proto/index.d.ts +16305 -0
- package/spec/proto/index.js +1 -0
- package/spec/version/index.d.ts +4 -0
- package/spec/version/index.js +9 -0
- package/spec/version/version.json +3 -0
- package/dist/client/events/chat.js +0 -227
- package/dist/client/incoming.js +0 -306
- package/dist/client/mailbox.js +0 -66
- package/dist/client/messages.js +0 -305
- package/dist/esm/client/events/chat.js +0 -224
- package/dist/esm/client/incoming.js +0 -296
- package/dist/esm/client/mailbox.js +0 -63
- package/dist/esm/client/messages.js +0 -301
- package/dist/esm/media/WaMediaCrypto.js +0 -499
- package/dist/esm/message/phash.js +0 -47
- package/dist/esm/store/locks/participants.lock.js +0 -20
- package/dist/esm/store/providers/memory/contact.store.js +0 -28
- package/dist/esm/store/providers/memory/device-list.store.js +0 -67
- package/dist/esm/transport/node/mex/persist-ids.js +0 -10
- package/dist/media/WaMediaCrypto.js +0 -503
- package/dist/message/phash.js +0 -50
- package/dist/store/locks/participants.lock.js +0 -23
- package/dist/store/providers/memory/contact.store.js +0 -32
- package/dist/store/providers/memory/device-list.store.js +0 -71
- package/dist/transport/node/mex/persist-ids.js +0 -13
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +0 -70
- package/dist/types/client/events/chat.d.ts +0 -3
- package/dist/types/client/history-sync.d.ts +0 -20
- package/dist/types/client/messages.d.ts +0 -18
- package/dist/types/client/messaging/participants.d.ts +0 -13
- package/dist/types/media/WaMediaCrypto.d.ts +0 -22
- package/dist/types/media/conn.d.ts +0 -3
- package/dist/types/message/content.d.ts +0 -14
- package/dist/types/message/incoming.d.ts +0 -18
- package/dist/types/signal/crypto/constants.d.ts +0 -4
- package/dist/types/store/contracts/participants.store.d.ts +0 -13
- package/dist/types/store/locks/participants.lock.d.ts +0 -2
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -17
- package/dist/types/transport/node/mex/persist-ids.d.ts +0 -14
- package/proto/index.d.ts +0 -10903
- package/proto/index.js +0 -1
- /package/dist/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/esm/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/esm/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/types/message/{padding.d.ts → encode/padding.d.ts} +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { downloadExternalBlobReference } from '../../appstate/utils.js';
|
|
2
|
+
import { encodeEnumValue, WA_APPSTATE_SCHEMAS } from '../../appstate-spec.js';
|
|
3
|
+
import { parseAppStateMutationEvent } from '../events/appstate-mutation.js';
|
|
4
|
+
import { proto } from '../../proto.js';
|
|
5
|
+
import { WA_APP_STATE_COLLECTION_STATES } from '../../protocol/constants.js';
|
|
6
|
+
import { isGroupJid, isGroupOrBroadcastJid, isLidJid, isUserJid, normalizeDeviceJid, normalizeRecipientJid, toUserJid } from '../../protocol/jid.js';
|
|
3
7
|
import { resolvePositive } from '../../util/coercion.js';
|
|
4
8
|
import { toError } from '../../util/primitives.js';
|
|
5
9
|
const WA_APP_STATE_MUTATION_FLUSH_SUCCESS_STATES = new Set([
|
|
@@ -7,18 +11,364 @@ const WA_APP_STATE_MUTATION_FLUSH_SUCCESS_STATES = new Set([
|
|
|
7
11
|
WA_APP_STATE_COLLECTION_STATES.SUCCESS_HAS_MORE
|
|
8
12
|
]);
|
|
9
13
|
const WA_APP_STATE_ARCHIVE_RANGE_DEFAULT_LIMIT = 256;
|
|
14
|
+
function buildMutationIndexFromSchema(schema, indexArgs) {
|
|
15
|
+
const parts = new Array(schema.indexParts.length);
|
|
16
|
+
const args = indexArgs;
|
|
17
|
+
for (let i = 0; i < schema.indexParts.length; i += 1) {
|
|
18
|
+
const part = schema.indexParts[i];
|
|
19
|
+
if (part.type === 'literal') {
|
|
20
|
+
parts[i] = part.value;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const arg = args[part.name];
|
|
24
|
+
if (part.type === 'boolString') {
|
|
25
|
+
parts[i] = arg ? '1' : '0';
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (part.type === 'jidOrZero') {
|
|
29
|
+
if (arg === null || arg === undefined) {
|
|
30
|
+
const fromMeSlot = schema.indexParts.find((p) => p.type === 'boolString' && p.name === 'fromMe');
|
|
31
|
+
if (fromMeSlot && args['fromMe'] !== true) {
|
|
32
|
+
throw new Error(`app-state index arg "${part.name}" for schema "${schema.name}" requires a JID when fromMe is not true`);
|
|
33
|
+
}
|
|
34
|
+
parts[i] = '0';
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
parts[i] = arg;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (part.type === 'enum') {
|
|
41
|
+
if (typeof arg === 'number') {
|
|
42
|
+
parts[i] = String(arg);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (typeof arg !== 'string') {
|
|
46
|
+
throw new Error(`app-state enum index arg "${part.name}" for schema "${schema.name}" must be a string`);
|
|
47
|
+
}
|
|
48
|
+
const numeric = encodeEnumValue(part.protoEnum, arg);
|
|
49
|
+
if (numeric === null) {
|
|
50
|
+
throw new Error(`app-state enum index arg "${part.name}"="${arg}" is not in enum ${part.protoEnum}`);
|
|
51
|
+
}
|
|
52
|
+
parts[i] = String(numeric);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (typeof arg !== 'string') {
|
|
56
|
+
throw new Error(`app-state index arg "${part.name}" for schema "${schema.name}" must be a string`);
|
|
57
|
+
}
|
|
58
|
+
parts[i] = arg;
|
|
59
|
+
}
|
|
60
|
+
return JSON.stringify(parts);
|
|
61
|
+
}
|
|
62
|
+
function buildSetMutationFromSchema(input) {
|
|
63
|
+
return {
|
|
64
|
+
collection: input.schema.collection,
|
|
65
|
+
operation: 'set',
|
|
66
|
+
index: buildMutationIndexFromSchema(input.schema, input.indexArgs),
|
|
67
|
+
value: { ...input.value, timestamp: input.timestamp },
|
|
68
|
+
version: input.schema.version,
|
|
69
|
+
timestamp: input.timestamp
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function splitFlatInput(schema, input) {
|
|
73
|
+
const indexNames = new Set();
|
|
74
|
+
for (const part of schema.indexParts) {
|
|
75
|
+
if (part.type !== 'literal') {
|
|
76
|
+
indexNames.add(part.name);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const indexArgs = {};
|
|
80
|
+
const data = {};
|
|
81
|
+
for (const key of Object.keys(input)) {
|
|
82
|
+
if (key === 'schema')
|
|
83
|
+
continue;
|
|
84
|
+
if (indexNames.has(key)) {
|
|
85
|
+
indexArgs[key] = input[key];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
data[key] = input[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { indexArgs, data };
|
|
92
|
+
}
|
|
93
|
+
function wrapData(schema, data) {
|
|
94
|
+
const encoded = applyEnumEncodeToData(schema.valueEnumFields, data);
|
|
95
|
+
const field = schema.valueField;
|
|
96
|
+
if (field === null) {
|
|
97
|
+
return encoded;
|
|
98
|
+
}
|
|
99
|
+
return { [field]: encoded };
|
|
100
|
+
}
|
|
101
|
+
function applyEnumEncodeToData(enumFields, data) {
|
|
102
|
+
if (!enumFields)
|
|
103
|
+
return { ...data };
|
|
104
|
+
const out = { ...data };
|
|
105
|
+
for (const [fieldPath, enumPath] of Object.entries(enumFields)) {
|
|
106
|
+
applyEnumAtPath(out, fieldPath.split('.'), (raw) => {
|
|
107
|
+
if (typeof raw === 'number')
|
|
108
|
+
return raw;
|
|
109
|
+
if (typeof raw !== 'string')
|
|
110
|
+
return raw;
|
|
111
|
+
const numeric = encodeEnumValue(enumPath, raw);
|
|
112
|
+
if (numeric === null) {
|
|
113
|
+
throw new Error(`enum value "${raw}" not in ${enumPath}`);
|
|
114
|
+
}
|
|
115
|
+
return numeric;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
function applyEnumAtPath(obj, segments, transform) {
|
|
121
|
+
if (segments.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
const [head, ...rest] = segments;
|
|
124
|
+
if (rest.length === 0) {
|
|
125
|
+
if (head in obj) {
|
|
126
|
+
const value = obj[head];
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
obj[head] = value.map(transform);
|
|
129
|
+
}
|
|
130
|
+
else if (value !== null && value !== undefined) {
|
|
131
|
+
obj[head] = transform(value);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const next = obj[head];
|
|
137
|
+
if (Array.isArray(next)) {
|
|
138
|
+
const cloned = next.map((item) => {
|
|
139
|
+
if (item && typeof item === 'object') {
|
|
140
|
+
const itemCopy = { ...item };
|
|
141
|
+
applyEnumAtPath(itemCopy, rest, transform);
|
|
142
|
+
return itemCopy;
|
|
143
|
+
}
|
|
144
|
+
return item;
|
|
145
|
+
});
|
|
146
|
+
obj[head] = cloned;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (next && typeof next === 'object') {
|
|
150
|
+
const nextCopy = { ...next };
|
|
151
|
+
applyEnumAtPath(nextCopy, rest, transform);
|
|
152
|
+
obj[head] = nextCopy;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function buildRemoveMutationFromSchema(input) {
|
|
156
|
+
return {
|
|
157
|
+
collection: input.schema.collection,
|
|
158
|
+
operation: 'remove',
|
|
159
|
+
index: buildMutationIndexFromSchema(input.schema, input.indexArgs),
|
|
160
|
+
previousValue: { timestamp: input.timestamp },
|
|
161
|
+
version: input.schema.version,
|
|
162
|
+
timestamp: input.timestamp
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Coordinates app-state mutations (mute/star/read/pin/archive/clear/delete/
|
|
167
|
+
* lock chats, status privacy, broadcast lists) and emits parsed mutation
|
|
168
|
+
* events on sync. Accessed via {@link WaClient.chat}.
|
|
169
|
+
*/
|
|
10
170
|
export class WaAppStateMutationCoordinator {
|
|
11
171
|
constructor(options) {
|
|
12
172
|
this.logger = options.logger;
|
|
13
173
|
this.messageStore = options.messageStore;
|
|
14
|
-
this.
|
|
174
|
+
this.appStateSync = options.appStateSync;
|
|
175
|
+
this.mediaTransfer = options.mediaTransfer;
|
|
176
|
+
this.isConnected = options.isConnected;
|
|
177
|
+
this.serverClock = options.serverClock;
|
|
15
178
|
this.archiveRangeLimit = resolvePositive(options.archiveRangeLimit, WA_APP_STATE_ARCHIVE_RANGE_DEFAULT_LIMIT, 'WaAppStateMutationCoordinatorOptions.archiveRangeLimit');
|
|
179
|
+
this.emitMutation = options.emitMutation;
|
|
180
|
+
this.emitSnapshotMutations = options.emitSnapshotMutations === true;
|
|
181
|
+
this.nctSaltSink = options.nctSaltSink;
|
|
182
|
+
this.contactSink = options.contactSink;
|
|
16
183
|
this.pendingMutations = new Map();
|
|
17
184
|
this.flushPromise = null;
|
|
18
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Runs an app-state sync round, optionally applying pending mutations.
|
|
188
|
+
* Throws when the client is not connected. Returns the per-collection
|
|
189
|
+
* result; blocked collections are logged.
|
|
190
|
+
*/
|
|
191
|
+
async sync(options = {}) {
|
|
192
|
+
if (!this.isConnected()) {
|
|
193
|
+
throw new Error('client is not connected');
|
|
194
|
+
}
|
|
195
|
+
const syncOptions = options.downloadExternalBlob
|
|
196
|
+
? options
|
|
197
|
+
: {
|
|
198
|
+
...options,
|
|
199
|
+
downloadExternalBlob: async (_collection, _kind, reference) => downloadExternalBlobReference(this.mediaTransfer, reference)
|
|
200
|
+
};
|
|
201
|
+
const syncResult = await this.appStateSync.sync(syncOptions);
|
|
202
|
+
const blockedCollections = this.getBlockedCollections(syncResult);
|
|
203
|
+
if (blockedCollections.length > 0) {
|
|
204
|
+
this.logger.warn('app-state sync has blocked collections', {
|
|
205
|
+
blockedCollections: blockedCollections.join(',')
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
this.emitEventsFromSyncResult(syncResult);
|
|
209
|
+
return syncResult;
|
|
210
|
+
}
|
|
211
|
+
/** Returns the names of collections reported as `BLOCKED` in `syncResult`. */
|
|
212
|
+
getBlockedCollections(syncResult) {
|
|
213
|
+
const blocked = [];
|
|
214
|
+
for (const entry of syncResult.collections) {
|
|
215
|
+
if (entry.state === WA_APP_STATE_COLLECTION_STATES.BLOCKED) {
|
|
216
|
+
blocked.push(entry.collection);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return blocked;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Walks a sync result and emits one `app_state_mutation` event per
|
|
223
|
+
* distinct (collection, index) – only the last mutation per key wins.
|
|
224
|
+
* Snapshot-source mutations are skipped unless `emitSnapshotMutations`
|
|
225
|
+
* was enabled at construction.
|
|
226
|
+
*/
|
|
227
|
+
emitEventsFromSyncResult(syncResult) {
|
|
228
|
+
for (const collectionResult of syncResult.collections) {
|
|
229
|
+
const mutations = collectionResult.mutations ?? [];
|
|
230
|
+
// Persistence sinks (contact store, ...): run on the last-wins
|
|
231
|
+
// mutation per key INCLUDING snapshot sources, so pair-time
|
|
232
|
+
// bootstrap of the address book always lands in the store even
|
|
233
|
+
// when public events are suppressed for snapshot mutations.
|
|
234
|
+
if (this.contactSink) {
|
|
235
|
+
const sinkLastIndex = new Map();
|
|
236
|
+
for (let i = 0; i < mutations.length; i += 1) {
|
|
237
|
+
const m = mutations[i];
|
|
238
|
+
sinkLastIndex.set(`${m.collection}\u0001${m.index}`, i);
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < mutations.length; i += 1) {
|
|
241
|
+
const m = mutations[i];
|
|
242
|
+
if (sinkLastIndex.get(`${m.collection}\u0001${m.index}`) !== i) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
this.handleContactMutation(m);
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
this.logger.debug('contact sink failed', {
|
|
250
|
+
collection: m.collection,
|
|
251
|
+
index: m.index,
|
|
252
|
+
message: toError(error).message
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const lastMutationIndexByKey = new Map();
|
|
258
|
+
for (let mutationIndex = 0; mutationIndex < mutations.length; mutationIndex += 1) {
|
|
259
|
+
const mutation = mutations[mutationIndex];
|
|
260
|
+
if (!this.emitSnapshotMutations && mutation.source === 'snapshot') {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
lastMutationIndexByKey.set(`${mutation.collection}\u0001${mutation.index}`, mutationIndex);
|
|
264
|
+
}
|
|
265
|
+
for (let mutationIndex = 0; mutationIndex < mutations.length; mutationIndex += 1) {
|
|
266
|
+
const mutation = mutations[mutationIndex];
|
|
267
|
+
if (!this.emitSnapshotMutations && mutation.source === 'snapshot') {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const coalesceKey = `${mutation.collection}\u0001${mutation.index}`;
|
|
271
|
+
if (lastMutationIndexByKey.get(coalesceKey) !== mutationIndex) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
this.handleNctSaltMutation(mutation);
|
|
276
|
+
const event = parseAppStateMutationEvent(mutation);
|
|
277
|
+
if (!event) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
this.emitMutation?.(event);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.logger.debug('failed to parse app-state mutation event', {
|
|
284
|
+
collection: mutation.collection,
|
|
285
|
+
source: mutation.source,
|
|
286
|
+
index: mutation.index,
|
|
287
|
+
message: toError(error).message
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
handleNctSaltMutation(mutation) {
|
|
294
|
+
if (!this.nctSaltSink)
|
|
295
|
+
return;
|
|
296
|
+
const nctAction = mutation.value?.nctSaltSyncAction;
|
|
297
|
+
if (!nctAction) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (mutation.operation === 'set' && nctAction.salt) {
|
|
301
|
+
this.nctSaltSink(nctAction.salt).catch((err) => this.logger.warn('nct salt sync set failed', {
|
|
302
|
+
message: toError(err).message
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
else if (mutation.operation === 'remove') {
|
|
306
|
+
this.nctSaltSink(null).catch((err) => this.logger.warn('nct salt sync remove failed', {
|
|
307
|
+
message: toError(err).message
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
handleContactMutation(mutation) {
|
|
312
|
+
if (!this.contactSink)
|
|
313
|
+
return;
|
|
314
|
+
// Cheap reject before JSON.parse: Contact mutations always carry
|
|
315
|
+
// the literal "contact" as their first index segment.
|
|
316
|
+
if (!mutation.index.includes('"contact"'))
|
|
317
|
+
return;
|
|
318
|
+
let parts;
|
|
319
|
+
try {
|
|
320
|
+
parts = JSON.parse(mutation.index);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (!Array.isArray(parts) || parts[0] !== 'contact' || typeof parts[1] !== 'string') {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const indexJid = parts[1];
|
|
329
|
+
const lastUpdatedMs = mutation.timestamp > 0 ? mutation.timestamp : Date.now();
|
|
330
|
+
// Remove operations are a no-op for the contact store: `mergeContact`
|
|
331
|
+
// preserves prior displayName when incoming.displayName is undefined,
|
|
332
|
+
// and the row should stay around (the chat may still be open). The
|
|
333
|
+
// public mutation event still fires below so consumers can react.
|
|
334
|
+
if (mutation.operation === 'remove')
|
|
335
|
+
return;
|
|
336
|
+
const action = mutation.value?.contactAction;
|
|
337
|
+
if (!action)
|
|
338
|
+
return;
|
|
339
|
+
// Resolve canonical (LID-preferred) jid + cross-reference: the index
|
|
340
|
+
// typically carries the PN form, and `contactAction.lidJid` carries
|
|
341
|
+
// the LID counterpart. Store one row keyed by LID when both are known
|
|
342
|
+
// (mirrors what the contact store does for history-sync writes), with
|
|
343
|
+
// `phoneNumber` populated so PN-form lookups still resolve.
|
|
344
|
+
const lid = action.lidJid && isLidJid(action.lidJid) ? action.lidJid : undefined;
|
|
345
|
+
const indexIsPn = isUserJid(indexJid);
|
|
346
|
+
const indexIsLid = isLidJid(indexJid);
|
|
347
|
+
const jid = lid ?? indexJid;
|
|
348
|
+
const phoneNumber = indexIsPn ? indexJid : undefined;
|
|
349
|
+
const lidField = lid ?? (indexIsLid ? indexJid : undefined);
|
|
350
|
+
const displayName = action.fullName || action.firstName || undefined;
|
|
351
|
+
this.contactSink({
|
|
352
|
+
jid,
|
|
353
|
+
displayName,
|
|
354
|
+
lid: lidField,
|
|
355
|
+
phoneNumber,
|
|
356
|
+
lastUpdatedMs
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Mutes or unmutes a chat. `muteEndTimestampMs` is required when
|
|
361
|
+
* `muted` is `true` and must be a non-negative safe-integer epoch.
|
|
362
|
+
*
|
|
363
|
+
* For a "mute forever" entry, pass a very large epoch value (the
|
|
364
|
+
* official client uses year-9999 epochs). The mute end is the absolute
|
|
365
|
+
* timestamp when WhatsApp will re-enable notifications - the client
|
|
366
|
+
* does **not** unmute automatically when the timer expires (you'll see
|
|
367
|
+
* the chat un-muted on the phone, but no `mutation` event re-fires).
|
|
368
|
+
*/
|
|
19
369
|
async setChatMute(chatJid, muted, muteEndTimestampMs) {
|
|
20
370
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
21
|
-
const timestamp =
|
|
371
|
+
const timestamp = this.serverClock.nowMs();
|
|
22
372
|
const normalizedMuteEnd = muteEndTimestampMs;
|
|
23
373
|
if (normalizedMuteEnd !== undefined &&
|
|
24
374
|
(!Number.isFinite(normalizedMuteEnd) ||
|
|
@@ -29,66 +379,63 @@ export class WaAppStateMutationCoordinator {
|
|
|
29
379
|
if (muted && normalizedMuteEnd === undefined) {
|
|
30
380
|
throw new Error('setChatMute requires muteEndTimestampMs when muted is true');
|
|
31
381
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
382
|
+
await this.enqueueAndFlush([
|
|
383
|
+
buildSetMutationFromSchema({
|
|
384
|
+
schema: WA_APPSTATE_SCHEMAS.Mute,
|
|
385
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
386
|
+
value: {
|
|
387
|
+
muteAction: {
|
|
388
|
+
muted,
|
|
389
|
+
...(normalizedMuteEnd === undefined
|
|
390
|
+
? {}
|
|
391
|
+
: { muteEndTimestamp: normalizedMuteEnd })
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
timestamp
|
|
395
|
+
})
|
|
396
|
+
]);
|
|
46
397
|
}
|
|
398
|
+
/** Stars or un-stars a specific message. */
|
|
47
399
|
async setMessageStar(message, starred) {
|
|
48
400
|
const messageIndex = this.buildMessageMutationIndex(message);
|
|
49
|
-
const timestamp =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
starAction: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
timestamp,
|
|
59
|
-
indexPartsTail: messageIndex.indexPartsTail
|
|
60
|
-
});
|
|
61
|
-
await this.enqueueAndFlush([mutation]);
|
|
401
|
+
const timestamp = this.serverClock.nowMs();
|
|
402
|
+
await this.enqueueAndFlush([
|
|
403
|
+
buildSetMutationFromSchema({
|
|
404
|
+
schema: WA_APPSTATE_SCHEMAS.Star,
|
|
405
|
+
indexArgs: messageIndex,
|
|
406
|
+
value: { starAction: { starred } },
|
|
407
|
+
timestamp
|
|
408
|
+
})
|
|
409
|
+
]);
|
|
62
410
|
}
|
|
411
|
+
/** Marks the chat as read or unread. */
|
|
63
412
|
async setChatRead(chatJid, read) {
|
|
64
413
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
65
|
-
const timestamp =
|
|
414
|
+
const timestamp = this.serverClock.nowMs();
|
|
66
415
|
const messageRange = await this.buildChatMessageRange(chatIndexJid);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
markChatAsReadAction: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
timestamp
|
|
77
|
-
});
|
|
78
|
-
await this.enqueueAndFlush([mutation]);
|
|
416
|
+
await this.enqueueAndFlush([
|
|
417
|
+
buildSetMutationFromSchema({
|
|
418
|
+
schema: WA_APPSTATE_SCHEMAS.MarkChatAsRead,
|
|
419
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
420
|
+
value: { markChatAsReadAction: { read, messageRange } },
|
|
421
|
+
timestamp
|
|
422
|
+
})
|
|
423
|
+
]);
|
|
79
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Pins or unpins the chat. Pinning also clears any active archive flag
|
|
427
|
+
* (the two states are mutually exclusive on the client). WhatsApp
|
|
428
|
+
* imposes a server-side cap on pinned chats - extra pins sync but the
|
|
429
|
+
* official UI will hide / reject them.
|
|
430
|
+
*/
|
|
80
431
|
async setChatPin(chatJid, pinned) {
|
|
81
432
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
82
|
-
const timestamp =
|
|
433
|
+
const timestamp = this.serverClock.nowMs();
|
|
83
434
|
const pending = [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
chatIndexJid,
|
|
87
|
-
value: {
|
|
88
|
-
pinAction: {
|
|
89
|
-
pinned
|
|
90
|
-
}
|
|
91
|
-
},
|
|
435
|
+
buildSetMutationFromSchema({
|
|
436
|
+
schema: WA_APPSTATE_SCHEMAS.Pin,
|
|
437
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
438
|
+
value: { pinAction: { pinned } },
|
|
92
439
|
timestamp
|
|
93
440
|
})
|
|
94
441
|
];
|
|
@@ -97,66 +444,82 @@ export class WaAppStateMutationCoordinator {
|
|
|
97
444
|
}
|
|
98
445
|
await this.enqueueAndFlush(pending);
|
|
99
446
|
}
|
|
447
|
+
/** Archives or unarchives the chat. Archiving also clears any pin. */
|
|
100
448
|
async setChatArchive(chatJid, archived) {
|
|
101
449
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
102
|
-
const timestamp =
|
|
450
|
+
const timestamp = this.serverClock.nowMs();
|
|
103
451
|
const pending = [
|
|
104
452
|
await this.createArchiveMutation(chatIndexJid, archived, timestamp)
|
|
105
453
|
];
|
|
106
454
|
if (archived) {
|
|
107
|
-
pending.push(
|
|
108
|
-
|
|
109
|
-
chatIndexJid,
|
|
110
|
-
value: {
|
|
111
|
-
pinAction: {
|
|
112
|
-
pinned: false
|
|
113
|
-
}
|
|
114
|
-
},
|
|
455
|
+
pending.push(buildSetMutationFromSchema({
|
|
456
|
+
schema: WA_APPSTATE_SCHEMAS.Pin,
|
|
457
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
458
|
+
value: { pinAction: { pinned: false } },
|
|
115
459
|
timestamp
|
|
116
460
|
}));
|
|
117
461
|
}
|
|
118
462
|
await this.enqueueAndFlush(pending);
|
|
119
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* Clears the chat history (without deleting the chat itself - it stays
|
|
466
|
+
* in the chat list, just empty). Defaults to **preserving** starred
|
|
467
|
+
* messages and media; set `options.deleteStarred`/`deleteMedia` to wipe
|
|
468
|
+
* those too. The clear is local-only - other participants keep their
|
|
469
|
+
* copies.
|
|
470
|
+
*/
|
|
120
471
|
async clearChat(chatJid, options = {}) {
|
|
121
472
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
122
|
-
const timestamp =
|
|
473
|
+
const timestamp = this.serverClock.nowMs();
|
|
123
474
|
const deleteStarred = options.deleteStarred === true;
|
|
124
475
|
const deleteMedia = options.deleteMedia === true;
|
|
125
476
|
const messageRange = await this.buildChatMessageRange(chatIndexJid);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
477
|
+
await this.enqueueAndFlush([
|
|
478
|
+
buildSetMutationFromSchema({
|
|
479
|
+
schema: WA_APPSTATE_SCHEMAS.ClearChat,
|
|
480
|
+
indexArgs: {
|
|
481
|
+
chatJid: chatIndexJid,
|
|
482
|
+
deleteStarred: deleteStarred ? '1' : '0',
|
|
483
|
+
deleteMedia: deleteMedia ? '1' : '0'
|
|
484
|
+
},
|
|
485
|
+
value: { clearChatAction: { messageRange } },
|
|
486
|
+
timestamp
|
|
487
|
+
})
|
|
488
|
+
]);
|
|
138
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Deletes the chat entirely (removes from the chat list + drops every
|
|
492
|
+
* stored message). Local-only - the conversation continues to exist on
|
|
493
|
+
* the peer's device. For groups, this does **not** leave the group;
|
|
494
|
+
* use {@link WaGroupCoordinator.leaveGroup} for that.
|
|
495
|
+
*/
|
|
139
496
|
async deleteChat(chatJid, options = {}) {
|
|
140
497
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
141
|
-
const timestamp =
|
|
498
|
+
const timestamp = this.serverClock.nowMs();
|
|
142
499
|
const deleteMedia = options.deleteMedia === true;
|
|
143
500
|
const messageRange = await this.buildChatMessageRange(chatIndexJid);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
await this.enqueueAndFlush([mutation]);
|
|
501
|
+
await this.enqueueAndFlush([
|
|
502
|
+
buildSetMutationFromSchema({
|
|
503
|
+
schema: WA_APPSTATE_SCHEMAS.DeleteChat,
|
|
504
|
+
indexArgs: {
|
|
505
|
+
chatJid: chatIndexJid,
|
|
506
|
+
deleteMedia: deleteMedia ? '1' : '0'
|
|
507
|
+
},
|
|
508
|
+
value: { deleteChatAction: { messageRange } },
|
|
509
|
+
timestamp
|
|
510
|
+
})
|
|
511
|
+
]);
|
|
156
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Deletes a single message **locally** - removes it from your own
|
|
515
|
+
* device(s) only. The recipient(s) still see it. Use a `revoke`
|
|
516
|
+
* outgoing message ({@link WaMessageCoordinator.send} with
|
|
517
|
+
* `{ type: 'revoke', ... }`) to delete-for-everyone instead.
|
|
518
|
+
* `messageTimestampMs` must be a non-negative safe-integer epoch when set.
|
|
519
|
+
*/
|
|
157
520
|
async deleteMessageForMe(message, options = {}) {
|
|
158
521
|
const messageIndex = this.buildMessageMutationIndex(message);
|
|
159
|
-
const timestamp =
|
|
522
|
+
const timestamp = this.serverClock.nowMs();
|
|
160
523
|
const deleteMedia = options.deleteMedia === true;
|
|
161
524
|
const messageTimestampMs = options.messageTimestampMs;
|
|
162
525
|
let messageTimestamp;
|
|
@@ -168,49 +531,47 @@ export class WaAppStateMutationCoordinator {
|
|
|
168
531
|
}
|
|
169
532
|
messageTimestamp = Math.floor(messageTimestampMs / 1000);
|
|
170
533
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
534
|
+
await this.enqueueAndFlush([
|
|
535
|
+
buildSetMutationFromSchema({
|
|
536
|
+
schema: WA_APPSTATE_SCHEMAS.DeleteMessageForMe,
|
|
537
|
+
indexArgs: messageIndex,
|
|
538
|
+
value: {
|
|
539
|
+
deleteMessageForMeAction: {
|
|
540
|
+
deleteMedia,
|
|
541
|
+
...(messageTimestamp === undefined ? {} : { messageTimestamp })
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
timestamp
|
|
545
|
+
})
|
|
546
|
+
]);
|
|
184
547
|
}
|
|
548
|
+
/** Locks or unlocks the chat. Locking also clears archive and pin. */
|
|
185
549
|
async setChatLock(chatJid, locked) {
|
|
186
550
|
const chatIndexJid = this.normalizeChatMutationJid(chatJid);
|
|
187
|
-
const timestamp =
|
|
551
|
+
const timestamp = this.serverClock.nowMs();
|
|
188
552
|
const pending = [];
|
|
189
553
|
if (locked) {
|
|
190
554
|
pending.push(await this.createArchiveMutation(chatIndexJid, false, timestamp));
|
|
191
|
-
pending.push(
|
|
192
|
-
|
|
193
|
-
chatIndexJid,
|
|
194
|
-
value: {
|
|
195
|
-
pinAction: {
|
|
196
|
-
pinned: false
|
|
197
|
-
}
|
|
198
|
-
},
|
|
555
|
+
pending.push(buildSetMutationFromSchema({
|
|
556
|
+
schema: WA_APPSTATE_SCHEMAS.Pin,
|
|
557
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
558
|
+
value: { pinAction: { pinned: false } },
|
|
199
559
|
timestamp
|
|
200
560
|
}));
|
|
201
561
|
}
|
|
202
|
-
pending.push(
|
|
203
|
-
|
|
204
|
-
chatIndexJid,
|
|
205
|
-
value: {
|
|
206
|
-
lockChatAction: {
|
|
207
|
-
locked
|
|
208
|
-
}
|
|
209
|
-
},
|
|
562
|
+
pending.push(buildSetMutationFromSchema({
|
|
563
|
+
schema: WA_APPSTATE_SCHEMAS.LockChat,
|
|
564
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
565
|
+
value: { lockChatAction: { locked } },
|
|
210
566
|
timestamp
|
|
211
567
|
}));
|
|
212
568
|
await this.enqueueAndFlush(pending);
|
|
213
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Drains any queued mutations through a sync round. Concurrent callers
|
|
572
|
+
* share the in-flight flush promise. Failed collections are re-queued
|
|
573
|
+
* before the error is rethrown.
|
|
574
|
+
*/
|
|
214
575
|
async flushMutations() {
|
|
215
576
|
if (this.flushPromise) {
|
|
216
577
|
return this.flushPromise;
|
|
@@ -268,7 +629,7 @@ export class WaAppStateMutationCoordinator {
|
|
|
268
629
|
seenCollections.add(mutation.collection);
|
|
269
630
|
collections.push(mutation.collection);
|
|
270
631
|
}
|
|
271
|
-
syncResult = await this.
|
|
632
|
+
syncResult = await this.sync({
|
|
272
633
|
collections,
|
|
273
634
|
pendingMutations: batch
|
|
274
635
|
});
|
|
@@ -320,30 +681,190 @@ export class WaAppStateMutationCoordinator {
|
|
|
320
681
|
this.enqueueMutation(mutation);
|
|
321
682
|
}
|
|
322
683
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
684
|
+
/**
|
|
685
|
+
* Sets the account-wide status-broadcast distribution policy. `mode`
|
|
686
|
+
* accepts either the proto enum number or its string name; allow/deny
|
|
687
|
+
* lists are provided via `userJids`.
|
|
688
|
+
*/
|
|
689
|
+
async setStatusPrivacy(input) {
|
|
690
|
+
const modeValue = typeof input.mode === 'number'
|
|
691
|
+
? input.mode
|
|
692
|
+
: proto.SyncActionValue.StatusPrivacyAction.StatusDistributionMode[input.mode];
|
|
693
|
+
if (typeof modeValue !== 'number' || !Number.isInteger(modeValue)) {
|
|
694
|
+
throw new Error(`setStatusPrivacy: invalid mode ${String(input.mode)}`);
|
|
695
|
+
}
|
|
696
|
+
const userJid = input.userJids ? [...input.userJids] : [];
|
|
697
|
+
const value = {
|
|
698
|
+
statusPrivacy: {
|
|
699
|
+
mode: modeValue,
|
|
700
|
+
userJid,
|
|
701
|
+
...(input.shareToFB === undefined ? {} : { shareToFB: input.shareToFB }),
|
|
702
|
+
...(input.shareToIG === undefined ? {} : { shareToIG: input.shareToIG })
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
const timestamp = this.serverClock.nowMs();
|
|
706
|
+
await this.enqueueAndFlush([
|
|
707
|
+
buildSetMutationFromSchema({
|
|
708
|
+
schema: WA_APPSTATE_SCHEMAS.StatusPrivacy,
|
|
709
|
+
indexArgs: {},
|
|
710
|
+
value,
|
|
711
|
+
timestamp
|
|
712
|
+
})
|
|
713
|
+
]);
|
|
714
|
+
}
|
|
715
|
+
/** Mutes/unmutes a single user's status broadcasts. Rejects group/broadcast JIDs. */
|
|
716
|
+
async setUserStatusMute(jid, muted) {
|
|
717
|
+
const indexJid = this.normalizeChatMutationJid(jid);
|
|
718
|
+
if (isGroupOrBroadcastJid(indexJid)) {
|
|
719
|
+
throw new Error(`setUserStatusMute requires a user jid, got ${jid}`);
|
|
720
|
+
}
|
|
721
|
+
const timestamp = this.serverClock.nowMs();
|
|
722
|
+
await this.enqueueAndFlush([
|
|
723
|
+
buildSetMutationFromSchema({
|
|
724
|
+
schema: WA_APPSTATE_SCHEMAS.UserStatusMute,
|
|
725
|
+
indexArgs: { id: indexJid },
|
|
726
|
+
value: { userStatusMuteAction: { muted } },
|
|
727
|
+
timestamp
|
|
728
|
+
})
|
|
729
|
+
]);
|
|
730
|
+
}
|
|
731
|
+
/** Creates or updates the broadcast list identified by `input.id`. */
|
|
732
|
+
async setBroadcastList(input) {
|
|
733
|
+
const participants = input.participants.map((entry) => ({
|
|
734
|
+
lidJid: entry.lidJid,
|
|
735
|
+
...(entry.pnJid === undefined ? {} : { pnJid: entry.pnJid })
|
|
736
|
+
}));
|
|
737
|
+
const value = {
|
|
738
|
+
businessBroadcastListAction: {
|
|
739
|
+
participants,
|
|
740
|
+
listName: input.listName,
|
|
741
|
+
labelIds: input.labelIds ? [...input.labelIds] : []
|
|
742
|
+
}
|
|
334
743
|
};
|
|
744
|
+
const timestamp = this.serverClock.nowMs();
|
|
745
|
+
await this.enqueueAndFlush([
|
|
746
|
+
buildSetMutationFromSchema({
|
|
747
|
+
schema: WA_APPSTATE_SCHEMAS.BusinessBroadcastList,
|
|
748
|
+
indexArgs: { id: input.id },
|
|
749
|
+
value,
|
|
750
|
+
timestamp
|
|
751
|
+
})
|
|
752
|
+
]);
|
|
753
|
+
}
|
|
754
|
+
/** Deletes the broadcast list identified by `id`. */
|
|
755
|
+
async removeBroadcastList(id) {
|
|
756
|
+
const timestamp = this.serverClock.nowMs();
|
|
757
|
+
await this.enqueueAndFlush([
|
|
758
|
+
buildRemoveMutationFromSchema({
|
|
759
|
+
schema: WA_APPSTATE_SCHEMAS.BusinessBroadcastList,
|
|
760
|
+
indexArgs: { id },
|
|
761
|
+
timestamp
|
|
762
|
+
})
|
|
763
|
+
]);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Applies a `set` mutation against any registered app-state schema. This
|
|
767
|
+
* is the way to reach schemas that don't have a typed helper on this
|
|
768
|
+
* coordinator (Contact, LabelEdit, LabelJid, QuickReply, AiThreadPin,
|
|
769
|
+
* Favorites, Nux, ...). For the common chat actions there's a dedicated
|
|
770
|
+
* method ({@link setChatMute}, {@link setChatRead}, {@link setMessageStar},
|
|
771
|
+
* {@link setChatPin}, {@link setChatArchive}, etc.) – use those instead.
|
|
772
|
+
*
|
|
773
|
+
* `input` is flat – pick a `schema` name from {@link WA_APPSTATE_SCHEMAS},
|
|
774
|
+
* fill the index fields (`id`, `chatJid`, `labelId`, ...) and the value
|
|
775
|
+
* fields side-by-side, and the coordinator routes them to the right
|
|
776
|
+
* SyncActionValue subfield.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* ```ts
|
|
780
|
+
* // Add a contact to the address book
|
|
781
|
+
* await client.chat.set({
|
|
782
|
+
* schema: 'Contact',
|
|
783
|
+
* id: '5511999999999@s.whatsapp.net',
|
|
784
|
+
* contactAction: { fullName: 'Maria Silva', firstName: 'Maria' }
|
|
785
|
+
* })
|
|
786
|
+
*
|
|
787
|
+
* // Create a chat label (color is a server-side palette index)
|
|
788
|
+
* await client.chat.set({
|
|
789
|
+
* schema: 'LabelEdit',
|
|
790
|
+
* id: 'label-1',
|
|
791
|
+
* labelEditAction: { name: 'Pendente', color: 0, isActive: true }
|
|
792
|
+
* })
|
|
793
|
+
*
|
|
794
|
+
* // Apply that label to a chat
|
|
795
|
+
* await client.chat.set({
|
|
796
|
+
* schema: 'LabelJid',
|
|
797
|
+
* labelId: 'label-1',
|
|
798
|
+
* chatJid: '5511999999999@s.whatsapp.net',
|
|
799
|
+
* labelAssociationAction: { labeled: true }
|
|
800
|
+
* })
|
|
801
|
+
*
|
|
802
|
+
* // Save a business quick reply
|
|
803
|
+
* await client.chat.set({
|
|
804
|
+
* schema: 'QuickReply',
|
|
805
|
+
* id: 'qr-greeting',
|
|
806
|
+
* quickReplyAction: { shortcut: '/oi', message: 'Olá! Tudo bem?' }
|
|
807
|
+
* })
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
810
|
+
async set(input) {
|
|
811
|
+
const resolved = WA_APPSTATE_SCHEMAS[input.schema];
|
|
812
|
+
const { indexArgs, data } = splitFlatInput(resolved, input);
|
|
813
|
+
const value = wrapData(resolved, data);
|
|
814
|
+
const timestamp = this.serverClock.nowMs();
|
|
815
|
+
const mutation = buildSetMutationFromSchema({
|
|
816
|
+
schema: resolved,
|
|
817
|
+
indexArgs: indexArgs,
|
|
818
|
+
value,
|
|
819
|
+
timestamp
|
|
820
|
+
});
|
|
821
|
+
await this.enqueueAndFlush([mutation]);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Applies a `remove` mutation against any registered app-state schema -
|
|
825
|
+
* same shape as {@link set} but without the value fields (only the schema
|
|
826
|
+
* name + index args). Use this for schemas without a typed helper.
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```ts
|
|
830
|
+
* // Drop a contact from the address book
|
|
831
|
+
* await client.chat.remove({
|
|
832
|
+
* schema: 'Contact',
|
|
833
|
+
* id: '5511999999999@s.whatsapp.net'
|
|
834
|
+
* })
|
|
835
|
+
*
|
|
836
|
+
* // Remove a label from a chat (the label itself stays – use LabelEdit
|
|
837
|
+
* // with `deleted: true` to delete the label definition entirely)
|
|
838
|
+
* await client.chat.remove({
|
|
839
|
+
* schema: 'LabelJid',
|
|
840
|
+
* labelId: 'label-1',
|
|
841
|
+
* chatJid: '5511999999999@s.whatsapp.net'
|
|
842
|
+
* })
|
|
843
|
+
*
|
|
844
|
+
* // Delete a quick reply
|
|
845
|
+
* await client.chat.remove({
|
|
846
|
+
* schema: 'QuickReply',
|
|
847
|
+
* id: 'qr-greeting'
|
|
848
|
+
* })
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
async remove(input) {
|
|
852
|
+
const resolved = WA_APPSTATE_SCHEMAS[input.schema];
|
|
853
|
+
const { indexArgs } = splitFlatInput(resolved, input);
|
|
854
|
+
const timestamp = this.serverClock.nowMs();
|
|
855
|
+
const mutation = buildRemoveMutationFromSchema({
|
|
856
|
+
schema: resolved,
|
|
857
|
+
indexArgs: indexArgs,
|
|
858
|
+
timestamp
|
|
859
|
+
});
|
|
860
|
+
await this.enqueueAndFlush([mutation]);
|
|
335
861
|
}
|
|
336
862
|
async createArchiveMutation(chatIndexJid, archived, timestamp) {
|
|
337
863
|
const messageRange = await this.buildChatMessageRange(chatIndexJid);
|
|
338
|
-
return
|
|
339
|
-
|
|
340
|
-
chatIndexJid,
|
|
341
|
-
value: {
|
|
342
|
-
archiveChatAction: {
|
|
343
|
-
archived,
|
|
344
|
-
messageRange
|
|
345
|
-
}
|
|
346
|
-
},
|
|
864
|
+
return buildSetMutationFromSchema({
|
|
865
|
+
schema: WA_APPSTATE_SCHEMAS.Archive,
|
|
866
|
+
indexArgs: { chatJid: chatIndexJid },
|
|
867
|
+
value: { archiveChatAction: { archived, messageRange } },
|
|
347
868
|
timestamp
|
|
348
869
|
});
|
|
349
870
|
}
|
|
@@ -428,8 +949,10 @@ export class WaAppStateMutationCoordinator {
|
|
|
428
949
|
const fromMe = message.fromMe === true;
|
|
429
950
|
const participant = this.resolveMessageMutationParticipant(chatIndexJid, fromMe, message.participantJid);
|
|
430
951
|
return {
|
|
431
|
-
chatIndexJid,
|
|
432
|
-
|
|
952
|
+
remote: chatIndexJid,
|
|
953
|
+
id: messageId,
|
|
954
|
+
fromMe,
|
|
955
|
+
participant
|
|
433
956
|
};
|
|
434
957
|
}
|
|
435
958
|
resolveMessageMutationParticipant(chatIndexJid, fromMe, participantJid) {
|
|
@@ -445,9 +968,6 @@ export class WaAppStateMutationCoordinator {
|
|
|
445
968
|
}
|
|
446
969
|
return normalizeDeviceJid(normalized);
|
|
447
970
|
}
|
|
448
|
-
buildMutationIndex(action, chatIndexJid, indexPartsTail) {
|
|
449
|
-
return JSON.stringify([action, chatIndexJid, ...indexPartsTail]);
|
|
450
|
-
}
|
|
451
971
|
describeMutationActions(mutations) {
|
|
452
972
|
return mutations
|
|
453
973
|
.map((mutation) => {
|