shellzapy 0.1.0__py3-none-any.whl
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.
- shellzapy-0.1.0.dist-info/METADATA +112 -0
- shellzapy-0.1.0.dist-info/RECORD +345 -0
- shellzapy-0.1.0.dist-info/WHEEL +4 -0
- shellzapy-0.1.0.dist-info/licenses/LICENSE +21 -0
- shellzapy-0.1.0.dist-info/licenses/NOTICE +9 -0
- zapy/__init__.py +58 -0
- zapy/_appstate/__init__.py +59 -0
- zapy/_appstate/constants.py +82 -0
- zapy/_appstate/crypto/__init__.py +17 -0
- zapy/_appstate/crypto/app_state_crypto.py +401 -0
- zapy/_appstate/parsers/__init__.py +23 -0
- zapy/_appstate/parsers/encoding.py +157 -0
- zapy/_appstate/parsers/response_parser.py +135 -0
- zapy/_appstate/sync/__init__.py +11 -0
- zapy/_appstate/sync/sync_client.py +1559 -0
- zapy/_appstate/types.py +137 -0
- zapy/_appstate/utils.py +100 -0
- zapy/_auth/__init__.py +3 -0
- zapy/_auth/auth_client.py +618 -0
- zapy/_auth/credentials_flow.py +290 -0
- zapy/_auth/pairing/__init__.py +3 -0
- zapy/_auth/pairing/companion_host.py +239 -0
- zapy/_auth/pairing/flow.py +808 -0
- zapy/_auth/pairing/pairing_code_crypto.py +143 -0
- zapy/_auth/pairing/qr_flow.py +123 -0
- zapy/_auth/pairing/shortcake_crypto.py +122 -0
- zapy/_auth/pairing/shortcake_flow.py +393 -0
- zapy/_auth/types.py +110 -0
- zapy/_client/__init__.py +26 -0
- zapy/_client/client.py +972 -0
- zapy/_client/connection/__init__.py +6 -0
- zapy/_client/connection/manager.py +525 -0
- zapy/_client/connection/receipt_queue.py +74 -0
- zapy/_client/coordinators/__init__.py +81 -0
- zapy/_client/coordinators/ab_props.py +260 -0
- zapy/_client/coordinators/app_state_mutation.py +2538 -0
- zapy/_client/coordinators/bot.py +830 -0
- zapy/_client/coordinators/broadcast_list.py +101 -0
- zapy/_client/coordinators/business.py +247 -0
- zapy/_client/coordinators/email.py +158 -0
- zapy/_client/coordinators/group.py +1478 -0
- zapy/_client/coordinators/incoming_node.py +758 -0
- zapy/_client/coordinators/low_level.py +119 -0
- zapy/_client/coordinators/message.py +1153 -0
- zapy/_client/coordinators/message_dispatch.py +1637 -0
- zapy/_client/coordinators/newsletter.py +110 -0
- zapy/_client/coordinators/offline_resume.py +271 -0
- zapy/_client/coordinators/passive_tasks.py +447 -0
- zapy/_client/coordinators/presence.py +103 -0
- zapy/_client/coordinators/privacy.py +623 -0
- zapy/_client/coordinators/profile.py +1024 -0
- zapy/_client/coordinators/retry.py +1878 -0
- zapy/_client/coordinators/status.py +132 -0
- zapy/_client/coordinators/stream_control.py +260 -0
- zapy/_client/coordinators/trusted_contact_token.py +417 -0
- zapy/_client/events/__init__.py +266 -0
- zapy/_client/events/abprops.py +58 -0
- zapy/_client/events/appstate_mutation.py +248 -0
- zapy/_client/events/business.py +565 -0
- zapy/_client/events/call.py +144 -0
- zapy/_client/events/chatstate.py +41 -0
- zapy/_client/events/devices.py +122 -0
- zapy/_client/events/dirty.py +384 -0
- zapy/_client/events/group.py +655 -0
- zapy/_client/events/identity.py +40 -0
- zapy/_client/events/incoming.py +1079 -0
- zapy/_client/events/mex_notification.py +317 -0
- zapy/_client/events/offline.py +123 -0
- zapy/_client/events/picture.py +67 -0
- zapy/_client/events/presence.py +74 -0
- zapy/_client/events/privacy.py +187 -0
- zapy/_client/events/privacy_token.py +72 -0
- zapy/_client/events/receipt.py +109 -0
- zapy/_client/events/registration.py +70 -0
- zapy/_client/events/username.py +76 -0
- zapy/_client/factory.py +2020 -0
- zapy/_client/media.py +829 -0
- zapy/_client/newsletter/__init__.py +90 -0
- zapy/_client/newsletter/admin.py +323 -0
- zapy/_client/newsletter/content.py +499 -0
- zapy/_client/newsletter/discovery.py +233 -0
- zapy/_client/newsletter/messaging.py +396 -0
- zapy/_client/newsletter/mex.py +99 -0
- zapy/_client/newsletter/parse.py +406 -0
- zapy/_client/newsletter/types.py +393 -0
- zapy/_client/persistence/__init__.py +89 -0
- zapy/_client/persistence/companion_host.py +133 -0
- zapy/_client/persistence/ephemeral_setting.py +245 -0
- zapy/_client/persistence/group_history.py +361 -0
- zapy/_client/persistence/history_blob.py +169 -0
- zapy/_client/persistence/history_sync.py +646 -0
- zapy/_client/persistence/mailbox.py +232 -0
- zapy/_client/persistence/write_behind_persistence.py +368 -0
- zapy/_client/plugins/__init__.py +23 -0
- zapy/_client/plugins/define.py +44 -0
- zapy/_client/plugins/install.py +254 -0
- zapy/_client/plugins/types.py +64 -0
- zapy/_client/tokens/__init__.py +21 -0
- zapy/_client/tokens/cs_token.py +47 -0
- zapy/_client/tokens/tc_token.py +43 -0
- zapy/_client/types.py +988 -0
- zapy/_crypto/__init__.py +65 -0
- zapy/_crypto/core/__init__.py +62 -0
- zapy/_crypto/core/hkdf.py +41 -0
- zapy/_crypto/core/keys.py +51 -0
- zapy/_crypto/core/nonce.py +25 -0
- zapy/_crypto/core/primitives.py +179 -0
- zapy/_crypto/core/random.py +32 -0
- zapy/_crypto/core/xeddsa.py +72 -0
- zapy/_crypto/curves/__init__.py +3 -0
- zapy/_crypto/curves/constants.py +10 -0
- zapy/_crypto/curves/ed25519.py +61 -0
- zapy/_crypto/curves/types.py +18 -0
- zapy/_crypto/curves/x25519.py +117 -0
- zapy/_crypto/math/__init__.py +3 -0
- zapy/_crypto/math/constants.py +35 -0
- zapy/_crypto/math/edwards.py +174 -0
- zapy/_crypto/math/fe.py +120 -0
- zapy/_crypto/math/le.py +13 -0
- zapy/_crypto/math/mod.py +15 -0
- zapy/_crypto/math/prime.py +11 -0
- zapy/_crypto/math/types.py +25 -0
- zapy/_crypto/native_backend.py +40 -0
- zapy/_infra/__init__.py +3 -0
- zapy/_infra/log.py +142 -0
- zapy/_infra/perf.py +77 -0
- zapy/_media/__init__.py +64 -0
- zapy/_media/constants.py +133 -0
- zapy/_media/container.py +110 -0
- zapy/_media/crypto/__init__.py +19 -0
- zapy/_media/crypto/crypto.py +633 -0
- zapy/_media/crypto/media_retry.py +107 -0
- zapy/_media/processor.py +100 -0
- zapy/_media/sticker/__init__.py +8 -0
- zapy/_media/sticker/pack.py +188 -0
- zapy/_media/transfer/__init__.py +15 -0
- zapy/_media/transfer/client.py +635 -0
- zapy/_media/transfer/conn.py +48 -0
- zapy/_media/types.py +169 -0
- zapy/_message/__init__.py +121 -0
- zapy/_message/addons/__init__.py +5 -0
- zapy/_message/addons/link_preview/__init__.py +54 -0
- zapy/_message/addons/link_preview/builder.py +56 -0
- zapy/_message/addons/link_preview/detect.py +72 -0
- zapy/_message/addons/link_preview/fetcher.py +553 -0
- zapy/_message/addons/link_preview/types.py +100 -0
- zapy/_message/client.py +486 -0
- zapy/_message/context_info.py +424 -0
- zapy/_message/crypto/__init__.py +71 -0
- zapy/_message/crypto/addon_crypto.py +656 -0
- zapy/_message/crypto/icdc.py +138 -0
- zapy/_message/crypto/phash.py +87 -0
- zapy/_message/crypto/reporting_token.py +498 -0
- zapy/_message/crypto/use_case_secret.py +113 -0
- zapy/_message/encode/__init__.py +84 -0
- zapy/_message/encode/content.py +636 -0
- zapy/_message/encode/device_sent.py +88 -0
- zapy/_message/encode/media_payload.py +122 -0
- zapy/_message/encode/padding.py +27 -0
- zapy/_message/kinds/__init__.py +1 -0
- zapy/_message/kinds/bot.py +179 -0
- zapy/_message/kinds/group_history.py +206 -0
- zapy/_message/kinds/newsletter.py +388 -0
- zapy/_message/kinds/sticker_pack.py +74 -0
- zapy/_message/messaging/__init__.py +336 -0
- zapy/_message/messaging/companion_host.py +117 -0
- zapy/_message/messaging/fanout.py +311 -0
- zapy/_message/messaging/group_metadata.py +444 -0
- zapy/_message/messaging/ignore_key.py +264 -0
- zapy/_message/messaging/key_protocol.py +217 -0
- zapy/_message/messaging/link_preview.py +448 -0
- zapy/_message/messaging/messages.py +1429 -0
- zapy/_message/primitives/__init__.py +1 -0
- zapy/_message/primitives/ack.py +232 -0
- zapy/_message/primitives/incoming.py +1141 -0
- zapy/_message/primitives/media_retry.py +451 -0
- zapy/_message/primitives/peer_data_operation.py +271 -0
- zapy/_message/types.py +434 -0
- zapy/_proto/WAProto_pb2.py +2584 -0
- zapy/_proto/__init__.py +1 -0
- zapy/_protocol/__init__.py +3 -0
- zapy/_protocol/abprops_spec.py +6216 -0
- zapy/_protocol/auth.py +17 -0
- zapy/_protocol/browser.py +57 -0
- zapy/_protocol/defaults.py +38 -0
- zapy/_protocol/device_identity.py +54 -0
- zapy/_protocol/jid.py +241 -0
- zapy/_protocol/message.py +127 -0
- zapy/_protocol/nodes.py +144 -0
- zapy/_protocol/notification.py +18 -0
- zapy/_retry/__init__.py +77 -0
- zapy/_retry/codec.py +209 -0
- zapy/_retry/constants.py +28 -0
- zapy/_retry/parse.py +132 -0
- zapy/_retry/reason.py +65 -0
- zapy/_retry/replay.py +483 -0
- zapy/_retry/tracker.py +161 -0
- zapy/_retry/types.py +122 -0
- zapy/_signal/__init__.py +171 -0
- zapy/_signal/api/__init__.py +133 -0
- zapy/_signal/api/codec.py +164 -0
- zapy/_signal/api/constants.py +14 -0
- zapy/_signal/api/device_sync.py +915 -0
- zapy/_signal/api/digest_sync.py +363 -0
- zapy/_signal/api/identity_sync.py +250 -0
- zapy/_signal/api/missing_pre_keys_sync.py +267 -0
- zapy/_signal/api/prekeys.py +191 -0
- zapy/_signal/api/result_map.py +40 -0
- zapy/_signal/api/rotate_key.py +111 -0
- zapy/_signal/api/session_sync.py +297 -0
- zapy/_signal/attestation.py +145 -0
- zapy/_signal/constants.py +22 -0
- zapy/_signal/encoding.py +78 -0
- zapy/_signal/group/__init__.py +35 -0
- zapy/_signal/group/chain.py +139 -0
- zapy/_signal/group/codec.py +78 -0
- zapy/_signal/group/encoding.py +166 -0
- zapy/_signal/group/manager.py +361 -0
- zapy/_signal/registration/__init__.py +44 -0
- zapy/_signal/registration/keygen.py +46 -0
- zapy/_signal/registration/reg_encoding.py +66 -0
- zapy/_signal/registration/reg_utils.py +52 -0
- zapy/_signal/session/__init__.py +114 -0
- zapy/_signal/session/encoding.py +385 -0
- zapy/_signal/session/protocol.py +590 -0
- zapy/_signal/session/ratchet.py +381 -0
- zapy/_signal/session/resolver.py +630 -0
- zapy/_signal/session/serializer.py +96 -0
- zapy/_signal/session/session.py +272 -0
- zapy/_signal/types.py +214 -0
- zapy/_store/__init__.py +118 -0
- zapy/_store/cache/__init__.py +166 -0
- zapy/_store/cache/identity.py +130 -0
- zapy/_store/cache/privacy_token.py +116 -0
- zapy/_store/cache/sender_key.py +168 -0
- zapy/_store/cache/session.py +142 -0
- zapy/_store/contracts/__init__.py +84 -0
- zapy/_store/contracts/appstate.py +82 -0
- zapy/_store/contracts/auth.py +16 -0
- zapy/_store/contracts/chat_metadata.py +29 -0
- zapy/_store/contracts/contact.py +31 -0
- zapy/_store/contracts/device_list.py +35 -0
- zapy/_store/contracts/group_metadata.py +33 -0
- zapy/_store/contracts/identity.py +18 -0
- zapy/_store/contracts/message.py +36 -0
- zapy/_store/contracts/message_secret.py +41 -0
- zapy/_store/contracts/pre_key.py +32 -0
- zapy/_store/contracts/privacy_token.py +32 -0
- zapy/_store/contracts/retry.py +47 -0
- zapy/_store/contracts/sender_key.py +37 -0
- zapy/_store/contracts/session.py +21 -0
- zapy/_store/contracts/signal.py +23 -0
- zapy/_store/contracts/thread.py +35 -0
- zapy/_store/create_store.py +890 -0
- zapy/_store/locks.py +1154 -0
- zapy/_store/memory/__init__.py +40 -0
- zapy/_store/memory/appstate.py +200 -0
- zapy/_store/memory/auth.py +24 -0
- zapy/_store/memory/chat_metadata.py +124 -0
- zapy/_store/memory/contact.py +125 -0
- zapy/_store/memory/device_list.py +161 -0
- zapy/_store/memory/group_metadata.py +125 -0
- zapy/_store/memory/identity.py +86 -0
- zapy/_store/memory/message.py +85 -0
- zapy/_store/memory/message_secret.py +145 -0
- zapy/_store/memory/pre_key.py +112 -0
- zapy/_store/memory/privacy_token.py +103 -0
- zapy/_store/memory/retry.py +250 -0
- zapy/_store/memory/sender_key.py +162 -0
- zapy/_store/memory/session.py +111 -0
- zapy/_store/memory/signal.py +45 -0
- zapy/_store/memory/thread.py +66 -0
- zapy/_store/noop.py +279 -0
- zapy/_transport/__init__.py +3 -0
- zapy/_transport/binary/__init__.py +77 -0
- zapy/_transport/binary/constants.py +80 -0
- zapy/_transport/binary/decoder.py +260 -0
- zapy/_transport/binary/encoder.py +279 -0
- zapy/_transport/binary/tokens.py +1289 -0
- zapy/_transport/comms.py +759 -0
- zapy/_transport/keepalive/__init__.py +3 -0
- zapy/_transport/keepalive/keep_alive.py +252 -0
- zapy/_transport/node/__init__.py +3 -0
- zapy/_transport/node/builders/__init__.py +9 -0
- zapy/_transport/node/builders/abprops.py +33 -0
- zapy/_transport/node/builders/account_sync.py +120 -0
- zapy/_transport/node/builders/bot.py +56 -0
- zapy/_transport/node/builders/business.py +261 -0
- zapy/_transport/node/builders/chatstate.py +74 -0
- zapy/_transport/node/builders/community.py +116 -0
- zapy/_transport/node/builders/device.py +30 -0
- zapy/_transport/node/builders/email.py +181 -0
- zapy/_transport/node/builders/global_.py +74 -0
- zapy/_transport/node/builders/group.py +279 -0
- zapy/_transport/node/builders/media.py +21 -0
- zapy/_transport/node/builders/message.py +436 -0
- zapy/_transport/node/builders/mobile.py +227 -0
- zapy/_transport/node/builders/newsletter.py +293 -0
- zapy/_transport/node/builders/offline.py +20 -0
- zapy/_transport/node/builders/pairing.py +130 -0
- zapy/_transport/node/builders/passive.py +28 -0
- zapy/_transport/node/builders/prekeys.py +215 -0
- zapy/_transport/node/builders/presence.py +100 -0
- zapy/_transport/node/builders/privacy.py +243 -0
- zapy/_transport/node/builders/privacy_token.py +94 -0
- zapy/_transport/node/builders/profile.py +176 -0
- zapy/_transport/node/builders/retry.py +156 -0
- zapy/_transport/node/builders/shortcake.py +87 -0
- zapy/_transport/node/builders/tos.py +92 -0
- zapy/_transport/node/builders/usync.py +185 -0
- zapy/_transport/node/helpers.py +201 -0
- zapy/_transport/node/orchestrator.py +210 -0
- zapy/_transport/node/query.py +82 -0
- zapy/_transport/node/transport.py +105 -0
- zapy/_transport/node/usync.py +33 -0
- zapy/_transport/node/xml.py +38 -0
- zapy/_transport/noise/__init__.py +7 -0
- zapy/_transport/noise/cert.py +85 -0
- zapy/_transport/noise/client_payload.py +344 -0
- zapy/_transport/noise/constants.py +12 -0
- zapy/_transport/noise/frame_codec.py +120 -0
- zapy/_transport/noise/handshake.py +92 -0
- zapy/_transport/noise/session.py +493 -0
- zapy/_transport/noise/socket.py +45 -0
- zapy/_transport/noise/types.py +66 -0
- zapy/_transport/noise/version.json +3 -0
- zapy/_transport/proxy.py +35 -0
- zapy/_transport/types.py +19 -0
- zapy/_transport/wa_version_fetcher.py +159 -0
- zapy/_transport/web_socket.py +602 -0
- zapy/_util/__init__.py +3 -0
- zapy/_util/bytes.py +131 -0
- zapy/_util/coercion.py +29 -0
- zapy/_util/collections.py +45 -0
- zapy/_util/primitives.py +49 -0
- zapy/client.py +840 -0
- zapy/errors.py +148 -0
- zapy/events.py +564 -0
- zapy/jid.py +140 -0
- zapy/py.typed +0 -0
- zapy/stores/__init__.py +50 -0
- zapy/stores/base.py +1627 -0
- zapy/stores/json_file.py +359 -0
- zapy/stores/memory.py +322 -0
- zapy/stores/sqlite.py +343 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""Discovery-side newsletter operations (mirrors ``newsletter/discovery.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from zapy._client.newsletter.mex import WaNewsletterMexDeps, run_mex
|
|
7
|
+
from zapy._client.newsletter.parse import (
|
|
8
|
+
parse_dehydrated_metadata,
|
|
9
|
+
parse_directory_categories_preview,
|
|
10
|
+
parse_directory_list,
|
|
11
|
+
parse_directory_search,
|
|
12
|
+
parse_domains_previewable,
|
|
13
|
+
parse_newsletter_metadata,
|
|
14
|
+
parse_recommended,
|
|
15
|
+
parse_similar,
|
|
16
|
+
)
|
|
17
|
+
from zapy._client.newsletter.types import (
|
|
18
|
+
NEWSLETTER_VIEW_ROLES,
|
|
19
|
+
WaNewsletterDehydratedMetadata,
|
|
20
|
+
WaNewsletterDirectoryCategoriesPreviewOptions,
|
|
21
|
+
WaNewsletterDirectoryCategoryPreview,
|
|
22
|
+
WaNewsletterDirectoryListOptions,
|
|
23
|
+
WaNewsletterDirectoryResults,
|
|
24
|
+
WaNewsletterDirectorySearchOptions,
|
|
25
|
+
WaNewsletterFetchOptions,
|
|
26
|
+
WaNewsletterMetadata,
|
|
27
|
+
WaNewsletterRecommendedOptions,
|
|
28
|
+
WaNewsletterSimilarOptions,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class WaNewsletterDiscoveryOps:
|
|
33
|
+
"""Discovery-side newsletter operations (lookup, search, recommendations)."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, deps: WaNewsletterMexDeps) -> None:
|
|
36
|
+
self._deps = deps
|
|
37
|
+
|
|
38
|
+
async def _fetch_metadata(
|
|
39
|
+
self, key: str, key_type: str, opts: WaNewsletterFetchOptions | None
|
|
40
|
+
) -> WaNewsletterMetadata:
|
|
41
|
+
view_role = opts.view_role if opts else NEWSLETTER_VIEW_ROLES["SUBSCRIBER"]
|
|
42
|
+
if opts and opts.fetch_full_image is not None:
|
|
43
|
+
fetch_full_image = opts.fetch_full_image
|
|
44
|
+
else:
|
|
45
|
+
fetch_full_image = key_type != "INVITE"
|
|
46
|
+
data = await run_mex(
|
|
47
|
+
self._deps,
|
|
48
|
+
"FetchNewsletter",
|
|
49
|
+
{
|
|
50
|
+
"input": {
|
|
51
|
+
"key": key,
|
|
52
|
+
"type": key_type,
|
|
53
|
+
"view_role": view_role,
|
|
54
|
+
},
|
|
55
|
+
"fetch_viewer_metadata": opts.fetch_viewer_metadata
|
|
56
|
+
if opts and opts.fetch_viewer_metadata is not None
|
|
57
|
+
else True,
|
|
58
|
+
"fetch_full_image": fetch_full_image,
|
|
59
|
+
"fetch_creation_time": opts.fetch_creation_time
|
|
60
|
+
if opts and opts.fetch_creation_time is not None
|
|
61
|
+
else True,
|
|
62
|
+
"fetch_wamo_sub": opts.fetch_wamo_sub
|
|
63
|
+
if opts and opts.fetch_wamo_sub is not None
|
|
64
|
+
else False,
|
|
65
|
+
"fetch_status_metadata": False,
|
|
66
|
+
"fetch_pinned_messages": True,
|
|
67
|
+
},
|
|
68
|
+
)
|
|
69
|
+
envelope = (data or {}).get("xwa2_newsletter")
|
|
70
|
+
if not envelope:
|
|
71
|
+
raise ValueError("newsletter fetch returned no envelope")
|
|
72
|
+
return parse_newsletter_metadata(envelope)
|
|
73
|
+
|
|
74
|
+
async def fetch(
|
|
75
|
+
self, newsletter_jid: str, options: WaNewsletterFetchOptions | None = None
|
|
76
|
+
) -> WaNewsletterMetadata:
|
|
77
|
+
"""Fetch the full metadata for a newsletter by JID."""
|
|
78
|
+
return await self._fetch_metadata(newsletter_jid, "JID", options)
|
|
79
|
+
|
|
80
|
+
async def fetch_by_invite(
|
|
81
|
+
self, invite_code: str, options: WaNewsletterFetchOptions | None = None
|
|
82
|
+
) -> WaNewsletterMetadata:
|
|
83
|
+
"""Fetch the full metadata for a newsletter by invite code."""
|
|
84
|
+
return await self._fetch_metadata(invite_code, "INVITE", options)
|
|
85
|
+
|
|
86
|
+
async def list_subscribed(
|
|
87
|
+
self, fetch_wamo_sub: bool = False
|
|
88
|
+
) -> tuple[WaNewsletterMetadata, ...]:
|
|
89
|
+
"""List newsletters the current account is subscribed to."""
|
|
90
|
+
data = await run_mex(
|
|
91
|
+
self._deps,
|
|
92
|
+
"FetchAllNewslettersMetadata",
|
|
93
|
+
{"fetch_wamo_sub": fetch_wamo_sub, "fetch_status_metadata": False},
|
|
94
|
+
)
|
|
95
|
+
return tuple(
|
|
96
|
+
parse_newsletter_metadata(item)
|
|
97
|
+
for item in (data or {}).get("xwa2_newsletter_subscribed") or []
|
|
98
|
+
if isinstance(item, dict)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
async def search_directory(
|
|
102
|
+
self, options: WaNewsletterDirectorySearchOptions | None = None
|
|
103
|
+
) -> WaNewsletterDirectoryResults:
|
|
104
|
+
"""Search the public newsletter directory by text/categories."""
|
|
105
|
+
data = await run_mex(
|
|
106
|
+
self._deps,
|
|
107
|
+
"FetchNewsletterDirectorySearchResults",
|
|
108
|
+
{
|
|
109
|
+
"input": {
|
|
110
|
+
"search_text": options.search_text if options else "",
|
|
111
|
+
"categories": list(options.categories) if options else [],
|
|
112
|
+
"limit": options.limit if options else 100,
|
|
113
|
+
"start_cursor": options.start_cursor if options else None,
|
|
114
|
+
},
|
|
115
|
+
"fetch_status_metadata": False,
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
return parse_directory_search(data)
|
|
119
|
+
|
|
120
|
+
async def fetch_recommended(
|
|
121
|
+
self, options: WaNewsletterRecommendedOptions | None = None
|
|
122
|
+
) -> tuple[WaNewsletterMetadata, ...]:
|
|
123
|
+
"""List newsletters recommended for the current account."""
|
|
124
|
+
data = await run_mex(
|
|
125
|
+
self._deps,
|
|
126
|
+
"FetchRecommendedNewsletters",
|
|
127
|
+
{
|
|
128
|
+
"input": {
|
|
129
|
+
"limit": options.limit if options else 25,
|
|
130
|
+
"country_codes": list(options.country_codes) if options else [],
|
|
131
|
+
},
|
|
132
|
+
"fetch_status_metadata": False,
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
return parse_recommended(data)
|
|
136
|
+
|
|
137
|
+
async def fetch_similar(
|
|
138
|
+
self,
|
|
139
|
+
newsletter_jid: str,
|
|
140
|
+
options: WaNewsletterSimilarOptions | None = None,
|
|
141
|
+
) -> tuple[WaNewsletterMetadata, ...]:
|
|
142
|
+
"""List newsletters similar to ``newsletter_jid``."""
|
|
143
|
+
data = await run_mex(
|
|
144
|
+
self._deps,
|
|
145
|
+
"FetchSimilarNewsletters",
|
|
146
|
+
{
|
|
147
|
+
"input": {
|
|
148
|
+
"newsletter_id": newsletter_jid,
|
|
149
|
+
"limit": options.limit if options else 10,
|
|
150
|
+
"country_codes": list(options.country_codes) if options else [],
|
|
151
|
+
},
|
|
152
|
+
"fetch_status_metadata": False,
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
return parse_similar(data)
|
|
156
|
+
|
|
157
|
+
async def fetch_directory_list(
|
|
158
|
+
self, options: WaNewsletterDirectoryListOptions
|
|
159
|
+
) -> WaNewsletterDirectoryResults:
|
|
160
|
+
"""Fetch the paged directory listing scoped by country/category."""
|
|
161
|
+
data = await run_mex(
|
|
162
|
+
self._deps,
|
|
163
|
+
"FetchNewsletterDirectoryList",
|
|
164
|
+
{
|
|
165
|
+
"input": {
|
|
166
|
+
"view": options.view,
|
|
167
|
+
"filters": {
|
|
168
|
+
"country_codes": list(options.country_codes),
|
|
169
|
+
"categories": list(options.categories),
|
|
170
|
+
},
|
|
171
|
+
"limit": options.limit,
|
|
172
|
+
"start_cursor": options.start_cursor,
|
|
173
|
+
},
|
|
174
|
+
"fetch_status_metadata": False,
|
|
175
|
+
},
|
|
176
|
+
)
|
|
177
|
+
return parse_directory_list(data)
|
|
178
|
+
|
|
179
|
+
async def fetch_directory_categories_preview(
|
|
180
|
+
self, options: WaNewsletterDirectoryCategoriesPreviewOptions
|
|
181
|
+
) -> tuple[WaNewsletterDirectoryCategoryPreview, ...]:
|
|
182
|
+
"""Fetch preview cards for the directory categories carousel."""
|
|
183
|
+
data = await run_mex(
|
|
184
|
+
self._deps,
|
|
185
|
+
"FetchNewsletterDirectoryCategoriesPreview",
|
|
186
|
+
{
|
|
187
|
+
"input": {
|
|
188
|
+
"categories": list(options.categories),
|
|
189
|
+
"country_code": options.country_code,
|
|
190
|
+
"per_category_limit": options.per_category_limit,
|
|
191
|
+
},
|
|
192
|
+
"fetch_status_metadata": False,
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
return parse_directory_categories_preview(data)
|
|
196
|
+
|
|
197
|
+
async def fetch_is_domain_previewable(self, domains: list[str]) -> dict[str, bool]:
|
|
198
|
+
"""Resolve which of the given URL domains support link previews."""
|
|
199
|
+
data = await run_mex(
|
|
200
|
+
self._deps, "FetchNewsletterIsDomainPreviewable", {"url_domains": domains}
|
|
201
|
+
)
|
|
202
|
+
return parse_domains_previewable(data)
|
|
203
|
+
|
|
204
|
+
async def fetch_dehydrated(
|
|
205
|
+
self,
|
|
206
|
+
key_or_invite: str,
|
|
207
|
+
view_role: str = "SUBSCRIBER",
|
|
208
|
+
fetch_wamo_sub: bool = False,
|
|
209
|
+
) -> WaNewsletterDehydratedMetadata:
|
|
210
|
+
"""Lightweight metadata fetch (no full image / followers)."""
|
|
211
|
+
is_jid = key_or_invite.endswith("@newsletter")
|
|
212
|
+
data = await run_mex(
|
|
213
|
+
self._deps,
|
|
214
|
+
"FetchNewsletterDehydrated",
|
|
215
|
+
{
|
|
216
|
+
"input": {
|
|
217
|
+
"key": key_or_invite,
|
|
218
|
+
"type": "JID" if is_jid else "INVITE",
|
|
219
|
+
"view_role": view_role,
|
|
220
|
+
},
|
|
221
|
+
"fetch_wamo_sub": fetch_wamo_sub,
|
|
222
|
+
"fetch_pinned_messages": True,
|
|
223
|
+
},
|
|
224
|
+
)
|
|
225
|
+
return parse_dehydrated_metadata(data)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def create_discovery_ops(deps: WaNewsletterMexDeps) -> WaNewsletterDiscoveryOps:
|
|
229
|
+
"""Build the discovery operation set (mirrors ``createDiscoveryOps``)."""
|
|
230
|
+
return WaNewsletterDiscoveryOps(deps)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
__all__: list[str] = ["WaNewsletterDiscoveryOps", "create_discovery_ops"]
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""Newsletter messaging operations (mirrors ``newsletter/messaging.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Awaitable, Callable
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from zapy._client.newsletter.content import (
|
|
10
|
+
BuildNewsletterContentOptions,
|
|
11
|
+
WaNewsletterBuiltContent,
|
|
12
|
+
build_newsletter_message_content,
|
|
13
|
+
)
|
|
14
|
+
from zapy._client.newsletter.mex import (
|
|
15
|
+
WaNewsletterMexDeps,
|
|
16
|
+
ensure_tos_accepted,
|
|
17
|
+
run_mex,
|
|
18
|
+
)
|
|
19
|
+
from zapy._client.newsletter.types import (
|
|
20
|
+
NEWSLETTER_MUTE_TYPES,
|
|
21
|
+
NEWSLETTER_MUTE_VALUES,
|
|
22
|
+
WaNewsletterMuteInput,
|
|
23
|
+
WaNewsletterReactInput,
|
|
24
|
+
WaNewsletterRevokeInput,
|
|
25
|
+
WaNewsletterSendOptions,
|
|
26
|
+
WaNewsletterSendResult,
|
|
27
|
+
WaNewsletterViewReceiptInput,
|
|
28
|
+
WaNewsletterVotePollInput,
|
|
29
|
+
)
|
|
30
|
+
from zapy._transport.node.builders.newsletter import (
|
|
31
|
+
NEWSLETTER_MESSAGE_EDIT_MEDIA,
|
|
32
|
+
NEWSLETTER_MESSAGE_EDIT_TEXT,
|
|
33
|
+
NEWSLETTER_MESSAGE_MEDIA,
|
|
34
|
+
NEWSLETTER_MESSAGE_POLL_CREATION,
|
|
35
|
+
NEWSLETTER_MESSAGE_POLL_VOTE,
|
|
36
|
+
NEWSLETTER_MESSAGE_REACTION,
|
|
37
|
+
NEWSLETTER_MESSAGE_REACTION_REVOKE,
|
|
38
|
+
NEWSLETTER_MESSAGE_REVOKE,
|
|
39
|
+
NEWSLETTER_MESSAGE_TEXT,
|
|
40
|
+
BuildNewsletterMessageInput,
|
|
41
|
+
BuildNewsletterMessageUpdatesInput,
|
|
42
|
+
BuildNewsletterMessagesInput,
|
|
43
|
+
BuildNewsletterViewReceiptInput,
|
|
44
|
+
build_newsletter_message_node,
|
|
45
|
+
build_newsletter_message_updates_iq,
|
|
46
|
+
build_newsletter_messages_iq,
|
|
47
|
+
build_newsletter_subscribe_live_updates_iq,
|
|
48
|
+
build_newsletter_view_receipt_node,
|
|
49
|
+
)
|
|
50
|
+
from zapy._transport.node.helpers import find_node_child
|
|
51
|
+
from zapy._transport.types import BinaryNode
|
|
52
|
+
|
|
53
|
+
# Mirrors ``WA_NEWSLETTER_NOTIFICATION_TAGS`` (``src/protocol/notification.ts``).
|
|
54
|
+
NEWSLETTER_LIVE_UPDATES_TAG: str = "live_updates"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True, slots=True)
|
|
58
|
+
class WaNewsletterMessagingDeps:
|
|
59
|
+
"""Messaging dependencies (mirrors ``WaNewsletterMessagingDeps``)."""
|
|
60
|
+
|
|
61
|
+
mex: WaNewsletterMexDeps
|
|
62
|
+
send_node: Callable[[BinaryNode], Awaitable[None]]
|
|
63
|
+
publish_message_node: Callable[[BinaryNode], Awaitable[WaNewsletterSendResult]]
|
|
64
|
+
generate_stanza_id: Callable[[], Awaitable[str]]
|
|
65
|
+
content_options: BuildNewsletterContentOptions
|
|
66
|
+
query_with_context: (
|
|
67
|
+
Callable[[str, BinaryNode, int | None], Awaitable[BinaryNode]] | None
|
|
68
|
+
) = None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _to_upload_summary(built: WaNewsletterBuiltContent) -> dict[str, Any] | None:
|
|
72
|
+
if built.upload is None:
|
|
73
|
+
return None
|
|
74
|
+
return {
|
|
75
|
+
"url": built.upload.url,
|
|
76
|
+
"directPath": built.upload.direct_path,
|
|
77
|
+
"fileSha256": built.upload.file_sha256,
|
|
78
|
+
"fileLength": built.upload.file_length,
|
|
79
|
+
"metadataUrl": built.upload.metadata_url,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _build_dispatch_node(
|
|
84
|
+
newsletter_jid: str,
|
|
85
|
+
stanza_id: str,
|
|
86
|
+
built: WaNewsletterBuiltContent,
|
|
87
|
+
edit_parent_message_id: str | None,
|
|
88
|
+
additional_attributes: dict[str, str] | None,
|
|
89
|
+
) -> BinaryNode:
|
|
90
|
+
if built.kind == "poll-creation":
|
|
91
|
+
if edit_parent_message_id is not None:
|
|
92
|
+
raise ValueError("newsletter poll creation cannot be sent as an edit")
|
|
93
|
+
return build_newsletter_message_node(
|
|
94
|
+
BuildNewsletterMessageInput(
|
|
95
|
+
kind=NEWSLETTER_MESSAGE_POLL_CREATION,
|
|
96
|
+
to=newsletter_jid,
|
|
97
|
+
id=stanza_id,
|
|
98
|
+
plaintext=built.plaintext,
|
|
99
|
+
additional_attributes=additional_attributes,
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
if built.kind == "media":
|
|
103
|
+
if built.media_type is None:
|
|
104
|
+
raise ValueError("newsletter media content missing mediaType attribute")
|
|
105
|
+
if edit_parent_message_id is not None:
|
|
106
|
+
return build_newsletter_message_node(
|
|
107
|
+
BuildNewsletterMessageInput(
|
|
108
|
+
kind=NEWSLETTER_MESSAGE_EDIT_MEDIA,
|
|
109
|
+
to=newsletter_jid,
|
|
110
|
+
parent_message_id=edit_parent_message_id,
|
|
111
|
+
plaintext=built.plaintext,
|
|
112
|
+
media_type=built.media_type,
|
|
113
|
+
additional_attributes=additional_attributes,
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
return build_newsletter_message_node(
|
|
117
|
+
BuildNewsletterMessageInput(
|
|
118
|
+
kind=NEWSLETTER_MESSAGE_MEDIA,
|
|
119
|
+
to=newsletter_jid,
|
|
120
|
+
id=stanza_id,
|
|
121
|
+
plaintext=built.plaintext,
|
|
122
|
+
media_type=built.media_type,
|
|
123
|
+
media_handle=built.upload.handle if built.upload else None,
|
|
124
|
+
additional_attributes=additional_attributes,
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
if edit_parent_message_id is not None:
|
|
128
|
+
return build_newsletter_message_node(
|
|
129
|
+
BuildNewsletterMessageInput(
|
|
130
|
+
kind=NEWSLETTER_MESSAGE_EDIT_TEXT,
|
|
131
|
+
to=newsletter_jid,
|
|
132
|
+
parent_message_id=edit_parent_message_id,
|
|
133
|
+
plaintext=built.plaintext,
|
|
134
|
+
additional_attributes=additional_attributes,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
return build_newsletter_message_node(
|
|
138
|
+
BuildNewsletterMessageInput(
|
|
139
|
+
kind=NEWSLETTER_MESSAGE_TEXT,
|
|
140
|
+
to=newsletter_jid,
|
|
141
|
+
id=stanza_id,
|
|
142
|
+
plaintext=built.plaintext,
|
|
143
|
+
additional_attributes=additional_attributes,
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class WaNewsletterMessagingOps:
|
|
149
|
+
"""Newsletter messaging operations (send, react, fetch, follow)."""
|
|
150
|
+
|
|
151
|
+
def __init__(self, deps: WaNewsletterMessagingDeps) -> None:
|
|
152
|
+
self._deps = deps
|
|
153
|
+
|
|
154
|
+
async def _resolve_stanza_id(self, provided: str | None) -> str:
|
|
155
|
+
if provided is not None:
|
|
156
|
+
return provided
|
|
157
|
+
return await self._deps.generate_stanza_id()
|
|
158
|
+
|
|
159
|
+
async def _require_query(
|
|
160
|
+
self, context: str, node: BinaryNode, op: str
|
|
161
|
+
) -> BinaryNode:
|
|
162
|
+
query = self._deps.query_with_context
|
|
163
|
+
if query is None:
|
|
164
|
+
raise ValueError(f"newsletter {op} requires queryWithContext")
|
|
165
|
+
return await query(context, node, None)
|
|
166
|
+
|
|
167
|
+
async def send(
|
|
168
|
+
self,
|
|
169
|
+
newsletter_jid: str,
|
|
170
|
+
content: Any,
|
|
171
|
+
options: WaNewsletterSendOptions | None = None,
|
|
172
|
+
) -> WaNewsletterSendResult:
|
|
173
|
+
"""Publish a message to the newsletter."""
|
|
174
|
+
stanza_id = await self._resolve_stanza_id(
|
|
175
|
+
options.stanza_id if options else None
|
|
176
|
+
)
|
|
177
|
+
built = await build_newsletter_message_content(
|
|
178
|
+
self._deps.content_options, content
|
|
179
|
+
)
|
|
180
|
+
node = _build_dispatch_node(
|
|
181
|
+
newsletter_jid,
|
|
182
|
+
stanza_id,
|
|
183
|
+
built,
|
|
184
|
+
None,
|
|
185
|
+
options.additional_attributes if options else None,
|
|
186
|
+
)
|
|
187
|
+
result = await self._deps.publish_message_node(node)
|
|
188
|
+
return WaNewsletterSendResult(
|
|
189
|
+
id=result.id,
|
|
190
|
+
timestamp_ms=result.timestamp_ms,
|
|
191
|
+
upload=_to_upload_summary(built),
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
async def edit_message(
|
|
195
|
+
self, newsletter_jid: str, parent_message_id: str, content: Any
|
|
196
|
+
) -> WaNewsletterSendResult:
|
|
197
|
+
"""Edit a previously-published newsletter message."""
|
|
198
|
+
built = await build_newsletter_message_content(
|
|
199
|
+
self._deps.content_options, content
|
|
200
|
+
)
|
|
201
|
+
if built.kind == "poll-creation":
|
|
202
|
+
raise ValueError("newsletter poll creations cannot be edited")
|
|
203
|
+
node = _build_dispatch_node(
|
|
204
|
+
newsletter_jid, parent_message_id, built, parent_message_id, None
|
|
205
|
+
)
|
|
206
|
+
result = await self._deps.publish_message_node(node)
|
|
207
|
+
return WaNewsletterSendResult(
|
|
208
|
+
id=result.id,
|
|
209
|
+
timestamp_ms=result.timestamp_ms,
|
|
210
|
+
upload=_to_upload_summary(built),
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
async def react(self, input: WaNewsletterReactInput) -> dict[str, str]:
|
|
214
|
+
"""React (or clear the reaction) on a newsletter message."""
|
|
215
|
+
stanza_id = await self._resolve_stanza_id(input.stanza_id)
|
|
216
|
+
if input.revoke:
|
|
217
|
+
node = build_newsletter_message_node(
|
|
218
|
+
BuildNewsletterMessageInput(
|
|
219
|
+
kind=NEWSLETTER_MESSAGE_REACTION_REVOKE,
|
|
220
|
+
to=input.newsletter_jid,
|
|
221
|
+
id=stanza_id,
|
|
222
|
+
parent_message_server_id=input.parent_message_server_id,
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
else:
|
|
226
|
+
node = build_newsletter_message_node(
|
|
227
|
+
BuildNewsletterMessageInput(
|
|
228
|
+
kind=NEWSLETTER_MESSAGE_REACTION,
|
|
229
|
+
to=input.newsletter_jid,
|
|
230
|
+
id=stanza_id,
|
|
231
|
+
parent_message_server_id=input.parent_message_server_id,
|
|
232
|
+
reaction_code=input.reaction_code,
|
|
233
|
+
)
|
|
234
|
+
)
|
|
235
|
+
await self._deps.send_node(node)
|
|
236
|
+
return {"stanzaId": stanza_id}
|
|
237
|
+
|
|
238
|
+
async def revoke(self, input: WaNewsletterRevokeInput) -> dict[str, str]:
|
|
239
|
+
"""Revoke a previously-published newsletter message."""
|
|
240
|
+
node = build_newsletter_message_node(
|
|
241
|
+
BuildNewsletterMessageInput(
|
|
242
|
+
kind=NEWSLETTER_MESSAGE_REVOKE,
|
|
243
|
+
to=input.newsletter_jid,
|
|
244
|
+
parent_message_id=input.original_message_id,
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
result = await self._deps.publish_message_node(node)
|
|
248
|
+
return {"stanzaId": result.id}
|
|
249
|
+
|
|
250
|
+
async def vote_poll(self, input: WaNewsletterVotePollInput) -> dict[str, str]:
|
|
251
|
+
"""Cast a vote on a newsletter poll."""
|
|
252
|
+
stanza_id = await self._resolve_stanza_id(input.stanza_id)
|
|
253
|
+
await self._deps.send_node(
|
|
254
|
+
build_newsletter_message_node(
|
|
255
|
+
BuildNewsletterMessageInput(
|
|
256
|
+
kind=NEWSLETTER_MESSAGE_POLL_VOTE,
|
|
257
|
+
to=input.newsletter_jid,
|
|
258
|
+
id=stanza_id,
|
|
259
|
+
parent_message_server_id=input.parent_message_server_id,
|
|
260
|
+
votes=tuple(input.votes),
|
|
261
|
+
content_type=input.content_type,
|
|
262
|
+
)
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
return {"stanzaId": stanza_id}
|
|
266
|
+
|
|
267
|
+
async def send_view_receipt(
|
|
268
|
+
self, input: WaNewsletterViewReceiptInput
|
|
269
|
+
) -> dict[str, str]:
|
|
270
|
+
"""Send a view-receipt notification for a newsletter message."""
|
|
271
|
+
stanza_id = await self._resolve_stanza_id(input.stanza_id)
|
|
272
|
+
await self._deps.send_node(
|
|
273
|
+
build_newsletter_view_receipt_node(
|
|
274
|
+
BuildNewsletterViewReceiptInput(
|
|
275
|
+
to=input.newsletter_jid,
|
|
276
|
+
id=stanza_id,
|
|
277
|
+
item_server_ids=tuple(input.item_server_ids),
|
|
278
|
+
)
|
|
279
|
+
)
|
|
280
|
+
)
|
|
281
|
+
return {"stanzaId": stanza_id}
|
|
282
|
+
|
|
283
|
+
async def fetch_messages(
|
|
284
|
+
self,
|
|
285
|
+
newsletter_jid: str,
|
|
286
|
+
count: int,
|
|
287
|
+
before: int | None = None,
|
|
288
|
+
after: int | None = None,
|
|
289
|
+
view_role: str | None = None,
|
|
290
|
+
) -> BinaryNode:
|
|
291
|
+
"""Fetch a page of newsletter messages."""
|
|
292
|
+
return await self._require_query(
|
|
293
|
+
"newsletter.fetch_messages",
|
|
294
|
+
build_newsletter_messages_iq(
|
|
295
|
+
BuildNewsletterMessagesInput(
|
|
296
|
+
newsletter_jid=newsletter_jid,
|
|
297
|
+
count=count,
|
|
298
|
+
before=before,
|
|
299
|
+
after=after,
|
|
300
|
+
view_role=view_role,
|
|
301
|
+
)
|
|
302
|
+
),
|
|
303
|
+
"fetchMessages",
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
async def fetch_message_updates(
|
|
307
|
+
self,
|
|
308
|
+
newsletter_jid: str,
|
|
309
|
+
count: int,
|
|
310
|
+
since: int | None = None,
|
|
311
|
+
before: int | None = None,
|
|
312
|
+
after: int | None = None,
|
|
313
|
+
) -> BinaryNode:
|
|
314
|
+
"""Fetch edits/reactions/poll updates for newsletter messages."""
|
|
315
|
+
return await self._require_query(
|
|
316
|
+
"newsletter.fetch_message_updates",
|
|
317
|
+
build_newsletter_message_updates_iq(
|
|
318
|
+
BuildNewsletterMessageUpdatesInput(
|
|
319
|
+
newsletter_jid=newsletter_jid,
|
|
320
|
+
count=count,
|
|
321
|
+
since=since,
|
|
322
|
+
before=before,
|
|
323
|
+
after=after,
|
|
324
|
+
)
|
|
325
|
+
),
|
|
326
|
+
"fetchMessageUpdates",
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
async def subscribe_live_updates(self, newsletter_jid: str) -> dict[str, int]:
|
|
330
|
+
"""Subscribe to live updates; returns the granted duration."""
|
|
331
|
+
response = await self._require_query(
|
|
332
|
+
"newsletter.subscribe_live_updates",
|
|
333
|
+
build_newsletter_subscribe_live_updates_iq(newsletter_jid),
|
|
334
|
+
"subscribeLiveUpdates",
|
|
335
|
+
)
|
|
336
|
+
live_updates = find_node_child(response, NEWSLETTER_LIVE_UPDATES_TAG)
|
|
337
|
+
duration_attr = live_updates.attrs.get("duration") if live_updates else None
|
|
338
|
+
try:
|
|
339
|
+
parsed = int(duration_attr) if duration_attr is not None else -1
|
|
340
|
+
except ValueError:
|
|
341
|
+
parsed = -1
|
|
342
|
+
if parsed < 30 or parsed > 600:
|
|
343
|
+
raise ValueError(
|
|
344
|
+
"newsletter subscribeLiveUpdates returned "
|
|
345
|
+
f"invalid duration: {duration_attr}"
|
|
346
|
+
)
|
|
347
|
+
return {"durationSeconds": parsed}
|
|
348
|
+
|
|
349
|
+
async def follow(self, newsletter_jid: str) -> None:
|
|
350
|
+
"""Follow the newsletter on the current account."""
|
|
351
|
+
await ensure_tos_accepted(self._deps.mex, "consumer")
|
|
352
|
+
await run_mex(
|
|
353
|
+
self._deps.mex, "JoinNewsletter", {"newsletter_id": newsletter_jid}
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
async def unfollow(self, newsletter_jid: str) -> None:
|
|
357
|
+
"""Unfollow the newsletter on the current account."""
|
|
358
|
+
await run_mex(
|
|
359
|
+
self._deps.mex, "LeaveNewsletter", {"newsletter_id": newsletter_jid}
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
async def mute(self, input: WaNewsletterMuteInput) -> None:
|
|
363
|
+
"""Mute or unmute the newsletter."""
|
|
364
|
+
mute_type = (
|
|
365
|
+
NEWSLETTER_MUTE_TYPES["ADMIN_ACTIVITY"]
|
|
366
|
+
if input.type == "admin"
|
|
367
|
+
else NEWSLETTER_MUTE_TYPES["FOLLOWER_ACTIVITY"]
|
|
368
|
+
)
|
|
369
|
+
value = (
|
|
370
|
+
NEWSLETTER_MUTE_VALUES["ON"]
|
|
371
|
+
if input.mute
|
|
372
|
+
else NEWSLETTER_MUTE_VALUES["OFF"]
|
|
373
|
+
)
|
|
374
|
+
await run_mex(
|
|
375
|
+
self._deps.mex,
|
|
376
|
+
"UpdateNewsletterUserSetting",
|
|
377
|
+
{
|
|
378
|
+
"input": {
|
|
379
|
+
"newsletter_id": input.newsletter_jid,
|
|
380
|
+
"type": mute_type,
|
|
381
|
+
"value": value,
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def create_messaging_ops(deps: WaNewsletterMessagingDeps) -> WaNewsletterMessagingOps:
|
|
388
|
+
"""Build the messaging operation set (mirrors ``createMessagingOps``)."""
|
|
389
|
+
return WaNewsletterMessagingOps(deps)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
__all__: list[str] = [
|
|
393
|
+
"WaNewsletterMessagingDeps",
|
|
394
|
+
"WaNewsletterMessagingOps",
|
|
395
|
+
"create_messaging_ops",
|
|
396
|
+
]
|