Cotton code
112 lines · 5.1 KB · SwiftRaw
// A meeting ENTERING from this phone — the one door, and the one rule about// which files may come through it.//// Two producers reach `meetings.create`: the Meetings list's file picker and// the record screen's Stop, and the share sheet's audio branch is a third// (`ShareIntake.swift`). All three hand over a PATH and nothing else — the// crate copies the bytes into the store and the caller discards its own copy// afterwards, which is the same contract `capture.media` already has and for// the same reason: bytes never cross the boundary (design M2).//// **The accepted set lives in ONE place**, `MeetingAudioFormats`// (`CottonMailbox/MeetingAudioFormats.swift`, where the share extension can// read it without the core). Before it the share sheet had// its own extension list and the picker had none at all, which is how a// WhatsApp voice note — `.opus` in an Ogg container, usually with no declared// type — fell out of every list and was filed as a page. Two lists that must// agree is how a fix lands on only one of them, so `MeetingAudioFormats` is the rule// and `ShareIntake`'s own sets are built from it.//// **The crate is still the authority on what it will take.** This set is what// the phone OFFERS; a file the server's key contract refuses comes back as a// refusal with the crate's own sentence, and the screen shows that sentence// rather than a sentence of its own.import Foundation// ``CottonMethod/meetingsCreate`` is NOT declared here. It is named in// `TrafficMethods.swift`, where every method name this app asks for is said// once — a name declared beside the screen that sends it is invisible to// `BoundaryContractTests`, which reads the crate's own tables by path, so a// crate-side rename would reach the app as an `unknown_method` at runtime// instead of as a red test. What lives here is the SHAPE of the call, which is// this lane's./// Where the audio came from — the one argument the crate cannot infer.public enum MeetingSource: String, Sendable, Equatable, CaseIterable {    /// This phone's own recorder, which knows when it started and how long it    /// ran.    case record    /// A file that arrived — picked from Files, or shared in from another app.    case `import`}/// `meetings.create`'s request.////// A synthesised `Encodable` omits a nil optional, so an unset field is an/// ABSENT field rather than a null — which is what lets the crate answer each/// of them with its own default (the day for a title, the file's own probe for/// a length) instead of being handed a null it has to re-decide.public struct MeetingCreateRequest: Encodable, Sendable, Equatable {    /// Where the bytes are NOW, on this device and outside the share inbox.    /// Copied into the store, never referenced in place.    public var path: String    public var source: String    /// What to call it. Absent lets the crate name it — the file's stem for an    /// import, the day for a recording.    public var title: String?    /// When the recording STARTED, RFC3339. A recording knows; an import    /// usually does not, and absent is honest.    public var startedAt: String?    /// How long it ran. The recorder's own elapsed figure — never a file    /// length this side probed, because a probe that fails would put a zero on    /// a row that means "we do not know".    public var durationMs: Int?    /// The wire type, from ``MeetingAudioFormats``. Absent lets the crate read the    /// extension.    public var mime: String?    public init(        path: String,        source: MeetingSource,        title: String? = nil,        startedAt: String? = nil,        durationMs: Int? = nil,        mime: String? = nil    ) {        self.path = path        self.source = source.rawValue        // A blank title is an ABSENT title: the crate's own default is a better        // name than an empty line, and a person who cleared the field on the        // record screen has said "you name it", not "call it nothing".        let trimmed = title?.trimmingCharacters(in: .whitespacesAndNewlines)        self.title = (trimmed?.isEmpty ?? true) ? nil : trimmed        self.startedAt = startedAt        self.durationMs = durationMs        self.mime = mime    }}/// `meetings.create`'s answer — the row's id, and the screen to open.////// **The ROUTE comes from the crate** rather than being spelled here. The route/// strings are wire protocol (design P6) and the crate already owns the table;/// a second spelling up here would be a second opinion about where a meeting/// lives. `route(parsedBy:)` is the one reader, and it falls back on the id/// when the crate answered a path this build's parser does not know — a new/// server is allowed to be ahead of an old app, and losing the meeting that was/// just created would be the worse failure.public struct MeetingCreated: Decodable, Equatable, Sendable {    public var id: String    public var route: String    public init(id: String = "", route: String = "") {        self.id = id        self.route = route    }    /// The screen to open.    public var landing: Route {        Route.parse(route) ?? .meetingsMeeting(id: id)    }}