Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cargo test -p e2e-tests # requires mock server running
- **Protocol**: Cross-reference **whatsmeow**, **Baileys**, and captured WhatsApp Web JS (`docs/captured-js/`) to verify implementations.
- **IQ Requests**: Use `client.execute(Spec::new(&jid)).await?` pattern. IqSpec constructors take `&Jid` not `Jid`.
- **New features**: Expose via `src/features/mod.rs`, re-export in `src/lib.rs`.
- **Event payloads**: Model a maybe-absent field as `Option<T>`, never an empty-string/zero sentinel. Pre-1.0 the payload structs stay constructible (not `#[non_exhaustive]`), so consumers read the fields they need instead of destructuring exhaustively; see the `Event` doc in `wacore/src/types/events.rs` for the full stability policy.
- **Wire-tagged enums**: Every protocol enum uses `#[derive(WireEnum)]`. The `#[wire = "..."]` (or `#[wire = NUM]` for int mode) attribute is the SINGLE source of truth for each variant's wire value. Do NOT also derive `serde::Serialize`/`Deserialize` or add `#[serde(rename_all)]` — the derive owns both. Three modes: unit-string (default), tagged-with-payload (`#[wire(tag = "type")]` on the enum, optional `#[wire_alias = "..."]` and `#[wire(skip)]` on fields, `#[wire_fallback]` for catch-all), and int (`#[wire(kind = "int")]`). In tagged mode the derive auto-generates a sibling `<Name>Tag` enum; parsers must dispatch via `<Name>Tag::try_from(node.tag.as_ref())` instead of matching string literals, so renaming a wire tag stays a single-attribute change.

## Detailed Docs
Expand Down
5 changes: 1 addition & 4 deletions src/client/node_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,7 @@ impl Client {
{
let ack = wacore::types::events::ServerAck {
id: id.as_str().to_string(),
class: node
.get_attr("class")
.map(|v| v.as_str().to_string())
.unwrap_or_default(),
class: node.get_attr("class").map(|v| v.as_str().to_string()),
from: node.get_attr("from").and_then(|v| v.as_str().parse().ok()),
timestamp: node
.get_attr("t")
Expand Down
6 changes: 3 additions & 3 deletions src/client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ async fn test_ack_dispatches_server_ack_event() {
e.as_ref(),
Event::ServerAck(ack)
if ack.id == "ack-evt-1"
&& ack.class == "message"
&& ack.class.as_deref() == Some("message")
&& ack.from.as_ref().is_some_and(|j| j.to_string() == "123456789@s.whatsapp.net")
&& ack.timestamp.is_some_and(|t| t.timestamp() == 1_720_000_000)
&& ack.error.is_none()
)),
"server <ack> should dispatch Event::ServerAck with class/from/t"
);

// Nack: the error code rides along; absent class/t stay empty/None.
// Nack: the error code rides along; absent class/t stay None.
let nack_node = NodeBuilder::new("ack")
.attr("id", "ack-evt-2")
.attr("error", "479")
Expand All @@ -255,7 +255,7 @@ async fn test_ack_dispatches_server_ack_event() {
e.as_ref(),
Event::ServerAck(ack)
if ack.id == "ack-evt-2"
&& ack.class.is_empty()
&& ack.class.is_none()
&& ack.timestamp.is_none()
&& ack.error.as_deref() == Some("479")
)),
Expand Down
15 changes: 13 additions & 2 deletions wacore/src/types/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,17 @@ pub struct DisappearingModeChanged {
pub setting_timestamp: DateTime<Utc>,
}

/// An event dispatched by the client to registered handlers.
///
/// # Stability (pre-1.0)
///
/// The enum is `#[non_exhaustive]`, so match arms must keep a `_` catch-all.
/// The payload structs are *not* sealed: while the crate is `0.x`, an existing
/// payload may gain new fields in a minor release, so read the fields you need
/// (`ack.class`) or keep a `..` rest when destructuring, rather than binding
/// every field. A maybe-absent field is always modeled as `Option<T>`, never
/// an empty-string / zero sentinel. Sealing the payloads behind
/// `#[non_exhaustive]` + constructors is deferred to the 1.0 API freeze.
#[derive(Debug, Clone, Serialize)]
#[non_exhaustive]
pub enum Event {
Expand Down Expand Up @@ -1195,8 +1206,8 @@ pub struct ServerAck {
/// Id of the acked stanza (for a sent message, its message id).
pub id: String,
/// Stanza class the ack refers to (`"message"`, `"receipt"`,
/// `"notification"`, `"call"`, …). Empty when the server omits it.
pub class: String,
/// `"notification"`, `"call"`, …). `None` when the server omits it.
pub class: Option<String>,
/// Chat/entity the ack refers to, when present and parseable.
pub from: Option<Jid>,
/// Server timestamp from the ack's `t` attribute, when present. For a
Expand Down
Loading