oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3/// One turn of a sub-chat: a task's thread ("Talk about this").
4public struct ThreadTurn: Identifiable, Sendable, Equatable {
5 public var id: String
6 public var who: Specialist? // nil is you
7 /// Someone else on the team, by address; nil for you and for Equipo.
8 public var person: String?
9 public var text: String
10 public var time: Date?
11 /// Yours and still on its way: how it is going. nil once the server has it.
12 public var delivery: EquipoSession.Outgoing.State?
13 public var own: Bool { who == nil && person == nil }
14 public var timeText: String { time.map { $0.formatted(date: .omitted, time: .shortened) } ?? "" }
15
16 public init(id: String, who: Specialist?, person: String? = nil, text: String, time: Date?, delivery: EquipoSession.Outgoing.State? = nil) {
17 self.id = id; self.who = who; self.person = person; self.text = text; self.time = time; self.delivery = delivery
18 }
19 /// A reply this device is still sending.
20 public init(_ outgoing: EquipoSession.Outgoing) {
21 self.init(id: outgoing.id, who: nil, text: outgoing.text, time: nil, delivery: outgoing.state)
22 }
23 /// A thread entry: yours, Equipo's own update (author "equipo"), or a teammate's.
24 public init(_ entry: ThreadEntry, me: String?) {
25 if entry.author == "equipo" {
26 self.init(id: entry.id, who: .coordinator, text: entry.text, time: entry.at)
27 } else if let me, entry.author.caseInsensitiveCompare(me) == .orderedSame {
28 self.init(id: entry.id, who: nil, text: entry.text, time: entry.at)
29 } else {
30 self.init(id: entry.id, who: nil, person: entry.author, text: entry.text, time: entry.at)
31 }
32 }
33}
34