// COMMS' EXPORT ON IPHONE (chat CONTRACT.md "Export"; owner, 23 Nov 2026, promised on the website for launch).// The core writes the file (`chat.export`: one chat, or every chat, as a text file with names and times and the// files this phone holds, in a zip); the phone only offers it and hands it to the share sheet, as Words' export// does. Every chat from You → Export; one chat from Export chat on its own page (a person's, a group's).#if os(iOS)importCottonKitimportSwiftUIenumChatExportMethod {/// `{ thread? }` → `{ path, file_name, mime, count, files, missing }`; refused `refused` with nothing to export.staticlet export = "chat.export"}/// The zip the core wrote.structChatExported: Decodable, Equatable, Sendable {let path: Stringlet fileName: StringenumCodingKeys: String, CodingKey {case pathcase fileName = "file_name" }}enumChatExport {privatestructAsk: Encodable, Sendable {var thread: String? }/// One chat (`thread`) or every chat (nil), written by the core and handed to the share sheet; a refusal is said/// in the core's words. @MainActor staticfunc share(_ core: (any CottonCalling)?, thread: String?, said: (String) -> Void) async {guardlet core else { return }do {let made = tryawait core.call(ChatExportMethod.export, Ask(thread: thread), as: ChatExported.self)ShareSheet.present(URL(fileURLWithPath: made.path)) } catch { said(ActionRefused.words(for: error)) } }}/// You → Export: what it makes, then Export all chats.structChatYouExportPage: View {let core: (any CottonCalling)?let back: () -> Void @Environment(\.chatLook) privatevar look @Environment(ToastCenter.self) privatevar toasts: ToastCenter? @State privatevar working = falsevar body: someView {ChatYouPageFrame(title: ChatWords.line("export.title"), id: "you-export-page", back: back) { VStack(alignment: .leading, spacing: 18) {Text(verbatim: ChatWords.line("export.hint")) .font(look.font(16)).foregroundStyle(look.colours.dim) .fixedSize(horizontal: false, vertical: true)WarmPill(words: ChatWords.line("export.all"), id: "you-export-all", accent: true) {guard !working else { return } working = trueTask {awaitChatExport.share(core, thread: nil) { toasts?.show($0, tone: .error) } working = false } } .opacity(working ? 0.5 : 1) } .padding(.top, 8) } }}#endif