// Cotton Chat (chat-new-ios, 19 Nov 2026): the shapes the core answers// Chat's five methods in, mirrored from `cotton-core::messages::app::shapes`// (camelCase on the wire). The phone decides nothing: order, names, last// lines, times, counts, grouping, dividers, ticks, the composer's button,// every word and every colour arrive here.//// chat.list {filter?, search?, after?} → ChatListAnswer// chat.thread {thread, before?, after?, around?} → ChatThreadAnswer// chat.compose {thread, text?, replyTo?, edit?, cancel?} → ChatComposeAnswer// chat.act {act, thread, message?, messages?, text?, emoji?, to?, until?, replyTo?, seconds?} → ChatActAnswer// chat.themes {} → ChatThemesAnswerimportFoundationenumChatMethod {staticlet list = "chat.list"staticlet thread = "chat.thread"staticlet compose = "chat.compose"staticlet act = "chat.act"staticlet themes = "chat.themes"staticlet picture = "chat.picture"staticlet ahead = "chat.ahead"staticlet warm = "chat.warm"staticlet previews = "chat.previews"staticlet preview = "chat.preview"/// A link's page this phone fetched, read by the core as its card (`chat.linkCard {thread, url, page}`, CONTRACT.md "Link previews").staticlet linkCard = "chat.linkCard"/// The voice player: the speed (`chat.settings` voiceSpeed) and waveforms for old voice messages.staticlet settings = "chat.settings"staticlet waveforms = "chat.waveforms"staticlet waveform = "chat.waveform"staticlet file = "chat.file"staticlet flush = "chat.flush"staticlet call = "chat.call"staticlet calls = "chat.calls"staticlet callScreen = "chat.callScreen"staticlet groupCall = "chat.groupCall"}/// A message's tick: `sending`, `sent`, `delivered`, `read`, `failed`.enumChatTick: String, Codable, Sendable {case sending, sent, delivered, read, failed}/// The small mark before a last line or inside a bubble.enumChatMark: String, Codable, Sendable {case photo, album, video, voice, audio, file, contact, location, poll, deleted}/// A round picture: the photo's media key, else typed initials on a tint.structChatAvatar: Codable, Equatable, Sendable, Hashable {var photo: String?var initials: Stringvar tint: Int/// Cotton's own mark in place of a face (the Downloads chat's `picture.mark`).var mark: String? = nil}structChatLastLine: Codable, Equatable, Sendable, Hashable {var text: Stringvar sender: String?var mark: ChatMark?var mine: Boolvar tick: ChatTick?/// Where his own last line stands while it is on its way to WhatsApp through the Mac, in its bubble's words/// ("Waiting to send", "Sending…", "Not sent: <why>"); absent once it has gone (CONTRACT.md "Writing to a number").var state: String? = nil}structChatSwipe: Codable, Equatable, Sendable, Hashable {var act: Stringvar label: String/// The question to ask before the act (Delete), in the core's words.var confirm: String?}structChatListRow: Codable, Equatable, Sendable, Hashable, Identifiable {/// Cotton's own Downloads chat's thread (the core's `chat_downloads::THREAD`): in every list, never the person's.staticlet downloads = "downloads"var thread: String/// A message can be written into it from here.var sendable: Bool?var name: Stringvar group: Boolvar source: Stringvar picture: ChatAvatarvar lastLine: ChatLastLine?var when: String?var unread: Intvar markedUnread: Boolvar pinned: Boolvar muted: Boolvar archived: Boolvar typing: String?var draft: String?var leading: [ChatSwipe]var trailing: [ChatSwipe]/// A hold's menu, in the core's order and words: Mark as read or Mark as unread, Pin, Mute, Archive, Delete.var hold: [ChatSwipe] = []var id: String { thread }enumCodingKeys: String, CodingKey {case thread, sendable, name, group, source, picture, lastLine, when, unread, markedUnread, pinned, muted, archived, typing, draft, leading, trailing, hold }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) thread = try c.decode(String.self, forKey: .thread) sendable = try c.decodeIfPresent(Bool.self, forKey: .sendable) name = try c.decode(String.self, forKey: .name) group = try c.decode(Bool.self, forKey: .group) source = try c.decode(String.self, forKey: .source) picture = try c.decode(ChatAvatar.self, forKey: .picture) lastLine = try c.decodeIfPresent(ChatLastLine.self, forKey: .lastLine) when = try c.decodeIfPresent(String.self, forKey: .when) unread = try c.decode(Int.self, forKey: .unread) markedUnread = try c.decode(Bool.self, forKey: .markedUnread) pinned = try c.decode(Bool.self, forKey: .pinned) muted = try c.decode(Bool.self, forKey: .muted) archived = try c.decode(Bool.self, forKey: .archived) typing = try c.decodeIfPresent(String.self, forKey: .typing) draft = try c.decodeIfPresent(String.self, forKey: .draft) leading = try c.decode([ChatSwipe].self, forKey: .leading) trailing = try c.decode([ChatSwipe].self, forKey: .trailing) hold = try c.decodeIfPresent([ChatSwipe].self, forKey: .hold) ?? [] }}/// A fan tile, in the fan's order: a filter id, or `account`.structChatFanTile: Codable, Equatable, Sendable, Hashable, Identifiable {var id: Stringvar label: Stringvar count: Int?var on: Bool}structChatListCounts: Codable, Equatable, Sendable {var waiting: Int?var all: Intvar people: Intvar groups: Intvar unread: Intvar archived: Intvar sources: [String: Int]}structChatListWords: Codable, Equatable, Sendable {var title: Stringvar search: Stringvar empty: String}structChatListAnswer: Codable, Equatable, Sendable {var filter: Stringvar search: String?var rows: [ChatListRow]var next: String?var counts: ChatListCountsvar fan: [ChatFanTile]/// The filters above the list: All, Unread, Groups.var filters: [ChatFanTile]var words: ChatListWords/// The wait in ms until any chat's next message goes by its timer (absent: none set to go): the list is asked again then.var erasesIn: Double? = nilenumCodingKeys: String, CodingKey { case filter, search, rows, next, counts, fan, filters, words, erasesIn }init(filter: String, search: String?, rows: [ChatListRow], next: String?, counts: ChatListCounts, fan: [ChatFanTile], filters: [ChatFanTile] = [], words: ChatListWords) {self.filter = filter; self.search = search; self.rows = rows; self.next = next; self.counts = counts; self.fan = fanself.filters = filters; self.words = words }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) filter = try c.decode(String.self, forKey: .filter) search = try c.decodeIfPresent(String.self, forKey: .search) rows = try c.decode([ChatListRow].self, forKey: .rows) next = try c.decodeIfPresent(String.self, forKey: .next) counts = try c.decode(ChatListCounts.self, forKey: .counts) fan = try c.decodeIfPresent([ChatFanTile].self, forKey: .fan) ?? [] filters = try c.decodeIfPresent([ChatFanTile].self, forKey: .filters) ?? [] words = try c.decode(ChatListWords.self, forKey: .words) erasesIn = try c.decodeIfPresent(Double.self, forKey: .erasesIn) }}// MARK: chat.threadenumChatBubbleKind: String, Codable, Sendable {case text, photo, album, video, voice, audio, file, contact, location, poll, deleted}structChatMediaPart: Codable, Equatable, Sendable, Hashable {var index: Intvar kind: ChatMarkvar name: String?var width: Double?var height: Double?var length: String?var size: String?var waveform: [Double]?var preview: String?var contact: String?var number: String?/// The core says the store does not hold the file (it answered 404 when last asked) and asks again only later.var gone: Bool? = nil/// A voice message's words, heard on its sender's phone after it went (`chat.act transcript`): drawn under the player.var transcript: String? = nil/// Voice, audio and video: the length as a number, for the player's countdown and position.var durationMs: Int? = nil/// Voice: the core's 36 bar heights, 0…1 (none: the player draws its thin track).var bars: [Double]? = nil/// Voice: false on a note of theirs not played yet on any of the person's phones; absent is played.var played: Bool? = nil/// The message this part opens through when it is not its bubble's (FEEDBACK-4 B3): a grid of one tap's pictures/// to WhatsApp names each tile's own, `outbox:<row>` while it waits (index 0), the landed message after.var message: String? = nil/// The message this part's picture and file are asked of, kept and opened by (`chat.picture`, `chat.file`).func opens(in bubble: ChatBubble) -> String { message ?? bubble.message }}structChatLinkCard: Codable, Equatable, Sendable, Hashable {var url: Stringvar site: String?var title: String?var description: String?var thumb: String?}structChatQuote: Codable, Equatable, Sendable, Hashable {var message: String?var sender: Stringvar line: Stringvar mark: ChatMark?}structChatReaction: Codable, Equatable, Sendable, Hashable {var emoji: Stringvar count: Intvar mine: Bool}structChatSender: Codable, Equatable, Sendable, Hashable {var name: Stringvar picture: ChatAvatarvar tint: Int}/// An agent's message: whose agent it is (`agent: { id, name, line }` on the bubble). Plain data, so it stands outside/// ChatAgent.swift's iOS-only drawing: the macOS stub build compiles these shapes too.structChatAgentTag: Codable, Equatable, Sendable, Hashable {var id: Stringvar name: Stringvar line: String}structChatBubble: Codable, Equatable, Sendable, Hashable, Identifiable {var message: Stringvar mine: Boolvar kind: ChatBubbleKindvar text: String?var sender: ChatSender?var head: Boolvar tail: Bool/// First of one sender's unbroken words in a day: their picture, and in a group their name, stand here once.var face: Boolvar time: Stringvar tick: ChatTick?/// The person's own message still going: until this moment (ms since the epoch) nothing is drawn under/// it, so a send that goes at once never flashes "Sending" (the core's `quietUntil`).var quietUntil: Double?/// Where the person's own text stands, in the core's words, drawn under it whenever present: a WhatsApp text/// on its way through the Mac ("Waiting to send", "Sending…", "Not sent: <why>"). It wins over the marks.var state: String? = nilvar edited: String?var forwarded: String?var pinned: Boolvar reply: ChatQuote?var reactions: [ChatReaction]var media: [ChatMediaPart]var link: ChatLinkCard?var actions: [String]/// A poll, drawn as one (CONTRACT.md "Polls shown"): its words stand here, never as `text`.var poll: ChatPoll? = nil/// An agent's words (CONTRACT.md "An agent in a chat"): whose agent wrote them; drawn on the left, never as his.var agent: ChatAgentTag? = nilvar id: String { message }enumCodingKeys: String, CodingKey {case message, mine, kind, text, sender, head, tail, face, time, tick, quietUntil, state, edited, forwarded, pinned, reply, reactions, media, link, actions, poll, agent }init(message: String, mine: Bool, kind: ChatBubbleKind, text: String?, sender: ChatSender?, head: Bool, tail: Bool, time: String, tick: ChatTick?, edited: String?, forwarded: String?, pinned: Bool, reply: ChatQuote?, reactions: [ChatReaction], media: [ChatMediaPart], link: ChatLinkCard?, actions: [String], face: Bool? = nil) {self.message = message; self.mine = mine; self.kind = kind; self.text = text; self.sender = senderself.head = head; self.tail = tail; self.face = face ?? head; self.time = time; self.tick = tick; self.edited = editedself.forwarded = forwarded; self.pinned = pinned; self.reply = reply; self.reactions = reactionsself.media = media; self.link = link; self.actions = actions }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) message = try c.decode(String.self, forKey: .message) mine = try c.decode(Bool.self, forKey: .mine) kind = try c.decode(ChatBubbleKind.self, forKey: .kind) text = try c.decodeIfPresent(String.self, forKey: .text) sender = try c.decodeIfPresent(ChatSender.self, forKey: .sender) head = try c.decode(Bool.self, forKey: .head) tail = try c.decode(Bool.self, forKey: .tail) face = try c.decodeIfPresent(Bool.self, forKey: .face) ?? head time = try c.decode(String.self, forKey: .time) tick = try c.decodeIfPresent(ChatTick.self, forKey: .tick) quietUntil = try c.decodeIfPresent(Double.self, forKey: .quietUntil) state = try c.decodeIfPresent(String.self, forKey: .state) edited = try c.decodeIfPresent(String.self, forKey: .edited) forwarded = try c.decodeIfPresent(String.self, forKey: .forwarded) pinned = try c.decodeIfPresent(Bool.self, forKey: .pinned) ?? false reply = try c.decodeIfPresent(ChatQuote.self, forKey: .reply) reactions = try c.decodeIfPresent([ChatReaction].self, forKey: .reactions) ?? [] media = try c.decodeIfPresent([ChatMediaPart].self, forKey: .media) ?? [] link = try c.decodeIfPresent(ChatLinkCard.self, forKey: .link) actions = try c.decodeIfPresent([String].self, forKey: .actions) ?? [] poll = try c.decodeIfPresent(ChatPoll.self, forKey: .poll) agent = try c.decodeIfPresent(ChatAgentTag.self, forKey: .agent) }}/// A poll as its bubble draws it (the core's `poll::card`): the question, how many may be chosen, each option with/// its count, its part of the people who voted and who chose it, and the total.structChatPoll: Codable, Equatable, Sendable, Hashable {var question: String/// "Select one" or "Select one or more"; absent on an exported poll.var choose: String?var options: [ChatPollOption]/// Everyone who voted, once each ("4 votes", "No votes yet").var said: String/// The whole poll as one line, for VoiceOver.var spoken: String/// The Votes panel's title.var votesTitle: String/// He can vote here (a WhatsApp poll his Mac's link sends to): a tap on an option is `chat.act vote`.var votable: Bool? = nil}structChatPollOption: Codable, Equatable, Sendable, Hashable {var text: Stringvar votes: Int/// "2 votes", "1 vote", "No votes".var said: String/// Its part of the people who voted, 0 to 100: the bar's length.var percent: Int/// Who chose it, as the chat names them, "You" first.var voters: [String]/// The person's own choice.var mine: BoolenumCodingKeys: String, CodingKey { case text, votes, said, percent, voters, mine }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) text = try c.decode(String.self, forKey: .text) votes = try c.decodeIfPresent(Int.self, forKey: .votes) ?? 0 said = try c.decode(String.self, forKey: .said) percent = try c.decodeIfPresent(Int.self, forKey: .percent) ?? 0 voters = try c.decodeIfPresent([String].self, forKey: .voters) ?? [] mine = try c.decodeIfPresent(Bool.self, forKey: .mine) ?? false }}/// One item of a thread page, oldest first (`item` names which).enumChatThreadItem: Codable, Equatable, Sendable, Hashable, Identifiable {/// A day: its label, and the numeral and words it is drawn as ("20", "Friday · November").case day(label: String, numeral: String? = nil, words: String? = nil)case unread(label: String)/// `opens`: what a tap on the line opens, where it opens something (`safety`: the safety number's screen)./// `groupCall`: a group's call still going on, its line offering Join (chat/CONTRACT.md "Group calls").case event(message: String, text: String, call: ChatThreadCall? = nil, opens: String? = nil, groupCall: ChatGroupCallLine? = nil)case bubble(ChatBubble)privateenumTag: String, CodingKey { case item, label, message, text, call, opens, numeral, words, groupCall }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: Tag.self)switchtry c.decode(String.self, forKey: .item) {case"day":self = .day(label: try c.decode(String.self, forKey: .label), numeral: try c.decodeIfPresent(String.self, forKey: .numeral), words: try c.decodeIfPresent(String.self, forKey: .words))case"unread": self = .unread(label: try c.decode(String.self, forKey: .label))case"event":self = .event(message: try c.decode(String.self, forKey: .message), text: try c.decode(String.self, forKey: .text), call: try c.decodeIfPresent(ChatThreadCall.self, forKey: .call), opens: try c.decodeIfPresent(String.self, forKey: .opens), groupCall: try c.decodeIfPresent(ChatGroupCallLine.self, forKey: .groupCall))default: self = .bubble(tryChatBubble(from: decoder)) } }func encode(to encoder: Encoder) throws {var c = encoder.container(keyedBy: Tag.self)switchself {case .day(let label, let numeral, let words):try c.encode("day", forKey: .item); try c.encode(label, forKey: .label)try c.encodeIfPresent(numeral, forKey: .numeral); try c.encodeIfPresent(words, forKey: .words)case .unread(let label): try c.encode("unread", forKey: .item); try c.encode(label, forKey: .label)case .event(let message, let text, let call, let opens, let groupCall):try c.encode("event", forKey: .item); try c.encode(message, forKey: .message); try c.encode(text, forKey: .text)try c.encodeIfPresent(call, forKey: .call); try c.encodeIfPresent(opens, forKey: .opens)try c.encodeIfPresent(groupCall, forKey: .groupCall)case .bubble(let bubble):try c.encode("bubble", forKey: .item)try bubble.encode(to: encoder) } }/// A stable identity: a bubble's or event's message; a divider by its place.var id: String {switchself {case .day(let label, _, _): "day:\(label)"case .unread: "unread"case .event(let message, _, _, _, _): "event:\(message)"case .bubble(let bubble): bubble.message } }var bubble: ChatBubble? { ifcase .bubble(let b) = self { b } else { nil } }}structChatHeader: Codable, Equatable, Sendable {var name: Stringvar picture: ChatAvatarvar group: Boolvar source: Stringvar status: String?/// Call and Video call, only on a Cotton conversation with someone to ring.var calls: [ChatCallButton]?/// Where a message written here goes, on a copy linked to WhatsApp through the Mac: drawn under the name.var place: ChatGoes? = nil}/// Where a message goes, said before it is sent (CONTRACT.md "Writing to a number"): `cotton` ("on Cotton") or/// `whatsapp` ("via WhatsApp"), in the core's words. Absent on a copy with no WhatsApp link.structChatGoes: Codable, Equatable, Sendable, Hashable {var id: Stringvar mark: String}// MARK: calls (`messages::app::calls`)/// The header's Call / Video call: tap → `chat.call {thread, video}`.structChatCallButton: Codable, Equatable, Sendable, Hashable {var video: Boolvar label: String}/// A call's centred line in its thread: tap → `chat.call {call}`.structChatThreadCall: Codable, Equatable, Sendable, Hashable {var call: Stringvar video: Boolvar missed: Boolvar incoming: Boolvar time: String/// The tap's accessible name ("Call back").var back: String}/// A group's call going on, on its line in the group: Join beside it (`chat.call { thread, join: true }`).structChatGroupCallLine: Codable, Equatable, Sendable, Hashable {var room: Stringvar video: Boolvar join: String}/// `chat.groupCall { thread }`: whether the group's call goes on, for the strip under the header. `unknown`: offline,/// never said as over.structChatGroupCallState: Codable, Equatable, Sendable {var live: Boolvar room: String?var unknown: Bool?var video: Bool?var here: Bool?var banner: String?/// "Asha, Ravi in the call".var `in`: String?var people: [String]?var count: Int?var join: String?var hereText: String?}/// `chat.call`: from a conversation, or calling back a call.structChatCallAsk: Codable, Equatable, Sendable {var thread: String?var call: String?var video: Bool?}/// `chat.calls`: the Calls tile, newest first, 80 a page.structChatCallsAnswer: Codable, Equatable, Sendable {var rows: [ChatCallRow]var next: String?var words: ChatCallsWords}structChatCallsWords: Codable, Equatable, Sendable {var title: Stringvar empty: Stringvar back: String/// Record, right of the title (CONTRACT.md "Recordings"): starts a recording.var record: String?/// Bring in a recording: the Files picker, audio only.var `import`: String?/// What Record says when the microphone is not allowed (iPhone's ask of the contract).var no_microphone: String?}/// A row of Calls: a call, or (CONTRACT.md "Recordings") a recording listed with the calls by day.structChatCallRow: Codable, Equatable, Sendable, Hashable, Identifiable {var call: Stringvar name: Stringvar picture: ChatAvatarvar thread: String?var incoming: Boolvar video: Boolvar missed: Boolvar group: Boolvar line: Stringvar when: String/// `call` or `recording`; nil is a call.var kind: String? = nil/// The heading of the day the row is under: drawn above a row whose day differs from the one before.var day: String? = nil/// A recording row's recording, or the notes this person took on a call.var recording: String? = nil/// A recording row's mark: `recording`, `memo` or `import`.var mark: String? = nilvar isRecording: Bool { kind == "recording" }var id: String { isRecording ? "recording-\(recording ?? "")" : call }}extensionChatCallRow {privateenumKeys: String, CodingKey {case call, name, picture, thread, incoming, video, missed, group, line, when, kind, day, recording, mark }/// A recording row carries only its own fields: the call's stand empty.init(from decoder: any Decoder) throws {let c = try decoder.container(keyedBy: Keys.self) call = try c.decodeIfPresent(String.self, forKey: .call) ?? "" name = try c.decode(String.self, forKey: .name) picture = try c.decodeIfPresent(ChatAvatar.self, forKey: .picture) ?? ChatAvatar(photo: nil, initials: "", tint: 0) thread = try c.decodeIfPresent(String.self, forKey: .thread) incoming = try c.decodeIfPresent(Bool.self, forKey: .incoming) ?? false video = try c.decodeIfPresent(Bool.self, forKey: .video) ?? false missed = try c.decodeIfPresent(Bool.self, forKey: .missed) ?? false group = try c.decodeIfPresent(Bool.self, forKey: .group) ?? false line = try c.decodeIfPresent(String.self, forKey: .line) ?? "" when = try c.decodeIfPresent(String.self, forKey: .when) ?? "" kind = try c.decodeIfPresent(String.self, forKey: .kind) day = try c.decodeIfPresent(String.self, forKey: .day) recording = try c.decodeIfPresent(String.self, forKey: .recording) mark = try c.decodeIfPresent(String.self, forKey: .mark) }}/// `chat.callScreen {speaker?}`: the call screen and the returning bar.structChatCallScreen: Codable, Equatable, Sendable {var shown: Boolvar phase: Stringvar name: Stringvar picture: ChatAvatarvar status: String?/// Ms since the epoch the call went live; the clock is drawn from it.var liveAt: Double?var video: Boolvar camera: Boolvar controls: [ChatCallControl]var ring: ChatCallRing?var bar: String?var endedFor: Doublevar thread: String?/// Someone on the call is taking notes (CONTRACT.md "Take notes"): drawn on the call screen and its bar while it stands.var notes: ChatCallNotes? = nil/// A group call (CONTRACT.md "Group calls"): a tile per person in `grid`, and the privacy line.var group: Bool? = nilvar tiles: [ChatCallTile]? = nilvar grid: ChatCallGrid? = nil/// "Protected in transit", and what a tap on it says.var privacy: String? = nilvar privacyDetail: String? = nil/// Take notes refused or stopped because someone cannot show the mark, in the core's words.var notice: String? = nil/// The controls this phone offers: all the core's but Take notes, until the iPhone records the notes it takes/// (CONTRACT.md "Take notes", the iPhone's tracks). The mark of anyone else's notes is drawn all the same.var offered: [ChatCallControl] { controls.filter { $0.id != "notes" } }staticlet hidden = ChatCallScreen(shown: false, phase: "", name: "", picture: ChatAvatar(photo: nil, initials: "", tint: 0), status: nil, liveAt: nil, video: false, camera: false, controls: [], ring: nil, bar: nil, endedFor: 0, thread: nil)}/// One person on a group call: the others in the room's order, you last.structChatCallTile: Codable, Equatable, Sendable, Identifiable {var member: Stringvar name: Stringvar picture: ChatAvatarvar you: Boolvar joined: Bool/// "Ringing…" for someone still being rung.var state: String?var speaking: Boolvar muted: Boolvar camera: Boolvar notes: Boolvar id: String { member }}/// The tiles' columns and rows (2: 1×2; 3–4: 2×2; 5–6: 2×3; 7–8: 2×4; 9: 3×3).structChatCallGrid: Codable, Equatable, Sendable {var columns: Intvar rows: Int}/// `chat.callScreen`'s `notes`: who is taking notes, the line that says so, and the mark.structChatCallNotes: Codable, Equatable, Sendable {structTaker: Codable, Equatable, Sendable {var member: Stringvar name: String }var by: [Taker]var line: Stringvar mark: Bool}structChatCallControl: Codable, Equatable, Sendable, Hashable, Identifiable {var id: Stringvar label: Stringvar on: Bool}structChatCallRing: Codable, Equatable, Sendable {var title: Stringvar answer: Stringvar decline: String}structChatPinnedBar: Codable, Equatable, Sendable {var message: Stringvar title: Stringvar line: Stringvar count: Int}/// A stranger's first message waits on an answer: Accept, Block and/// Delete go to `chat.accept` / `chat.block` / `chat.refuse`.structChatAskCard: Codable, Equatable, Sendable {var title: Stringvar line: Stringvar accept: Stringvar block: Stringvar refuse: String}structChatJump: Codable, Equatable, Sendable {var count: Intvar label: String}structChatActionWords: Codable, Equatable, Sendable {var reply: Stringvar react: Stringvar copy: Stringvar forward: Stringvar edit: Stringvar delete: Stringvar pin: Stringvar unpin: Stringvar select: String/// Message info, in a Cotton group (older cores answer none).var info: String?/// Delete for me, in a WhatsApp chat that sends: his copy only (CONTRACT.md "Delete for me"; older cores answer none).var deleteMine: String?/// Star and Unstar (older cores answer none).var star: String?var unstar: String?var copied: Stringvar emoji: [String]/// An action's word, by the act a bubble offers.func word(_ act: String) -> String {switch act {case"reply": replycase"react": reactcase"copy": copycase"forward": forwardcase"edit": editcase"delete": deletecase"pin": pincase"unpin": unpincase"select": selectcase"info": info ?? ShellLines.line("chat", "app.group.info")case"deleteMine": deleteMine.flatMap { $0.isEmpty ? nil : $0 } ?? ShellLines.line("chat", "app.actions.delete_mine")case"star": star ?? ShellLines.line("chat", "app.actions.star")case"unstar": unstar ?? ShellLines.line("chat", "app.actions.unstar")case"retry": ShellLines.line("chat", "app.actions.retry")default: act } }}structChatThreadAnswer: Codable, Equatable, Sendable {var thread: Stringvar header: ChatHeadervar pinned: ChatPinnedBar?var items: [ChatThreadItem]var older: String?var newer: String?var focus: String?var unread: Intvar jump: ChatJump?var composer: ChatComposeAnswer?var readOnly: String?var request: ChatAskCard?var actions: ChatActionWords/// Whether the person can be written to yet.var reach: ChatReach? = nil/// "Loading this chat…" while the first pull runs and nothing of it has come.var loading: String? = nil/// The chat's disappearing timer (CONTRACT.md "Disappearing messages"): none where the core answers none.var timer: ChatTimerCard? = nil/// The wait in ms until this chat's next message goes (its timer's time come): the chat is asked again then, so it/// leaves while he looks (absent: none set to go).var erasesIn: Double? = nil}/// One length a chat's timer can take (`timer.choices`).structChatTimerChoice: Codable, Equatable, Sendable, Hashable, Identifiable {var seconds: Intvar label: Stringvar on: Boolvar id: Int { seconds }}/// A chat's disappearing timer (`chat.thread`'s `timer`): `chat.act { act: "timer", thread, seconds }` sets it.structChatTimerCard: Codable, Equatable, Sendable {/// 0 when off.var seconds: Int/// "Disappearing messages".var title: String/// "Disappearing messages: 7 days" while on (the header says it); none while off.var label: String?/// What it does, and what it cannot stop.var note: String/// Off, 24 hours, 7 days, 90 days; empty where the person cannot set it (they cannot write in the chat).var choices: [ChatTimerChoice]}/// `reach` on `chat.thread`: whether the person can be written to yet./// Here, not in ChatPeople.swift (iOS only), because ChatThreadAnswer builds on the Mac too.structChatReach: Codable, Equatable, Sendable {/// `on` or `notYet`.var state: Stringvar waiting: Int?var number: String?}// MARK: chat.composeenumChatButton: String, Codable, Sendable {case mic, send, idle}enumChatStripKind: String, Codable, Sendable {case reply, edit}structChatStrip: Codable, Equatable, Sendable {var kind: ChatStripKindvar message: Stringvar title: Stringvar line: Stringvar cancel: String}structChatComposeAnswer: Codable, Equatable, Sendable {var thread: Stringvar text: Stringvar placeholder: Stringvar button: ChatButtonvar buttonLabel: Stringvar attach: Boolvar attachLabel: Stringvar strip: ChatStrip?/// The send rule: Send is live only with something to send.var sendEnabled: Bool/// The composer's microphone dictates into the text (Cotton's voice path).var dictate: Boolvar dictateLabel: String/// The on-screen keyboard's Return sends (false: a new line).var returnSends: Boolvar hardwareReturnSends: Bool/// Where this message goes (the header's `place`), drawn by the field before Send.var place: ChatGoes? = nil/// The link in the words this phone fetches a card for (`composer.preview {url}`, FEEDBACK-4 B4); absent when none goes.var preview: ChatPreviewAsk? = nil/// The words of the sheet a poll is made on, where he can make one (a WhatsApp chat whose outbox takes it).var poll: ChatPollMaker? = nilinit(thread: String, text: String, placeholder: String, button: ChatButton, buttonLabel: String, attach: Bool, attachLabel: String, strip: ChatStrip?, sendEnabled: Bool, dictate: Bool, dictateLabel: String, returnSends: Bool, hardwareReturnSends: Bool) {self.thread = thread; self.text = text; self.placeholder = placeholder; self.button = button; self.buttonLabel = buttonLabelself.attach = attach; self.attachLabel = attachLabel; self.strip = strip; self.sendEnabled = sendEnabledself.dictate = dictate; self.dictateLabel = dictateLabel; self.returnSends = returnSends; self.hardwareReturnSends = hardwareReturnSends }enumCodingKeys: String, CodingKey {case thread, text, placeholder, button, buttonLabel, attach, attachLabel, strip, sendEnabled, dictate, dictateLabel, returnSends, hardwareReturnSends, place, preview, poll }init(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) thread = try c.decode(String.self, forKey: .thread) text = try c.decode(String.self, forKey: .text) placeholder = try c.decode(String.self, forKey: .placeholder) button = try c.decode(ChatButton.self, forKey: .button) buttonLabel = try c.decode(String.self, forKey: .buttonLabel) attach = try c.decode(Bool.self, forKey: .attach) attachLabel = try c.decode(String.self, forKey: .attachLabel) strip = try c.decodeIfPresent(ChatStrip.self, forKey: .strip)// The first shapes had none of these: read as the core then meant them. sendEnabled = try c.decodeIfPresent(Bool.self, forKey: .sendEnabled) ?? (button == .send) dictate = try c.decodeIfPresent(Bool.self, forKey: .dictate) ?? false dictateLabel = try c.decodeIfPresent(String.self, forKey: .dictateLabel) ?? "" returnSends = try c.decodeIfPresent(Bool.self, forKey: .returnSends) ?? false hardwareReturnSends = try c.decodeIfPresent(Bool.self, forKey: .hardwareReturnSends) ?? true place = try c.decodeIfPresent(ChatGoes.self, forKey: .place) preview = try c.decodeIfPresent(ChatPreviewAsk.self, forKey: .preview) poll = try c.decodeIfPresent(ChatPollMaker.self, forKey: .poll) }}/// `composer.preview`: the link whose card this phone may fetch.structChatPreviewAsk: Codable, Equatable, Sendable {var url: String}/// `chat.linkCard`'s answer: the fetched page read as its card; `image` the picture this phone fetches and makes the/// card's `thumb`. Empty (`{}`, no title) when no card goes.structChatLinkCardAnswer: Codable, Equatable, Sendable {var url: String?var site: String?var title: String?var description: String?var image: String?}/// The sheet a poll is made on (CONTRACT.md "Making a poll"): its words only; the core checks what is sent.structChatPollMaker: Codable, Equatable, Sendable {/// The attach sheet's row, and the sheet's title.var label: Stringvar question: Stringvar option: Stringvar add: String/// The switch: more than one may be chosen.var many: Stringvar send: String/// At most this many options.var most: Int}// MARK: chat.actstructChatActAnswer: Codable, Equatable, Sendable {var ok: Boolvar act: Stringvar thread: Stringvar message: String?var bubble: ChatBubble?var row: ChatListRow?var sentTo: [String]?var flush: Boolvar said: String?}// MARK: chat.themes/// One theme: colours by token (`ground`, `bubble_out`, `ink_in`,/// `tint.<n>` …), for light and for dark.structChatThemeAnswer: Codable, Equatable, Sendable, Identifiable {var id: Stringvar name: Stringvar on: Bool/// `plain` or a quiet pattern's id (`weave`), drawn in `pattern`.var ground: Stringvar light: [String: String]var dark: [String: String]}/// One choice of a Settings row: a text size (with its scale) or a ground.structChatChoice: Codable, Equatable, Sendable, Identifiable {var id: Stringvar label: Stringvar scale: Double?}/// A Settings row: its title, what is chosen, the choices in order.structChatChoosing: Codable, Equatable, Sendable {var title: Stringvar chosen: Stringvar options: [ChatChoice]}structChatThemeWords: Codable, Equatable, Sendable {var title: Stringvar light: Stringvar dark: Stringvar settings: String}/// `chat.themes` (and what `chat.theme`, `chat.text`, `chat.ground` answer):/// every theme, the one standing for each appearance, the text size, the/// thread's ground and Settings' words.structChatThemesAnswer: Codable, Equatable, Sendable {var themes: [ChatThemeAnswer]var light: Stringvar dark: Stringvar text: ChatChoosingvar ground: ChatChoosingvar words: ChatThemeWordsfunc theme(dark: Bool) -> ChatThemeAnswer? {let chosen = dark ? self.dark : lightreturn themes.first { $0.id == chosen } ?? themes.first }}enumChatSettingsMethod {staticlet theme = "chat.theme"staticlet text = "chat.text"staticlet ground = "chat.ground"}// MARK: requestsstructChatListAsk: Codable, Equatable, Sendable {var filter: String?var search: String?var after: String?/// Only the rows a message can be written into (Forward's picker).var sendable: Bool?}structChatThreadAsk: Codable, Equatable, Sendable {var thread: Stringvar before: String?var after: String?var around: String?}structChatComposeAsk: Codable, Equatable, Sendable {var thread: Stringvar text: String?var replyTo: String?var edit: String?var cancel: Bool?/// Pictures waiting in the writing box, to go with what is written as their caption: with any, Send is live.var attached: Int?}/// `chat.file`'s answer: any attachment written under its own extension/// (a PDF a `.pdf`, a video an `.mp4`), to open with the system.structChatFileAnswer: Codable, Equatable, Sendable {var path: Stringvar mime: Stringvar name: String?/// `video`, `file`, `photo`, `voice` …, when the message said one.var kind: String?/// Whether it is kept in the person's own media past the chat store's 30 days.var kept: Bool?var url: URL { URL(fileURLWithPath: path) }}structChatActAsk: Codable, Equatable, Sendable {var act: Stringvar thread: Stringvar message: String?var messages: [String]?var text: String?var emoji: String?var to: [String]?var until: String?var attachments: [ChatAttachment]?/// `send`: the message this answers (the composer's reply strip), so its bubble quotes it.var replyTo: String?/// `timer`: the length, one of the card's choices (0 is Off).var seconds: Int?/// `send`: the link card fetched here for a link in the words (`url, site, title, description, thumb`); the core keeps it.var preview: ChatLinkCard?/// `vote`: the option tapped, 0 first.var option: Int?/// `poll`: the question, the options in order, and whether more than one may be chosen.var question: String?var options: [String]?var many: Bool?}/// A file sent with a message: a photo, a video, a file or a voice message,/// lying on the phone at `path` until `chat.flush` seals and uploads it.structChatAttachment: Codable, Equatable, Sendable {var path: Stringvar mime: Stringvar name: String?var width: Double?var height: Double?/// `photo`, `video`, `file` or `voice`.var kind: String?var durationMs: Double?/// A voice message's levels, 0…1.var waveform: [Double]?/// A picture's preview made here (`ChatPreviewMaker`): sealed in the message, so it arrives with the words.var preview: String?}