// The small object at the left of a conversation's strip, a call's strip and a// conversation's header: the print when there is a photograph, the typed// initial card when there is not.//// **The picture is a KEY, and bytes never cross the boundary.** `read.threads`,// `read.thread` and `read.callLog` answer the key (`phone/pictures.rs`), so// print-or-card is decided without touching a byte, and only the print that is// on screen asks `media.ensure` for a path, decoded at the edge it is drawn. A// print whose bytes have not reached this phone shows its empty window — a// window, never a grey photograph pretending to load.//// A GROUP is its own photograph, one print. Never a cluster of its members'// faces: that was the owner's correction to picture 10.importCottonKitimportSwiftUI#if canImport(UIKit)import UIKit#endif/// A picture by object key, filling whatever window it is put in — and/// picture-shaped before its bytes arrive: left to itself it is `edge` square,/// and until there is a picture its window holds a quiet picture mark.structKeyedPicture: View { @Environment(\.theme) privatevar themelet key: String?/// The edge the picture is drawn at, in points.let edge: CGFloat/// Told when the picture turns out not to be on this device (or is, after/// all), so what holds the window can say so in words under it.var onAbsent: ((Bool) -> Void)? = nil/// The picture AND the key it is about — a re-ask over the same key keeps/// it on screen, so a pop-back into the conversation list does not blink. @State privatevar slot = MediaImageSlot()var body: someView { ZStack {Rectangle().fill(theme.printWindow)iflet image = slot.image {Image(uiImage: image) .resizable() .scaledToFill() } else {Image(systemName: "photo") .font(theme.type.interface(max(ChatPictureKnobs.faceChatPictureMarkMinSize, edge * ChatPictureKnobs.faceChatPictureMarkFraction))) .foregroundStyle(theme.print(.pencil).opacity(ChatPictureKnobs.faceChatPicturePencilOpacity)) } } .frame(idealWidth: edge, idealHeight: edge) .accessibilityHidden(true) .mediaSlot($slot, key: key, edge: edge) .onChange(of: slot.isAbsent, initial: true) { _, absent in onAbsent?(absent) } }}/// A conversation or a caller, as the object at the left of their strip.structChatFace: View { @Environment(\.theme) privatevar themelet seed: Stringlet name: Stringlet pictureKey: String?/// nil: the worn theme's strip lead (`paper_strip_leading_side`).var width: CGFloat? = nilprivatevar side: CGFloat { width ?? SlipFaceKnobs.paperStripLeadingSide }var body: someView {iflet pictureKey, !pictureKey.isEmpty {InstantPrint(seed: seed, size: .thumb) {KeyedPicture(key: pictureKey, edge: side) } .frame(width: side) } else {TypedCard(name: ChatFace.initial(name), seed: seed, monogram: true) .frame(width: side * ChatPictureKnobs.faceChatPictureCardFraction) } }/// The one letter a typed card carries: the name's first letter, or a/// dash for a conversation nobody named. Numbers and symbols are kept as/// they are — a withheld caller is "+" rather than an invented letter.staticfunc initial(_ name: String) -> String {guardlet first = name.trimmingCharacters(in: .whitespacesAndNewlines).first else {return"\u{2013}" }returnString(first).uppercased() }}/// The sizes, counts and timings ChatPicture draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumChatPictureKnobs {staticlet faceChatPictureCardFraction: CGFloat = 0.92staticlet faceChatPictureMarkFraction: CGFloat = 0.2staticlet faceChatPictureMarkMinSize: CGFloat = 9staticlet faceChatPicturePencilOpacity: CGFloat = 0.35}