//! The wire shapes of Cotton Chat's five methods. Published early so the //! phone lanes build against them (a `shapes.md` kept beside the work //! says the same in prose). Add-only: a field once shipped keeps its name //! and meaning; a new one is optional. //! //! ```text //! chat.list {filter?, search?, after?} → ListAnswer //! chat.thread {thread, before?, after?, around?} → ThreadAnswer //! chat.compose {thread, text?, replyTo?, edit?, cancel?} → ComposeAnswer //! chat.act {act, thread, message?, messages?, text?, emoji?, to?, until?} → ActAnswer //! chat.themes {} → ThemesAnswer //! chat.theme.set {appearance: "light"|"dark", id} → ThemesAnswer //! chat.theme {theme, dark} / chat.text {value} / chat.ground {ground} → ThemesAnswer //! ``` use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; pub use crate::messages::ticks::MessageTick as Tick; /// Rows a list page holds. The stride is the read's, never the phone's. pub const LIST_PAGE: usize = 80; /// Messages a thread page holds. pub const THREAD_PAGE: usize = 60; /// Counts stop here: a badge past it says [`badge`]'s "999+". pub const COUNT_CEILING: u32 = 1000; /// A count as a badge says it. pub fn badge(count: u32) -> String { if count >= COUNT_CEILING { format!("{}+", COUNT_CEILING - 1) } else { count.to_string() } } /// Bubbles from one sender group while each follows the last within this. pub const GROUP_GAP_MS: i64 = 5 * 60_000; /// Tints a typed-initials picture is drawn on (`chat.tint.` in a theme). pub const TINTS: u32 = 8; // ── chat.list ─────────────────────────────────────────────────────────── /// Which conversations the list shows: a fan tile's id. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] #[serde(rename_all = "lowercase")] pub enum Filter { #[default] All, People, Groups, Unread, Archived, /// The last word was theirs and is unanswered. Waiting, /// One source: `cotton`, `whatsapp`, `sms`, … #[serde(untagged)] Source(String), } impl Filter { pub fn parse(text: Option<&str>) -> Filter { match text.unwrap_or("all") { "all" | "" => Filter::All, "people" => Filter::People, "groups" => Filter::Groups, "unread" => Filter::Unread, "archived" => Filter::Archived, "waiting" => Filter::Waiting, other => Filter::Source(other.to_string()), } } pub fn id(&self) -> &str { match self { Filter::All => "all", Filter::People => "people", Filter::Groups => "groups", Filter::Unread => "unread", Filter::Archived => "archived", Filter::Waiting => "waiting", Filter::Source(s) => s, } } } /// A round picture: the photo's media key when there is one, else typed /// initials on a tint (`tint` is 0..TINTS, a theme's `chat.tint.`). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Picture { #[serde(default, skip_serializing_if = "Option::is_none")] pub photo: Option, pub initials: String, pub tint: u32, } /// The small mark before a last line or inside a bubble. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Mark { Photo, Album, Video, Voice, Audio, File, Contact, Location, Poll, Deleted, } /// A conversation's last line. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct LastLine { pub text: String, /// The sender's first name, in a group ("You" for your own). #[serde(default, skip_serializing_if = "Option::is_none")] pub sender: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub mark: Option, pub mine: bool, /// Your own last line's tick. #[serde(default, skip_serializing_if = "Option::is_none")] pub tick: Option, /// Where your own last line stands while it is on its way to WhatsApp through the Mac, in the bubble's own words /// ("Waiting to send", "Sending…", "Not sent: "); absent once it has gone, and on every other line. #[serde(default, skip_serializing_if = "Option::is_none")] pub state: Option, } /// One swipe action on a row: the act `chat.act` takes, and its word. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Swipe { pub act: String, pub label: String, /// The question asked before the act runs (Delete); none for an act that runs at once. #[serde(default, skip_serializing_if = "Option::is_none")] pub confirm: Option, } /// One conversation in the list. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ListRow { pub thread: String, pub name: String, pub group: bool, /// Where it is from (`cotton`, `whatsapp`, `sms`, …). pub source: String, pub picture: Picture, #[serde(default, skip_serializing_if = "Option::is_none")] pub last_line: Option, /// The time today, "Yesterday", else the day. #[serde(default, skip_serializing_if = "Option::is_none")] pub when: Option, /// Unread messages; 0 draws no badge. Counted to a ceiling (1000). pub unread: u32, /// What the badge says: the count, "999+" past the ceiling; none at 0. #[serde(default, skip_serializing_if = "Option::is_none")] pub badge: Option, /// Marked unread by hand: a badge with no number. pub marked_unread: bool, pub pinned: bool, pub muted: bool, pub archived: bool, /// The typing line where the source gives it. #[serde(default, skip_serializing_if = "Option::is_none")] pub typing: Option, /// A draft waiting in the composer, said as the last line is. #[serde(default, skip_serializing_if = "Option::is_none")] pub draft: Option, /// A message can be written into it from here (Forward's picker keeps these). #[serde(default)] pub sendable: bool, /// Swipe from the leading edge (read / unread, pin), then the trailing (mute, archive). pub leading: Vec, pub trailing: Vec, /// A long press: Mark as read or Mark as unread, Pin, Mute, Archive, Delete (`list::hold`). #[serde(default)] pub hold: Vec, } /// A fan tile, in the fan's order. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct FanTile { /// A filter id, or `account`. pub id: String, pub label: String, /// Conversations under it (unread ones for Unread); none on Account. #[serde(default, skip_serializing_if = "Option::is_none")] pub count: Option, pub on: bool, } #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ListCounts { pub all: u32, pub people: u32, pub groups: u32, /// Conversations with anything unread (not archived). pub unread: u32, pub archived: u32, /// Conversations whose last word was theirs (not archived). #[serde(default)] pub waiting: u32, pub sources: BTreeMap, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ListWords { pub title: String, pub search: String, /// What stands where no row does (the filter's own line, or none found). pub empty: String, } /// `chat.list`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ListAnswer { pub filter: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub search: Option, /// Pinned first, then newest. pub rows: Vec, /// Hand back as `after` for the next page; none at the end. #[serde(default, skip_serializing_if = "Option::is_none")] pub next: Option, pub counts: ListCounts, pub fan: Vec, /// The filters above the list, in order: All, Unread, Groups. #[serde(default)] pub filters: Vec, pub words: ListWords, } // ── chat.thread ───────────────────────────────────────────────────────── /// What a bubble is. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum BubbleKind { Text, Photo, Album, Video, Voice, Audio, File, Contact, Location, Poll, Deleted, } /// One attachment as a bubble draws it. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MediaPart { /// Opened through `chat.picture {message, index}` / the media store. pub index: u32, pub kind: Mark, #[serde(default, skip_serializing_if = "Option::is_none")] pub name: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub width: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub height: Option, /// "0:12" for voice, audio and video. #[serde(default, skip_serializing_if = "Option::is_none")] pub length: Option, /// "2.4 MB" for a file. #[serde(default, skip_serializing_if = "Option::is_none")] pub size: Option, /// Voice, audio and video: the length as a number, which a player's /// countdown and position need (`length` is its words). #[serde(default, skip_serializing_if = "Option::is_none")] pub duration_ms: Option, /// Voice: samples in 0..1, as the recorder sent them (up to 64). Kept /// for phones that know nothing of `bars`. #[serde(default, skip_serializing_if = "Option::is_none")] pub waveform: Option>, /// Voice: exactly [`super::bubble::BARS`] heights in 0..1, worked out /// from `waveform` by [`super::bubble::bars`], so both phones draw the /// same bars from the same note. Absent when there is no waveform (the /// player draws its thin track). #[serde(default, skip_serializing_if = "Option::is_none")] pub bars: Option>, /// Voice: false on a voice message of theirs nobody has played on any /// of the person's phones (`chat.act played`). Absent is played: the /// person's own, and an imported note. #[serde(default = "played_default", skip_serializing_if = "is_played")] pub played: bool, /// A tiny base64 JPEG drawn blurred until the bytes are local. #[serde(default, skip_serializing_if = "Option::is_none")] pub preview: Option, /// A shared contact's name and first number. #[serde(default, skip_serializing_if = "Option::is_none")] pub contact: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub number: Option, /// The store said it does not hold the file (it answered 404 when last /// asked, `cotton_client::media::absent`), and it is not asked again /// until its wait is over: drawn as not available, never an empty box. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub gone: bool, /// A voice message's words, transcribed on the sender's phone and sealed /// like the message, following it: drawn under the player, so nobody has /// to listen. #[serde(default, skip_serializing_if = "Option::is_none")] pub transcript: Option, /// The message this part opens through (`chat.picture {message, index}`), when it is not the bubble's: a grid of /// one tap's pictures to WhatsApp, each its own message (FEEDBACK-4 B3, CONTRACT "Several pictures to WhatsApp, /// one grid"). Absent, the bubble's. #[serde(default, skip_serializing_if = "Option::is_none")] pub message: Option, } fn played_default() -> bool { true } fn is_played(played: &bool) -> bool { *played } /// The link a phone fetches a card for, from the words being written. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PreviewAsk { pub url: String, } /// `chat.preview`'s answer: the page the phone fetched, read as its card; `image` the picture the phone fetches and /// makes the card's `thumb`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PreviewCard { pub url: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub site: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub title: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub image: Option, } /// A link unfolded into a card. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct LinkCard { pub url: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub site: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub title: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub thumb: Option, } /// The quoted line of a reply; a tap goes to `message` (`chat.thread {around}`). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Quote { #[serde(default, skip_serializing_if = "Option::is_none")] pub message: Option, pub sender: String, pub line: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub mark: Option, } /// Reactions under a bubble, one per emoji, in first-seen order. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Reaction { pub emoji: String, pub count: u32, pub mine: bool, } /// Who wrote a bubble in a group, said on the group's first bubble (name) /// and its last (picture). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Sender { pub name: String, pub picture: Picture, /// 0..TINTS: the name's ink in a group (`chat.name.`). pub tint: u32, } /// The agent a bubble is from: its name and whose it is ("Asha's agent", "Your agent"). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct AgentTag { pub id: String, pub name: String, pub line: String, } /// One bubble. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Bubble { pub message: String, pub mine: bool, pub kind: BubbleKind, #[serde(default, skip_serializing_if = "Option::is_none")] pub text: Option, /// In a group, on a bubble from someone else. #[serde(default, skip_serializing_if = "Option::is_none")] pub sender: Option, /// Said by an agent (an agent in a chat, 23 Nov 2026): drawn on the left with the agent's mark, its name and /// whose agent it is, even on its person's own phones (`mine` is then false). #[serde(default, skip_serializing_if = "Option::is_none")] pub agent: Option, /// First of a run from one sender: the gap above it. pub head: bool, /// Last of the run: the tail. pub tail: bool, /// First of one sender's unbroken words in a day: their picture, and in a /// group their name, stand here once (a pause starts a run, not a face). #[serde(default)] pub face: bool, /// The clock. pub time: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub tick: Option, /// The person's own message still going (`tick` sending): until this /// moment, ms since the epoch, nothing is drawn under it, so a send that /// goes at once never flashes "Sending" ([`crate::messages::app::bubble::QUIET_SENDING_MS`] /// after it was written); from then "Sending" stands until the tick moves. #[serde(default, skip_serializing_if = "Option::is_none")] pub quiet_until: Option, /// Where the person's own text stands, in words, drawn under the bubble when present: a WhatsApp text on its /// way through the Mac ("Waiting to send", "Sending…", "Not sent: "). Never "Sent" before it was. #[serde(default, skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub edited: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub forwarded: Option, pub pinned: bool, #[serde(default, skip_serializing_if = "Option::is_none")] pub reply: Option, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub reactions: Vec, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub media: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub link: Option, /// What a long press offers, in order: `chat.act`'s acts plus `copy` and `select`. pub actions: Vec, /// Where a search asked for (`chat.thread { find }`) stands in `text`, in /// UTF-16 `[start, end)`: drawn marked. Empty when nothing was asked. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub marks: Vec<[u32; 2]>, /// Starred by this person (`chat.act star`): private, kept in their own database. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub starred: bool, /// Where this message went or came by, in a chat holding both Cotton's and WhatsApp's messages on a linked copy /// (FEEDBACK-2 A): "on Cotton" or "via WhatsApp", drawn small by the time. Absent anywhere else. #[serde(default, skip_serializing_if = "Option::is_none")] pub place: Option, /// The phone numbers in its words (`numbers::numbers_in`): a tap on one opens that number's chat, as /// `chat.start { number }` routes it (FEEDBACK-2 A). Empty when it holds none. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub numbers: Vec, /// The links in its words (`links::links_at`: only an explicit `http(s)://`), where each stands and where it goes: /// a tap opens the page inside Comms (a Custom Tab on Android, Safari's sheet on iPhone), never out to the browser. /// Empty when it holds none. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub links: Vec, /// A poll, drawn as one (`poll::card`; CONTRACT "Polls shown"): its words stand here, never as `text`. #[serde(default, skip_serializing_if = "Option::is_none")] pub poll: Option, } /// A poll as the bubble draws it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PollCard { pub question: String, /// "Select one" or "Select one or more"; absent on an exported poll. #[serde(default, skip_serializing_if = "Option::is_none")] pub choose: Option, pub options: Vec, /// Everyone who voted, once each ("5 votes", "No votes yet"); an export's, the sum. pub said: String, /// The whole poll as one line, for TalkBack and VoiceOver. pub spoken: String, /// The Votes sheet's title. pub votes_title: String, /// He can vote here (a WhatsApp poll his Mac's link sends to): a tap on an option is `chat.act vote`. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub votable: bool, } /// One option of a poll. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PollChoice { pub text: String, pub votes: u32, /// "3 votes", "1 vote", "No votes". pub said: String, /// Its part of the people who voted, 0 to 100: the bar's length. pub percent: u32, /// Who chose it, as the chat names them: "You" first, then in the order they voted. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub voters: Vec, /// The owner's own choice. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub mine: bool, } /// A phone number in a message's words: where it stands (UTF-16 `[start, end)`, as `marks`) and as E.164. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct NumberAt { pub at: [u32; 2], pub number: String, } /// A link in a message's words: UTF-16 `[start, end)` and the address it opens. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct LinkAt { pub at: [u32; 2], pub url: String, } /// One item of a thread page, oldest first. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(tag = "item", rename_all = "lowercase")] pub enum Item { Day { label: String, /// The day drawn as a large numeral ("20") … #[serde(default, skip_serializing_if = "Option::is_none")] numeral: Option, /// … and the words beside it ("Friday · November"). #[serde(default, skip_serializing_if = "Option::is_none")] words: Option, }, Unread { label: String }, /// A group event or an importer's aside, centred. Event { message: String, text: String, /// What a tap on the line opens, where it opens something: `safety`, the /// safety number's screen (CONTRACT.md "Safety number"). #[serde(default, skip_serializing_if = "Option::is_none")] opens: Option, }, /// A mail between the person and whoever this chat is with, by time among /// the messages (MAIL.md): marked as mail, opening whole (`chat.mail.thread`). Mail(MailCard), Bubble(Bubble), } /// One mail in a conversation, drawn as a quiet card marked as mail. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MailCard { /// The email's id. pub email: String, /// Its conversation of mail: what `chat.mail.thread` opens. pub mail_thread: String, /// The person sent it (drawn on the right, as their own words). pub mine: bool, /// "Mail", beside the envelope mark. pub mark: String, pub subject: String, /// Its first words on one line. #[serde(default, skip_serializing_if = "Option::is_none")] pub line: Option, /// "2 attachments". #[serde(default, skip_serializing_if = "Option::is_none")] pub attachments: Option, pub unread: bool, /// Its clock ("09:41"). pub time: String, /// When it was sent, RFC 3339. pub at: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Header { pub name: String, pub picture: Picture, pub group: bool, pub source: String, /// Members in a group; typing or last seen where the source gives it. #[serde(default, skip_serializing_if = "Option::is_none")] pub status: Option, /// Where a message written here goes, on a copy linked to WhatsApp through the Mac (FEEDBACK-2 A): drawn /// under the name. Absent unlinked, and where nothing can be written. #[serde(default, skip_serializing_if = "Option::is_none")] pub place: Option, /// Acts on his WhatsApp itself for a person's WhatsApp chat (owner, 24 Nov 2026; chat CONTRACT "Blocking a /// WhatsApp sender, deleting a WhatsApp chat"): Block on WhatsApp, and Delete on WhatsApp too. Each is a /// `chat.act`; the delete answers `count_first` with the count before it runs. Absent elsewhere. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub acts: Vec, } /// Where a message goes, said before it is sent: `cotton` ("on Cotton") or `whatsapp` ("via WhatsApp"). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PlaceMark { pub id: String, pub mark: String, } /// The pinned-message bar: the newest pin, and how many there are. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PinnedBar { pub message: String, pub title: String, pub line: String, pub count: u32, } /// A stranger's first message waits on an answer: their words stand, and /// Accept, Block and Delete go to `chat.accept` / `chat.block` / `chat.refuse`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RequestCard { pub title: String, pub line: String, pub accept: String, pub block: String, pub refuse: String, } /// Jump to latest, with the count of what came in below. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Jump { pub count: u32, pub label: String, /// The count as the button says it ("999+" past the ceiling). pub badge: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ActionWords { pub reply: String, pub react: String, pub copy: String, pub forward: String, pub edit: String, pub delete: String, /// Delete for me, in a WhatsApp chat that sends: his copy only (chat CONTRACT.md "Delete for me"). #[serde(default)] pub delete_mine: String, pub pin: String, pub unpin: String, pub select: String, /// Message info: who in a group has the person's words (`chat.group.receipts`). #[serde(default)] pub info: String, /// Star and Unstar (`chat.act star` / `unstar`). #[serde(default)] pub star: String, #[serde(default)] pub unstar: String, pub copied: String, /// The few emoji a react row offers first. pub emoji: Vec, } /// `chat.thread`: a page of items oldest first. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ThreadAnswer { pub thread: String, pub header: Header, #[serde(default, skip_serializing_if = "Option::is_none")] pub pinned: Option, pub items: Vec, /// Hand back as `before` for the page above; none at the top. #[serde(default, skip_serializing_if = "Option::is_none")] pub older: Option, /// Hand back as `after` for the page below; none at the newest. #[serde(default, skip_serializing_if = "Option::is_none")] pub newer: Option, /// The message `around` asked for, to scroll to and flash. #[serde(default, skip_serializing_if = "Option::is_none")] pub focus: Option, pub unread: u32, #[serde(default, skip_serializing_if = "Option::is_none")] pub jump: Option, /// The composer, only where Cotton can really send. #[serde(default, skip_serializing_if = "Option::is_none")] pub composer: Option, /// Why there is no composer ("Read only: imported from WhatsApp"). #[serde(default, skip_serializing_if = "Option::is_none")] pub read_only: Option, /// A stranger's request, until it is answered. #[serde(default, skip_serializing_if = "Option::is_none")] pub request: Option, pub actions: ActionWords, /// The chat's disappearing timer, in a Cotton chat (chat-search): where it stands and its choices. #[serde(default, skip_serializing_if = "Option::is_none")] pub timer: Option, /// While this phone's first pull runs and nothing of this chat has come /// yet: "Loading this chat…", said in place of an empty page. #[serde(default, skip_serializing_if = "Option::is_none")] pub loading: Option, } // ── chat.compose ──────────────────────────────────────────────────────── /// The composer's one button. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Button { /// Empty, and a voice message can be sent here. Mic, Send, /// Empty and no voice here: Send, dimmed. Idle, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum StripKind { Reply, Edit, } /// The strip above the field while a reply or an edit is in progress. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Strip { pub kind: StripKind, pub message: String, pub title: String, pub line: String, pub cancel: String, } /// The sheet a poll is made on (chat CONTRACT.md "Making a poll"): its words only; the core checks what is sent. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PollMaker { /// The attach sheet's row, and the sheet's title. pub label: String, pub question: String, pub option: String, pub add: String, /// The switch: more than one may be chosen. pub many: String, pub send: String, /// At most this many options (WhatsApp's 12). pub most: u32, } /// `chat.compose`: everything the shared composer (COMPOSER.md) is handed. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ComposeAnswer { pub thread: String, pub text: String, pub placeholder: String, pub button: Button, pub button_label: String, pub attach: bool, pub attach_label: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub strip: Option, /// The send rule: Send is live only with something to send. pub send_enabled: bool, /// The composer's microphone dictates into the text (Cotton's voice path). pub dictate: bool, pub dictate_label: String, /// The on-screen keyboard's Return makes a new line; a hardware /// keyboard's Return sends (Shift-Return a new line). pub return_sends: bool, pub hardware_return_sends: bool, /// Where this message goes (the header's `place`), drawn by the field before Send. #[serde(default, skip_serializing_if = "Option::is_none")] pub place: Option, /// A WhatsApp chat that takes a poll he makes (chat CONTRACT.md "Making a poll"): the words of its sheet. Absent /// where no poll can be made. #[serde(default, skip_serializing_if = "Option::is_none")] pub poll: Option, /// A link in the words being written that this phone fetches a card for (chat CONTRACT.md "Link previews", /// FEEDBACK-4 B4): absent when previews are off here, the chat takes none, or there is no link. #[serde(default, skip_serializing_if = "Option::is_none")] pub preview: Option, // No pick chip: Chat has none (the shared composer draws none when the // answer names none; Story's `story.scene` is the shape of one). } // ── chat.act ──────────────────────────────────────────────────────────── /// Every act `chat.act` takes. pub const ACTS: &[&str] = &[ "send", "react", "unreact", "edit", "delete", "pin", "unpin", "forward", "read", "unread", "mute", "unmute", "archive", "unarchive", "pinChat", "unpinChat", "typing", "deleteChat", // Acts on his WhatsApp itself, through the Mac: a person blocked there, and a chat deleted there for him alone // (owner, 24 Nov 2026; CONTRACT "Blocking a WhatsApp sender, deleting a WhatsApp chat"). "blockOnWhatsApp", "deleteOnWhatsApp", // A failed message of the person's own put back in the outbox (20 Nov 2026). "retry", // A message starred or unstarred, the person's own; the chat's disappearing timer set (chat-search, 21 Nov 2026). "star", "unstar", "timer", // His vote on a WhatsApp poll, through the Mac (CONTRACT "Documents and votes", 23 Nov 2026). "vote", // A WhatsApp message deleted in his copy only, and a poll he makes there (CONTRACT "Editing and deleting his own // message", "Making a poll"; 23 Nov 2026). "deleteMine", "poll", // A voice message's transcript from the phone that recorded it, told after the message (FEEDBACK1 item 5, 22 Nov 2026). "transcript", // A voice message of theirs played a second on one of the person's phones: theirs alone, never told to the // sender (the voice player, 23 Nov 2026). "played", ]; /// `chat.act`. A send answers its bubble at once, before the network /// (`flush` says the shell should call `chat.flush` off the main thread). #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ActAnswer { pub ok: bool, pub act: String, pub thread: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub message: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub bubble: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub row: Option, /// Forward: the conversations it went to. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub sent_to: Vec, pub flush: bool, /// A short line to toast ("Copied", "Pinned"). #[serde(default, skip_serializing_if = "Option::is_none")] pub said: Option, } // ── chat.themes ───────────────────────────────────────────────────────── /// One theme as chat draws it: colours by token, for light and dark /// (`messages::app::themes::TOKENS`, plus `tint.` and `name.`). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ChatTheme { pub id: String, pub name: String, /// Standing for the light or the dark appearance. pub on: bool, /// `plain` or a quiet pattern's id, drawn in the `pattern` colour. pub ground: String, pub light: BTreeMap, pub dark: BTreeMap, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ThemeWords { pub title: String, pub light: String, pub dark: String, /// Settings' own title. pub settings: String, } /// One choice of a Settings row (a text size, a thread ground). #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Choice { pub id: String, pub label: String, /// A text size's scale over the phone's own size. #[serde(default, skip_serializing_if = "Option::is_none")] pub scale: Option, } /// A Settings row: its title, what is chosen, and the choices in order. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Choosing { pub title: String, pub chosen: String, pub options: Vec, } /// `chat.themes` and `chat.theme.set`: every theme, and the one standing /// for each appearance (the phone's own pick, else the kit's default). #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ThemesAnswer { pub themes: Vec, pub light: String, pub dark: String, /// The thread's text size. pub text: Choosing, /// The thread's ground: `theme` (as the standing theme's `ground`), `plain` or `weave`. pub ground: Choosing, pub words: ThemeWords, } // ── search (`chat.search`, chat-search 21 Nov 2026) ───────────────────── /// One message a search found, as the results draw it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct FoundMessage { pub thread: String, pub message: String, /// The chat's name, and its picture. pub name: String, pub picture: Picture, pub group: bool, /// Who wrote it: "You", or a member's name in a group; none for the other /// person of a one-to-one (the chat's name says it). #[serde(default, skip_serializing_if = "Option::is_none")] pub from: Option, pub mine: bool, /// The words around the match, on one line, with "…" where cut … pub line: String, /// … and where the match stands in `line`, UTF-16 `[start, end)`. pub marks: Vec<[u32; 2]>, /// The time today, "Yesterday", else the day. #[serde(default, skip_serializing_if = "Option::is_none")] pub when: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SearchWords { pub hint: String, pub chats: String, pub messages: String, pub more: String, } /// `chat.search { text }`: across every chat, chats by name first, then /// messages, newest first. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SearchAnswer { /// The search as it was matched (trimmed, composed). pub text: String, /// Chats whose name holds it (a person's, a group's): only on the first page. pub chats: Vec, pub messages: Vec, /// Ask again with `after` for the next page of messages. #[serde(default, skip_serializing_if = "Option::is_none")] pub after: Option, /// Said while this phone still reads its older messages into the index: /// what was found is real, and more may come. #[serde(default, skip_serializing_if = "Option::is_none")] pub older: Option, /// "Nothing found for …" when there is nothing at all. #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option, pub words: SearchWords, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InChatWords { pub hint: String, /// Toward older matches, and toward newer. pub earlier: String, pub later: String, } /// `chat.search { text, thread }`: the matches inside one chat. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InChatAnswer { pub text: String, pub thread: String, /// Every match, newest first, at most [`COUNT_CEILING`]. The shell opens /// `hits[i]` with `chat.thread { thread, around: hits[i], find: text }`; /// "earlier" is `i + 1`, "later" is `i - 1`. pub hits: Vec, /// `hits.len()`, said as a count ("999+" past the ceiling). pub count: String, /// "{i} of {n}" for each place: `places[i]` is said while `hits[i]` is open. pub places: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub older: Option, /// "Not in this chat." when there is none. #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option, pub words: InChatWords, } // ── disappearing and starred (chat-search, 21 Nov 2026) ───────────────── /// One length a chat's timer can take. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct TimerChoice { pub seconds: u32, pub label: String, pub on: bool, } /// A conversation's disappearing timer (`chat.thread`'s `timer`): `chat.act { act: "timer", thread, seconds }` sets it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct TimerCard { /// 0 when off. pub seconds: u32, /// "Disappearing messages". pub title: String, /// "Disappearing messages: 7 days" while on, for the header; none while off. #[serde(default, skip_serializing_if = "Option::is_none")] pub label: Option, /// What it does, and what it cannot stop (a screenshot). pub note: String, /// Off, 24 hours, 7 days, 90 days; empty where the person cannot write in the chat. pub choices: Vec, } /// `chat.starred { after? }`: the person's starred messages, newest starred first. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct StarredAnswer { pub title: String, /// Each as a search result draws it, the whole message on its line, no marks. pub messages: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub after: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option, }