// A send drawn as the real card: the root record's face with its fields, as// the object read them off the payload (`card`), its pictures fetched through// the send before Keep (`send.picture`), and under it what the core says of// it — whom from, its state, how far its copy has come — and its acts, each// asked of the core as it said them. The thread with the sender draws it in// Messages; an app with no chat draws it on its Sent to you card.importCottonFacesimportCottonKitimportCottonPaperimportCottonValuesimportSwiftUI#if canImport(UIKit)importImageIOimport UIKit#endifstructSendCard: View {let item: SendItem/// The card's words and acts: the item's own unless the thread's row holds newer.var shows: SendShows? = nil @Environment(\.cottonCore) privatevar core @Environment(ToastCenter.self) privatevar toasts: ToastCenter? @Environment(Navigator.self) privatevar navigator: Navigator? @Environment(\.tableDefinitions) privatevar definitionsprivatevar center: SendCenter { .session }privatevar said: SendShows? { shows ?? item.shows }var body: someView { VStack(alignment: .leading, spacing: 8) {iflet from = said?.from {Text(from).paperMeta().accessibilityIdentifier("send-from-\(item.id)") } face .frame(width: SendKnobs.cardWidth, height: SendKnobs.cardWidth * SendKnobs.cardRatio) .clipShape(RoundedRectangle(cornerRadius: 8)) .environment(\.facePictureDrawer) { key, edge inAnyView(SendPicture(send: item.id, key: key, edge: edge)) } .allowsHitTesting(false) .accessibilityIdentifier("send-card-\(item.id)")iflet line = said?.line {Text(line).paperMeta().accessibilityIdentifier("send-line-\(item.id)") }iflet fraction = said?.progress?.fraction {ProgressView(value: fraction).frame(width: SendKnobs.cardWidth) .accessibilityIdentifier("send-progress-\(item.id)") } acts } .task(id: item.copying) { if item.copying { await center.follow(item, core: core) } } .accessibilityElement(children: .contain) } @ViewBuilder privatevar face: someView {iflet value = item.card, case .success(let card)? = DeckCard.read(RecordValue(value)), let face = FaceRegistry.face(card.face) { face.view(card, picture: nil, taps: FaceTaps()) } else {RoundedRectangle(cornerRadius: 8).fill(PaperDye.cream.fill) .overlay { Text(item.title ?? "").paperTitle().padding() } } }/// The core's acts in its order, the primary first as it said.privatevar acts: someView { HStack(spacing: 14) {ForEach(said?.acts ?? []) { act inPaperTypedButton(act.words, destructive: act.red == true) {Task { await center.run(act, on: item.id, core: core, toasts: toasts, open: open) } } .disabled(center.busy.contains(item.id)) .accessibilityIdentifier("send-\(act.id)-\(item.id)") } } }/// The record a send landed as, or the one already held, opened where its deck stands.privatefuncopen(_ record: SendRecordRef) { navigator?.open(table: record.table, id: record.id, definition: definitions[record.table]) }}/// A picture an offer names (its cover), fetched once through the send and/// drawn at the card's size; nothing while it comes.structSendPicture: View {let send: Stringlet key: Stringlet edge: CGFloat @Environment(\.cottonCore) privatevar core #if canImport(UIKit) @State privatevar image: UIImage? #endifvar body: someView {Group { #if canImport(UIKit)iflet image {Image(uiImage: image).resizable().scaledToFill() } else {Color.clear } #elseColor.clear #endif } .task(id: key) { await load() } }privatefunc load() async { #if canImport(UIKit)guardlet core else { return }let dir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("send-pictures", isDirectory: true)let ask = JSONValue.object(["id": .string(send), "key": .string(key), "dir": .string(dir.path)])guardlet path = try? await core.callJSON(CottonMethod.sendPicture, ask)["path"]?.string else { return } image = Self.picture(at: URL(fileURLWithPath: path), edge: edge) #endif } #if canImport(UIKit)/// Decoded at the card's size by ImageIO, never the whole file into memory.privatestaticfunc picture(at file: URL, edge: CGFloat) -> UIImage? {guardlet source = CGImageSourceCreateWithURL(file as CFURL, nil),let drawn = CGImageSourceCreateThumbnailAtIndex(source, 0, [ kCGImageSourceCreateThumbnailFromImageAlways: true, kCGImageSourceCreateThumbnailWithTransform: true, kCGImageSourceThumbnailMaxPixelSize: max(1, Int(edge * 3)), ] as CFDictionary)else { returnnil }return UIImage(cgImage: drawn) } #endif}/// The Sent to you card's page, in an app with no chat tool: what was sent/// to this person, each as its real card with its acts, the newest first/// (send-walk, 13 Nov 2026: oldest first, a new arrival stood below the fold/// under the hovering fan). Messages draws them in the thread, in its order.structSentPage: View { @Environment(\.cottonCore) privatevar core @Environment(\.scenePhase) privatevar scenePhaseprivatevar center: SendCenter { .session }var body: someView {ScrollView {LazyVStack(alignment: .leading, spacing: 28) {ForEach(center.incoming.reversed()) { item inSendCard(item: item) } } .padding(.horizontal, 16) .padding(.vertical, 24) .frame(maxWidth: .infinity, alignment: .leading) } .accessibilityIdentifier("sent-page") .task { await center.refresh(core: core) } .onReceive(NotificationCenter.default.publisher(for: .cottonSendArrived)) { _ inTask { await center.refresh(core: core) } } .onChange(of: scenePhase) { _, phase inif phase == .active { Task { await center.refresh(core: core) } } } }}