Introducing a new way to review your PRs.

Read the announcement

crmne / zapfast

ZapFast: a fast, native WhatsApp client in Rust and egui

View on GitHub

19 documents · Updated Nov 18, 2026

docs / interactive-messages-and-polls

Interactive messages and polls

Interactive messages let a person act on a received business card without leaving the conversation. Polls add a shared question with vote controls and result details. The worker turns protocol events into safe message state, keeps the durable vote record, and reports changes to the interface.

Interactive message actions

Interactive actions connect a displayed choice to one local result or to a validated reply sent through WhatsApp. The message view exposes only safe labels and supported actions. Protocol ids and flow data remain in the worker so a click cannot change the action it sends (src/model.rs• L1022-1061, src/…/interactive.rs• L1-16).

Supported action types are:

  • Reply: send a quick reply that quotes the original message.
  • Select: open a choice dialog for a list response.
  • Link: open a validated HTTP or HTTPS URL in the system browser.
  • Copy: copy a supplied code without sending a message.
  • Unavailable: direct the person to WhatsApp Web or the phone when ZapFast cannot safely perform the action.

The interface maps each action to the same behavior for clicks and message-menu commands. A list uses a grouped, scrollable dialog. The dialog closes only after the worker receives a displayed choice (src/…/conversation.rs• L9424-9451, src/…/dialogs.rs• L162-273).

Interactive reply flow

The worker resolves the selected display index against the archived original message before it creates a reply. It then adds a quote and sends the protocol-native response through the normal outgoing message path. This preserves the original choice id and keeps the new reply in the conversation (src/…/replies.rs• L182-223, src/…/replies.rs• L225-303).

The flow has these stages:

  1. The interface emits a reply action with the source message and displayed button or option index.
  2. The worker loads the source message and its original protocol data.
  3. The worker checks that the source is an incoming, unchanged interactive message and that the index is valid.
  4. The worker creates a quoted native reply and stores it as pending.
  5. The send result clears the pending state. A failed send permits another attempt.
sequenceDiagram
    participant UI as Message view
    participant W as Worker
    participant A as Local archive
    participant WA as WhatsApp
    UI->>W: ReplyInteractive(source, choice)
    W->>A: Load message and original data
    A-->>W: Source and protocol choice
    W->>W: Validate and build quoted reply
    W->>WA: Send native response
    WA-->>W: Send result
    W-->>UI: Pending or complete state

Only one reply can be in flight for a source message. Unsupported actions, outgoing or edited sources, revoked messages, invalid choices, disconnected accounts, and read-only chats do not produce a response (src/…/replies.rs• L200-223, src/…/replies.rs• L234-252).

Poll composition and presentation

Polls provide a question with two to twelve distinct answers. A poll can allow one answer or several answers. The composer validates the question and answer limits before it enables sending (src/model.rs• L1090-1139, src/…/polls.rs• L9-177).

The poll ballot shows the current selection, vote count, and result tracks for each answer. The interface enables voting only when the account has the poll key, the chat can send, and no vote is pending. The Show votes action opens participant names and vote times when those details are known (src/…/polls.rs• L181-373, src/…/polls.rs• L376-449).

Poll result details are derived from each participant's newest decrypted vote. A withdrawal removes that participant from the visible voter list. The poll content sent to the interface contains counts and the current selection, while the detailed voter list is rebuilt from the archive (src/model.rs• L1063-1088, src/…/polls.rs• L242-334).

Poll vote lifecycle

Voting uses the saved poll definition and key to create an encrypted protocol vote. The worker records the local vote after the send succeeds, then emits a message update so the ballot reflects the new selection (src/…/polls.rs• L488-600).

Incoming vote events may arrive before the poll or before their contents can be decrypted. The worker archives the encrypted event, decrypts a bounded number at a time when the poll definition is available, and updates the message after a valid choice is recovered (src/…/polls.rs• L602-717, src/…/polls.rs• L123-160).

flowchart LR
    V[Vote event] --> R[Durable vote record]
    R --> D{Poll key and definition available?}
    D -- No --> Q[Keep encrypted and retry later]
    D -- Yes --> X[Decrypt and match option hashes]
    X --> S[Keep newest vote per participant]
    S --> U[Refresh ballot and result details]

The archive uses one current vote record per poll and participant. Newer votes replace older votes, so replayed history cannot undo a later selection or withdrawal. A deleted poll removes its definition, history marker, and votes (src/…/polls.rs• L6-29, src/…/polls.rs• L96-110).

Poll history recovery

The phone remains the source for older poll votes that are not in the local archive. When a poll needs recovery, the worker requests history anchored after the poll so the response includes the poll creation and its vote snapshot. Requests are serialized with other older-history work and retry with increasing delays after failure (src/…/polls.rs• L84-153, src/…/poll_history.rs• L17-107).

The ballot reports whether result history is complete, loading, or waiting after a failed request. An empty or unusable phone snapshot does not mark recovery complete. A poll that is created locally already has complete history, while a live poll with no known votes is treated as a valid zero-vote state (src/…/polls.rs• L156-221, src/…/polls.rs• L242-334).

Event ordering

Worker events can name a message before that message reaches the archive. The early-event buffer holds reads and reactions until the target is filed. It merges repeated state, keeps the newest reaction from each sender, supports identity remapping, and drops entries after a bounded age or count (src/…/early_events.rs• L1-16, src/…/early_events.rs• L59-187).

Poll votes follow a separate durable path because encrypted votes may need the poll definition and key before they can affect the ballot. Both paths preserve the rule that a late event must not overwrite newer local state or resurrect deleted content (src/…/early_events.rs• L88-138, src/…/polls.rs• L144-167).

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep displayed interactive indices aligned with the worker's re-resolution of archived protocol choices.
  • Preserve the quote context and native response type when adding an interactive action.
  • Keep poll counts and participant details derived from the same latest-vote archive records.
  • Keep poll-history completion separate from the presence of the poll question or an empty phone snapshot.
  • Keep encrypted vote events retryable until the matching poll definition and key are available.
  • Keep pending interactive replies and poll votes scoped to their source message so unrelated send results cannot clear them.

Important failure modes

TriggerConsequenceGuard
The displayed option order differs from the archived sourceThe worker could send the wrong business choiceRe-resolve the index against the archived protocol message
A reply source is outgoing, edited, or revokedThe action must not create a responseReject the source before building the quote
A poll vote arrives before its poll keyThe ballot cannot decrypt the vote yetStore the encrypted vote and retry after the key is present
Phone history returns no usable poll votesResults look complete when they are notKeep recovery pending and show an incomplete-history state
A late or repeated vote is older than the saved voteA replay could undo the latest resultCompare vote time and update id before replacing the record

Key files

FileWhy to read it
src/…/replies.rsFollow validation, choice re-resolution, quoting, pending state, and native reply sending.
src/…/interactive.rsSee how received cards and actions become safe interface state.
src/…/conversation.rsSee how card actions become links, replies, copy actions, or list dialogs.
src/…/dialogs.rsSee the grouped list selection flow.
src/…/polls.rsFollow poll creation, voting, decryption, history recovery, and result derivation.
src/…/polls.rsSee the durable poll definition and latest-vote contract.
src/…/poll_history.rsSee serialized poll-history requests and retry behavior.
src/…/polls.rsSee poll composition, ballot state, and result presentation.
src/…/early_events.rsSee how message events that arrive early wait for their target.