Repository Public
1import Foundation23struct Snapshot: Decodable {4 var ready = false5 var online = false6 var fatal: String?7 var me: MeInfo?8 var convs: [Conv] = []9 var messages: [Message] = []10 var pending: [PendingDevice] = []11 var notices: [String] = []12 var unread = 013 var prefs: Prefs?14 private enum CodingKeys: String, CodingKey { case ready, online, fatal, me, convs, messages, pending, notices, unread, prefs }15 init() {}16 init(from d: Decoder) throws {17 let c = try d.container(keyedBy: CodingKeys.self)18 ready = (try? c.decode(Bool.self, forKey: .ready)) ?? false19 online = (try? c.decode(Bool.self, forKey: .online)) ?? false20 fatal = try? c.decodeIfPresent(String.self, forKey: .fatal)21 me = try? c.decodeIfPresent(MeInfo.self, forKey: .me)22 convs = (try? c.decode([Conv].self, forKey: .convs)) ?? []23 messages = (try? c.decode([Message].self, forKey: .messages)) ?? []24 pending = (try? c.decode([PendingDevice].self, forKey: .pending)) ?? []25 notices = (try? c.decode([String].self, forKey: .notices)) ?? []26 unread = (try? c.decode(Int.self, forKey: .unread)) ?? 027 prefs = try? c.decodeIfPresent(Prefs.self, forKey: .prefs)28 }29}30struct MeInfo: Decodable, Equatable { let id, name, handle, role: String }31struct Prefs: Decodable, Equatable { var readReceipts: Bool; var compress: Bool; var notify: Bool }32struct PendingDevice: Decodable, Identifiable, Equatable { let id, label, code: String }33struct Named: Decodable, Identifiable, Equatable { let id, name: String; var canAccept: Bool? }34struct Member: Decodable, Identifiable, Equatable { let id, name, role: String; let verified, me: Bool }35struct Conv: Decodable, Identifiable, Equatable, Hashable {36 static func == (a: Conv, b: Conv) -> Bool { a.id == b.id && a.title == b.title && a.unread == b.unread && a.lastTs == b.lastTs && a.preview == b.preview && a.typing == b.typing && a.waiting == b.waiting && a.warnings == b.warnings && a.missing == b.missing && a.members == b.members && a.ttl == b.ttl && a.muted == b.muted && a.online == b.online && a.left == b.left }37 func hash(into h: inout Hasher) { h.combine(id) }38 let id, kind, title, peer: String39 let unread: Int40 let lastTs: Double41 let preview: String42 let muted, left, waiting, online: Bool43 let typing: [String]44 let warnings: [Named]45 let missing: [Named]46 let ttl: Int47 let members: [Member]48 let epoch, devices: Int49}50struct Reaction: Decodable, Equatable, Identifiable { let emoji: String; let count: Int; let mine: Bool; var id: String { emoji } }51struct Attachment: Decodable, Equatable, Identifiable {52 let id, name, mime: String53 let size: Int54 let w, h: Double55 let dur: Double56 let voice: Bool57 let thumb, ref: String58 var isVisual: Bool { (mime.hasPrefix("image/") && !thumb.isEmpty) || mime.hasPrefix("video/") }59}60struct ReplyRef: Decodable, Equatable { let id, name, excerpt: String }61struct SysInfo: Decodable, Equatable { let type: String; let users: [String]; let text: String; let video: Bool }62struct Message: Decodable, Identifiable, Equatable {63 let id: String64 let seq: Int65 let from, fromName: String66 let mine: Bool67 let ts: Double68 let kind, body: String69 let deleted, edited, pinned: Bool70 let status: String71 let untrusted: Bool72 let receipt: Int73 let reply: ReplyRef?74 let fwd: String?75 let reactions: [Reaction]76 let files: [Attachment]77 let sys: SysInfo?78 var date: Date { Date(timeIntervalSince1970: ts / 1000) }79}80struct Contact: Decodable, Identifiable, Equatable { let id, handle, name: String; let verified: Bool }81struct DeviceRow: Decodable, Identifiable, Equatable {82 let id, label, status: String83 let enrolled_via: String?84 let current: Bool85}86