// FACES BROUGHT DOWN, AS A SEAM (Android 6d83189695; owner via the coordinator, 24 Nov 2026: people's display// pictures no longer showed in chats that came through WhatsApp). A face draws only what this phone holds// (`RecordPicture`, `read.mediaPath`) and redraws when bytes land (the media doorbell). Nothing brought a person's,// a contact's or a group's photo down, so every face stayed initials. This is the one step that does: after the chat// list loads, the photos of its rows' faces are asked of the core (`media.ensure`, which answers from the phone when// they are here) one at a time in the background, never in Low Data Mode, each once until a refusal's wait runs out.#if os(iOS)importCottonKitimportFoundation@MainActor finalclassChatFaces {staticlet shared = ChatFaces()privatestructWait { var tries: Int; var until: ContinuousClock.Instant }privatevar waits: [String: Wait] = [:]privatevar out: Set<String> = []/// Keys the core already answered from this phone or fetched: not asked again while the app runs.privatevar landed: Set<String> = []privatevar running: Task<Void, Never>?privatestructAsk: Encodable, Sendable { let key: String }privatestructLanded: Decodable, Sendable { let path: String; let fetched: Bool? }/// The photos behind `keys`, brought down one at a time behind whatever is already running; none in Low Data Mode.func bring(_ keys: [String], core: any CottonCalling, constrained: Bool = ChatLowData.shared.constrained) {guard !constrained else { return }let wanted = keys.filter { !$0.isEmpty && !landed.contains($0) }guard !wanted.isEmpty else { return }let before = running running = Task {await before?.valuefor key in wanted { _ = awaitself.bring(key, core: core) } } }/// One photo: whether the core fetched it just now (false when it was here already, refused, or waiting). @discardableResult func bring(_ key: String, core: any CottonCalling) async -> Bool {guard !key.isEmpty, !out.contains(key), !landed.contains(key) else { returnfalse }iflet wait = waits[key], ContinuousClock.now < wait.until { returnfalse } out.insert(key)defer { out.remove(key) }do {let answer = tryawait core.call(CottonMethod.mediaEnsure, Ask(key: key), as: Landed.self) waits[key] = nil landed.insert(key)return answer.fetched == true } catch {let tries = (waits[key]?.tries ?? 0) + 1let backoff = ChatPictureTries.backoff waits[key] = Wait(tries: tries, until: .now + backoff[min(tries, backoff.count) - 1])returnfalse } }/// The last pass, for a check that waits on it.func settled() async { await running?.value }}#endif