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,317 @@
|
|
|
1
|
+
"""MEX (GraphQL) notification parser (``src/client/events/mex-notification.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import math
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import Any, Callable
|
|
9
|
+
|
|
10
|
+
from zapy._protocol.nodes import WA_NODE_TAGS
|
|
11
|
+
from zapy._transport.node.helpers import find_node_child
|
|
12
|
+
from zapy._transport.types import BinaryNode
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _try_as_record(value: Any) -> dict[str, Any] | None:
|
|
16
|
+
if isinstance(value, dict):
|
|
17
|
+
return value
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _try_as_string(value: Any) -> str | None:
|
|
22
|
+
if isinstance(value, str) and len(value) > 0:
|
|
23
|
+
return value
|
|
24
|
+
return None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _try_as_number(value: Any) -> float | None:
|
|
28
|
+
if isinstance(value, bool):
|
|
29
|
+
return None
|
|
30
|
+
if isinstance(value, (int, float)):
|
|
31
|
+
return value if math.isfinite(value) else None
|
|
32
|
+
if isinstance(value, str):
|
|
33
|
+
normalized = value.strip()
|
|
34
|
+
if not normalized:
|
|
35
|
+
return None
|
|
36
|
+
try:
|
|
37
|
+
parsed = float(normalized)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return None
|
|
40
|
+
return parsed if math.isfinite(parsed) else None
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True, slots=True)
|
|
45
|
+
class WaMexNotificationGraphQlError:
|
|
46
|
+
"""One entry of the ``errors`` array of a MEX notification."""
|
|
47
|
+
|
|
48
|
+
message: str | None = None
|
|
49
|
+
path: list[str] | None = None
|
|
50
|
+
extensions: dict[str, Any] | None = None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass(frozen=True, slots=True)
|
|
54
|
+
class WaMexNotificationParsed:
|
|
55
|
+
"""A MEX notification with its ``update`` payload normalized by operation name."""
|
|
56
|
+
|
|
57
|
+
kind: str
|
|
58
|
+
operation_name: str
|
|
59
|
+
errors: list[WaMexNotificationGraphQlError] = field(default_factory=list)
|
|
60
|
+
data: Any = None
|
|
61
|
+
username: str | None = None
|
|
62
|
+
lid_jid: str | None = None
|
|
63
|
+
display_name: str | None = None
|
|
64
|
+
contact_hash: str | None = None
|
|
65
|
+
own_lid_jid: str | None = None
|
|
66
|
+
state: str | None = None
|
|
67
|
+
pin: str | None = None
|
|
68
|
+
jid: str | None = None
|
|
69
|
+
text: str | None = None
|
|
70
|
+
emoji: str | None = None
|
|
71
|
+
ephemeral_duration_sec: float | None = None
|
|
72
|
+
last_update_time: float | None = None
|
|
73
|
+
old_lid_jid: str | None = None
|
|
74
|
+
new_lid_jid: str | None = None
|
|
75
|
+
capping_status: str | None = None
|
|
76
|
+
ote_status: str | None = None
|
|
77
|
+
mv_status: str | None = None
|
|
78
|
+
total_quota: float | None = None
|
|
79
|
+
used_quota: float | None = None
|
|
80
|
+
cycle_start_timestamp: float | None = None
|
|
81
|
+
cycle_end_timestamp: float | None = None
|
|
82
|
+
server_sent_timestamp: float | None = None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _normalize_username_set(data: Any) -> dict[str, Any] | None:
|
|
86
|
+
outer = _try_as_record(data)
|
|
87
|
+
payload = (
|
|
88
|
+
_try_as_record(outer.get("xwa2_notify_username_on_change")) if outer else None
|
|
89
|
+
)
|
|
90
|
+
if payload is None:
|
|
91
|
+
return None
|
|
92
|
+
username = _try_as_string(payload.get("username"))
|
|
93
|
+
lid_jid = _try_as_string(payload.get("lid"))
|
|
94
|
+
if not username or not lid_jid:
|
|
95
|
+
return None
|
|
96
|
+
return {
|
|
97
|
+
"kind": "username_set",
|
|
98
|
+
"operation_name": "UsernameSetNotification",
|
|
99
|
+
"username": username,
|
|
100
|
+
"lid_jid": lid_jid,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _normalize_username_delete(data: Any) -> dict[str, Any] | None:
|
|
105
|
+
outer = _try_as_record(data)
|
|
106
|
+
payload = (
|
|
107
|
+
_try_as_record(outer.get("xwa2_notify_username_delete")) if outer else None
|
|
108
|
+
)
|
|
109
|
+
if payload is None:
|
|
110
|
+
return None
|
|
111
|
+
lid_jid = _try_as_string(payload.get("lid"))
|
|
112
|
+
if not lid_jid:
|
|
113
|
+
return None
|
|
114
|
+
return {
|
|
115
|
+
"kind": "username_delete",
|
|
116
|
+
"operation_name": "UsernameDeleteNotification",
|
|
117
|
+
"lid_jid": lid_jid,
|
|
118
|
+
"display_name": _try_as_string(payload.get("display_name")),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _normalize_username_update_hint(data: Any) -> dict[str, Any] | None:
|
|
123
|
+
outer = _try_as_record(data)
|
|
124
|
+
payload = (
|
|
125
|
+
_try_as_record(outer.get("xwa2_notify_username_on_update_side_sub"))
|
|
126
|
+
if outer
|
|
127
|
+
else None
|
|
128
|
+
)
|
|
129
|
+
if payload is None:
|
|
130
|
+
return None
|
|
131
|
+
contact_hash = _try_as_string(payload.get("hash"))
|
|
132
|
+
if not contact_hash:
|
|
133
|
+
return None
|
|
134
|
+
return {
|
|
135
|
+
"kind": "username_update_hint",
|
|
136
|
+
"operation_name": "UsernameUpdateNotification",
|
|
137
|
+
"contact_hash": contact_hash,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _normalize_own_username_sync(data: Any) -> dict[str, Any] | None:
|
|
142
|
+
outer = _try_as_record(data)
|
|
143
|
+
payload = _try_as_record(outer.get("xwa2_notify_wa_user")) if outer else None
|
|
144
|
+
if payload is None:
|
|
145
|
+
return None
|
|
146
|
+
own_lid_jid = _try_as_string(payload.get("lid_jid"))
|
|
147
|
+
if not own_lid_jid:
|
|
148
|
+
return None
|
|
149
|
+
info = _try_as_record(payload.get("username_info"))
|
|
150
|
+
return {
|
|
151
|
+
"kind": "own_username_sync",
|
|
152
|
+
"operation_name": "AccountSyncUsernameNotification",
|
|
153
|
+
"own_lid_jid": own_lid_jid,
|
|
154
|
+
"username": _try_as_string(info.get("username")) if info else None,
|
|
155
|
+
"state": _try_as_string(info.get("state")) if info else None,
|
|
156
|
+
"pin": _try_as_string(info.get("pin")) if info else None,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _normalize_text_status_update(data: Any) -> dict[str, Any] | None:
|
|
161
|
+
outer = _try_as_record(data)
|
|
162
|
+
payload = (
|
|
163
|
+
_try_as_record(outer.get("xwa2_notify_text_status_on_update"))
|
|
164
|
+
if outer
|
|
165
|
+
else None
|
|
166
|
+
)
|
|
167
|
+
if payload is None:
|
|
168
|
+
return None
|
|
169
|
+
jid = _try_as_string(payload.get("jid"))
|
|
170
|
+
if not jid:
|
|
171
|
+
return None
|
|
172
|
+
emoji_node = _try_as_record(payload.get("emoji"))
|
|
173
|
+
return {
|
|
174
|
+
"kind": "text_status_update",
|
|
175
|
+
"operation_name": "TextStatusUpdateNotification",
|
|
176
|
+
"jid": jid,
|
|
177
|
+
"text": _try_as_string(payload.get("text")),
|
|
178
|
+
"emoji": _try_as_string(emoji_node.get("content")) if emoji_node else None,
|
|
179
|
+
"ephemeral_duration_sec": _try_as_number(payload.get("ephemeral_duration_sec")),
|
|
180
|
+
"last_update_time": _try_as_number(payload.get("last_update_time")),
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _normalize_text_status_update_hint(data: Any) -> dict[str, Any] | None:
|
|
185
|
+
outer = _try_as_record(data)
|
|
186
|
+
payload = (
|
|
187
|
+
_try_as_record(outer.get("xwa2_notify_text_status_on_update_side_sub"))
|
|
188
|
+
if outer
|
|
189
|
+
else None
|
|
190
|
+
)
|
|
191
|
+
if payload is None:
|
|
192
|
+
return None
|
|
193
|
+
contact_hash = _try_as_string(payload.get("hash"))
|
|
194
|
+
if not contact_hash:
|
|
195
|
+
return None
|
|
196
|
+
return {
|
|
197
|
+
"kind": "text_status_update_hint",
|
|
198
|
+
"operation_name": "TextStatusUpdateNotificationSideSub",
|
|
199
|
+
"contact_hash": contact_hash,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _normalize_lid_change(data: Any) -> dict[str, Any] | None:
|
|
204
|
+
outer = _try_as_record(data)
|
|
205
|
+
payload = _try_as_record(outer.get("xwa2_notify_lid_change")) if outer else None
|
|
206
|
+
if payload is None:
|
|
207
|
+
return None
|
|
208
|
+
old_lid_jid = _try_as_string(payload.get("old"))
|
|
209
|
+
new_lid_jid = _try_as_string(payload.get("new"))
|
|
210
|
+
if not old_lid_jid or not new_lid_jid:
|
|
211
|
+
return None
|
|
212
|
+
return {
|
|
213
|
+
"kind": "lid_change",
|
|
214
|
+
"operation_name": "LidChangeNotification",
|
|
215
|
+
"old_lid_jid": old_lid_jid,
|
|
216
|
+
"new_lid_jid": new_lid_jid,
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _normalize_message_capping(data: Any) -> dict[str, Any] | None:
|
|
221
|
+
outer = _try_as_record(data)
|
|
222
|
+
payload = (
|
|
223
|
+
_try_as_record(outer.get("xwa2_notify_new_chat_messages_capping_info_update"))
|
|
224
|
+
if outer
|
|
225
|
+
else None
|
|
226
|
+
)
|
|
227
|
+
if payload is None:
|
|
228
|
+
return None
|
|
229
|
+
capping_status = _try_as_string(payload.get("capping_status"))
|
|
230
|
+
if not capping_status:
|
|
231
|
+
return None
|
|
232
|
+
return {
|
|
233
|
+
"kind": "message_capping",
|
|
234
|
+
"operation_name": "MessageCappingInfoNotification",
|
|
235
|
+
"capping_status": capping_status,
|
|
236
|
+
"ote_status": _try_as_string(payload.get("ote_status")),
|
|
237
|
+
"mv_status": _try_as_string(payload.get("mv_status")),
|
|
238
|
+
"total_quota": _try_as_number(payload.get("total_quota")),
|
|
239
|
+
"used_quota": _try_as_number(payload.get("used_quota")),
|
|
240
|
+
"cycle_start_timestamp": _try_as_number(payload.get("cycle_start_timestamp")),
|
|
241
|
+
"cycle_end_timestamp": _try_as_number(payload.get("cycle_end_timestamp")),
|
|
242
|
+
"server_sent_timestamp": _try_as_number(payload.get("server_sent_timestamp")),
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
_OP_NORMALIZERS: dict[str, Callable[[Any], dict[str, Any] | None]] = {
|
|
247
|
+
"UsernameSetNotification": _normalize_username_set,
|
|
248
|
+
"UsernameDeleteNotification": _normalize_username_delete,
|
|
249
|
+
"UsernameUpdateNotification": _normalize_username_update_hint,
|
|
250
|
+
"AccountSyncUsernameNotification": _normalize_own_username_sync,
|
|
251
|
+
"TextStatusUpdateNotification": _normalize_text_status_update,
|
|
252
|
+
"TextStatusUpdateNotificationSideSub": _normalize_text_status_update_hint,
|
|
253
|
+
"LidChangeNotification": _normalize_lid_change,
|
|
254
|
+
"MessageCappingInfoNotification": _normalize_message_capping,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _coerce_graphql_errors(raw: Any) -> list[WaMexNotificationGraphQlError]:
|
|
259
|
+
if not isinstance(raw, list):
|
|
260
|
+
return []
|
|
261
|
+
errors: list[WaMexNotificationGraphQlError] = []
|
|
262
|
+
for item in raw:
|
|
263
|
+
record = _try_as_record(item)
|
|
264
|
+
if record is None:
|
|
265
|
+
continue
|
|
266
|
+
message = record.get("message")
|
|
267
|
+
path = record.get("path")
|
|
268
|
+
extensions = _try_as_record(record.get("extensions"))
|
|
269
|
+
errors.append(
|
|
270
|
+
WaMexNotificationGraphQlError(
|
|
271
|
+
message=message if isinstance(message, str) else None,
|
|
272
|
+
path=[str(p) for p in path] if isinstance(path, list) else None,
|
|
273
|
+
extensions=dict(extensions) if extensions is not None else None,
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
return errors
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def parse_mex_notification(node: BinaryNode) -> WaMexNotificationParsed | None:
|
|
280
|
+
"""Parse a ``type="mex"`` notification's ``<update>`` GraphQL payload."""
|
|
281
|
+
if node.tag != WA_NODE_TAGS["NOTIFICATION"] or node.attrs.get("type") != "mex":
|
|
282
|
+
return None
|
|
283
|
+
update_node = find_node_child(node, "update")
|
|
284
|
+
if update_node is None:
|
|
285
|
+
return None
|
|
286
|
+
operation_name = update_node.attrs.get("op_name")
|
|
287
|
+
if not operation_name:
|
|
288
|
+
return None
|
|
289
|
+
content = update_node.content
|
|
290
|
+
if isinstance(content, (bytes, bytearray)):
|
|
291
|
+
try:
|
|
292
|
+
payload_text = bytes(content).decode("utf-8")
|
|
293
|
+
except UnicodeDecodeError:
|
|
294
|
+
return None
|
|
295
|
+
elif isinstance(content, str):
|
|
296
|
+
payload_text = content
|
|
297
|
+
else:
|
|
298
|
+
return None
|
|
299
|
+
try:
|
|
300
|
+
parsed_raw: Any = json.loads(payload_text)
|
|
301
|
+
except json.JSONDecodeError:
|
|
302
|
+
return None
|
|
303
|
+
parsed = _try_as_record(parsed_raw)
|
|
304
|
+
if parsed is None:
|
|
305
|
+
return None
|
|
306
|
+
errors = _coerce_graphql_errors(parsed.get("errors"))
|
|
307
|
+
data = parsed.get("data")
|
|
308
|
+
normalizer = _OP_NORMALIZERS.get(operation_name)
|
|
309
|
+
if normalizer is not None:
|
|
310
|
+
normalized = normalizer(data)
|
|
311
|
+
if normalized is not None:
|
|
312
|
+
fields: dict[str, Any] = dict(normalized)
|
|
313
|
+
fields["errors"] = errors
|
|
314
|
+
return WaMexNotificationParsed(**fields)
|
|
315
|
+
return WaMexNotificationParsed(
|
|
316
|
+
kind="unknown", operation_name=operation_name, data=data, errors=errors
|
|
317
|
+
)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Offline preview-manifest parser (``src/client/events/offline.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
from zapy._transport.node.helpers import find_node_child, get_node_children_by_tag
|
|
8
|
+
from zapy._transport.types import BinaryNode
|
|
9
|
+
from zapy._util.primitives import parse_optional_int
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class WaOfflineThreadPreview:
|
|
14
|
+
"""One thread with queued traffic: JID plus newest queued stanza timestamp."""
|
|
15
|
+
|
|
16
|
+
jid: str
|
|
17
|
+
timestamp_seconds: int
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class WaOfflineThreadReadWatermark:
|
|
22
|
+
"""How far up a thread the peer has already read."""
|
|
23
|
+
|
|
24
|
+
jid: str
|
|
25
|
+
read_timestamp_seconds: int
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class WaOfflinePendingStatusMessages:
|
|
30
|
+
"""Status-update backlog still queued behind the offline flush."""
|
|
31
|
+
|
|
32
|
+
count: int = 0
|
|
33
|
+
jids: list[str] = field(default_factory=list)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True, slots=True)
|
|
37
|
+
class WaOfflinePendingNotifications:
|
|
38
|
+
"""Notification backlog still queued behind the offline flush."""
|
|
39
|
+
|
|
40
|
+
count: int = 0
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True, slots=True)
|
|
44
|
+
class WaOfflineThreadMetadataEvent:
|
|
45
|
+
"""Which threads have queued traffic, announced before the offline flush.
|
|
46
|
+
|
|
47
|
+
Informational only - every listed thread still delivers its stanzas
|
|
48
|
+
normally. All fields but ``threads`` depend on server gating and are
|
|
49
|
+
commonly absent.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
threads: list[WaOfflineThreadPreview] = field(default_factory=list)
|
|
53
|
+
read_watermarks: list[WaOfflineThreadReadWatermark] | None = None
|
|
54
|
+
pending_status_messages: WaOfflinePendingStatusMessages | None = None
|
|
55
|
+
pending_notifications: WaOfflinePendingNotifications | None = None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _parse_thread_previews(node: BinaryNode) -> list[WaOfflineThreadPreview]:
|
|
59
|
+
previews: list[WaOfflineThreadPreview] = []
|
|
60
|
+
for item in get_node_children_by_tag(node, "item"):
|
|
61
|
+
jid = item.attrs.get("from")
|
|
62
|
+
timestamp_seconds = parse_optional_int(item.attrs.get("t"))
|
|
63
|
+
if not jid or timestamp_seconds is None or timestamp_seconds < 0:
|
|
64
|
+
continue
|
|
65
|
+
previews.append(
|
|
66
|
+
WaOfflineThreadPreview(jid=jid, timestamp_seconds=timestamp_seconds)
|
|
67
|
+
)
|
|
68
|
+
return previews
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _parse_read_watermarks(
|
|
72
|
+
node: BinaryNode,
|
|
73
|
+
) -> list[WaOfflineThreadReadWatermark] | None:
|
|
74
|
+
"""Keep the highest ``sts`` per JID; non-positive means "no watermark"."""
|
|
75
|
+
watermark_node = find_node_child(node, "watermark")
|
|
76
|
+
if watermark_node is None:
|
|
77
|
+
return None
|
|
78
|
+
highest_by_jid: dict[str, int] = {}
|
|
79
|
+
for item in get_node_children_by_tag(watermark_node, "item"):
|
|
80
|
+
jid = item.attrs.get("from")
|
|
81
|
+
read_timestamp_seconds = parse_optional_int(item.attrs.get("sts"))
|
|
82
|
+
if not jid or read_timestamp_seconds is None or read_timestamp_seconds <= 0:
|
|
83
|
+
continue
|
|
84
|
+
current = highest_by_jid.get(jid)
|
|
85
|
+
if current is None or read_timestamp_seconds > current:
|
|
86
|
+
highest_by_jid[jid] = read_timestamp_seconds
|
|
87
|
+
if not highest_by_jid:
|
|
88
|
+
return None
|
|
89
|
+
return [
|
|
90
|
+
WaOfflineThreadReadWatermark(jid=jid, read_timestamp_seconds=ts)
|
|
91
|
+
for jid, ts in highest_by_jid.items()
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def parse_offline_thread_metadata(node: BinaryNode) -> WaOfflineThreadMetadataEvent:
|
|
96
|
+
"""Parse the offline preview manifest out of a ``<thread_metadata>`` bulletin.
|
|
97
|
+
|
|
98
|
+
Takes the ``<thread_metadata>`` node, not the enclosing ``<ib>``. Every
|
|
99
|
+
child is optional: a bare node yields an empty ``threads`` list.
|
|
100
|
+
"""
|
|
101
|
+
status_node = find_node_child(node, "status_msgs")
|
|
102
|
+
pending_status: WaOfflinePendingStatusMessages | None = None
|
|
103
|
+
if status_node is not None:
|
|
104
|
+
pending_status = WaOfflinePendingStatusMessages(
|
|
105
|
+
count=parse_optional_int(status_node.attrs.get("count")) or 0,
|
|
106
|
+
jids=[
|
|
107
|
+
item.attrs["from"]
|
|
108
|
+
for item in get_node_children_by_tag(status_node, "item")
|
|
109
|
+
if item.attrs.get("from")
|
|
110
|
+
],
|
|
111
|
+
)
|
|
112
|
+
notifications_node = find_node_child(node, "notifications")
|
|
113
|
+
pending_notifications: WaOfflinePendingNotifications | None = None
|
|
114
|
+
if notifications_node is not None:
|
|
115
|
+
pending_notifications = WaOfflinePendingNotifications(
|
|
116
|
+
count=parse_optional_int(notifications_node.attrs.get("count")) or 0
|
|
117
|
+
)
|
|
118
|
+
return WaOfflineThreadMetadataEvent(
|
|
119
|
+
threads=_parse_thread_previews(node),
|
|
120
|
+
read_watermarks=_parse_read_watermarks(node),
|
|
121
|
+
pending_status_messages=pending_status,
|
|
122
|
+
pending_notifications=pending_notifications,
|
|
123
|
+
)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Picture-change notification parser (``src/client/events/picture.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from zapy._transport.node.helpers import find_node_child
|
|
9
|
+
from zapy._transport.types import BinaryNode
|
|
10
|
+
from zapy._util.primitives import parse_optional_int
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from zapy._client.events.incoming import WaIncomingUnhandledStanzaEvent
|
|
14
|
+
|
|
15
|
+
PICTURE_ACTION_TAGS = ("set", "delete", "request", "set_avatar")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True, slots=True)
|
|
19
|
+
class WaPictureEvent:
|
|
20
|
+
"""A ``picture`` notification: who changed whose picture, and the new picture id."""
|
|
21
|
+
|
|
22
|
+
raw_node: BinaryNode
|
|
23
|
+
stanza_id: str | None
|
|
24
|
+
chat_jid: str | None
|
|
25
|
+
stanza_type: str | None
|
|
26
|
+
offline: bool
|
|
27
|
+
action: str
|
|
28
|
+
target_jid: str | None = None
|
|
29
|
+
author_jid: str | None = None
|
|
30
|
+
timestamp_seconds: int | None = None
|
|
31
|
+
picture_id: int | None = None
|
|
32
|
+
contact_hash: str | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True, slots=True)
|
|
36
|
+
class WaParsePictureNotificationResult:
|
|
37
|
+
"""Outcome of ``parse_picture_notification_events``."""
|
|
38
|
+
|
|
39
|
+
events: list[WaPictureEvent]
|
|
40
|
+
unhandled: list[WaIncomingUnhandledStanzaEvent]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def parse_picture_notification_events(
|
|
44
|
+
node: BinaryNode,
|
|
45
|
+
) -> WaParsePictureNotificationResult:
|
|
46
|
+
"""Parse a ``picture`` notification into at most one typed event."""
|
|
47
|
+
for action in PICTURE_ACTION_TAGS:
|
|
48
|
+
action_node = find_node_child(node, action)
|
|
49
|
+
if action_node is None:
|
|
50
|
+
continue
|
|
51
|
+
event = WaPictureEvent(
|
|
52
|
+
raw_node=node,
|
|
53
|
+
stanza_id=node.attrs.get("id"),
|
|
54
|
+
chat_jid=node.attrs.get("from"),
|
|
55
|
+
stanza_type=node.attrs.get("type"),
|
|
56
|
+
offline="offline" in node.attrs,
|
|
57
|
+
action=action,
|
|
58
|
+
target_jid=action_node.attrs.get("jid"),
|
|
59
|
+
author_jid=action_node.attrs.get("author"),
|
|
60
|
+
timestamp_seconds=parse_optional_int(node.attrs.get("t")),
|
|
61
|
+
picture_id=parse_optional_int(action_node.attrs.get("id"))
|
|
62
|
+
if action == "set"
|
|
63
|
+
else None,
|
|
64
|
+
contact_hash=action_node.attrs.get("hash"),
|
|
65
|
+
)
|
|
66
|
+
return WaParsePictureNotificationResult(events=[event], unhandled=[])
|
|
67
|
+
return WaParsePictureNotificationResult(events=[], unhandled=[])
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Presence stanza parser (``src/client/events/presence.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from zapy._protocol import defaults as _defaults
|
|
8
|
+
from zapy._transport.types import BinaryNode
|
|
9
|
+
from zapy._util.primitives import parse_optional_int
|
|
10
|
+
|
|
11
|
+
# Mirrors ``WA_PRESENCE_TYPES`` / ``WA_PRESENCE_LAST_SENTINELS`` in
|
|
12
|
+
# ``src/protocol/presence.ts``.
|
|
13
|
+
_PRESENCE_AVAILABLE = "available"
|
|
14
|
+
_PRESENCE_UNAVAILABLE = "unavailable"
|
|
15
|
+
_LAST_DENY = "deny"
|
|
16
|
+
_LAST_NONE = "none"
|
|
17
|
+
_LAST_ERROR = "error"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class PresenceLastSeen:
|
|
22
|
+
"""Peer last-seen disclosure: a timestamp, a privacy sentinel, or unknown."""
|
|
23
|
+
|
|
24
|
+
kind: str
|
|
25
|
+
unix_seconds: int | None = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class ParsedPresence:
|
|
30
|
+
"""A ``<presence>`` stanza, split into user and group variants."""
|
|
31
|
+
|
|
32
|
+
type: str
|
|
33
|
+
last_seen: PresenceLastSeen | None = None
|
|
34
|
+
group_online_count: int | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _is_group_jid(jid: str) -> bool:
|
|
38
|
+
server = jid.rsplit("@", 1)[-1] if "@" in jid else ""
|
|
39
|
+
return server == _defaults.GROUP_SERVER
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _parse_last_seen(value: str) -> PresenceLastSeen:
|
|
43
|
+
if value == _LAST_DENY:
|
|
44
|
+
return PresenceLastSeen(kind="privacy_denied")
|
|
45
|
+
if value == _LAST_NONE:
|
|
46
|
+
return PresenceLastSeen(kind="never_online")
|
|
47
|
+
if value == _LAST_ERROR:
|
|
48
|
+
return PresenceLastSeen(kind="unknown")
|
|
49
|
+
unix_seconds = parse_optional_int(value)
|
|
50
|
+
if unix_seconds is None:
|
|
51
|
+
return PresenceLastSeen(kind="unknown")
|
|
52
|
+
return PresenceLastSeen(kind="timestamp", unix_seconds=unix_seconds)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def parse_presence_node(node: BinaryNode) -> ParsedPresence:
|
|
56
|
+
"""Parse a ``<presence>`` stanza into its user or group variant."""
|
|
57
|
+
from_jid = node.attrs.get("from")
|
|
58
|
+
is_group = from_jid is not None and _is_group_jid(from_jid)
|
|
59
|
+
type_: str = (
|
|
60
|
+
_PRESENCE_UNAVAILABLE
|
|
61
|
+
if node.attrs.get("type") == _PRESENCE_UNAVAILABLE
|
|
62
|
+
else _PRESENCE_AVAILABLE
|
|
63
|
+
)
|
|
64
|
+
if is_group:
|
|
65
|
+
count = parse_optional_int(node.attrs.get("count"))
|
|
66
|
+
if count is not None:
|
|
67
|
+
return ParsedPresence(type=type_, group_online_count=count)
|
|
68
|
+
if type_ == _PRESENCE_UNAVAILABLE:
|
|
69
|
+
return ParsedPresence(type=type_, group_online_count=0)
|
|
70
|
+
return ParsedPresence(type=type_)
|
|
71
|
+
last = node.attrs.get("last")
|
|
72
|
+
if type_ == _PRESENCE_UNAVAILABLE and last is not None:
|
|
73
|
+
return ParsedPresence(type=type_, last_seen=_parse_last_seen(last))
|
|
74
|
+
return ParsedPresence(type=type_)
|