| 1 | import Foundation |
| 2 | |
| 3 | // đŸ¤– Shared list/format helpers that need Foundation only. |
| 4 | |
| 5 | /// A compact "last activity" label for the thread list — mirrors relTime in |
| 6 | /// web/static/chat.js. (Moved from the iOS ThreadRow; the Mac list uses it too.) |
| 7 | public func relTime(_ sec: Int64) -> String { |
| 8 | guard sec > 0 else { return "" } |
| 9 | let d = Date(timeIntervalSince1970: TimeInterval(sec)) |
| 10 | let cal = Calendar.current |
| 11 | if cal.isDateInToday(d) { |
| 12 | return d.formatted(date: .omitted, time: .shortened) |
| 13 | } |
| 14 | if cal.isDateInYesterday(d) { return "Yesterday" } |
| 15 | if let days = cal.dateComponents([.day], from: d, to: Date()).day, days < 7 { |
| 16 | return d.formatted(.dateTime.weekday(.abbreviated)) |
| 17 | } |
| 18 | return d.formatted(.dateTime.day().month(.twoDigits)) |
| 19 | } |
| 20 | /// ui.js memberCountLabel: the group-header subtitle, split by helper kind — |
| 21 | /// "2 members, 1 bot, 2 AI agents". Zero categories drop out; "0 members" |
| 22 | /// shows only when a group has no helpers at all. |
| 23 | public func memberCountLabel(people: Int, bots: Int, agents: Int) -> String { |
| 24 | var parts: [String] = [] |
| 25 | if people > 0 || (bots == 0 && agents == 0) { |
| 26 | parts.append("\(people) member\(people == 1 ? "" : "s")") |
| 27 | } |
| 28 | if bots > 0 { parts.append("\(bots) bot\(bots == 1 ? "" : "s")") } |
| 29 | if agents > 0 { parts.append("\(agents) AI agent\(agents == 1 ? "" : "s")") } |
| 30 | return parts.joined(separator: ", ") |
| 31 | } |
| 32 | |