Watch: keep Recent past 10 behind an N more row with a full list, and settle all in one call
This commit is contained in:
1 parent
2a127327bf
commit
a5222e14e8
13 files changed
+384
-52
No files matched your search
@@ -167,8 +167,51 @@ struct FeedItem: Codable, Hashable, Sendable, Identifiable {
|
||||
struct Feed: Codable, Hashable, Sendable {
|
||||
var needsYou: [FeedItem]
|
||||
var working: [FeedItem]
|
||||
/// Finished or failed threads not settled yet, newest first and at most 10.
|
||||
var recent: [FeedItem]
|
||||
/// How many threads Recent holds in all. `GET /v1/recent` lists the ones past `recent`.
|
||||
var recentTotal: Int
|
||||
var hosts: [HostSummary]
|
||||
|
||||
/// `recentTotal` defaults to the threads in `recent`, as when nothing is left out.
|
||||
init(needsYou: [FeedItem], working: [FeedItem], recent: [FeedItem], recentTotal: Int? = nil, hosts: [HostSummary]) {
|
||||
self.needsYou = needsYou
|
||||
self.working = working
|
||||
self.recent = recent
|
||||
self.recentTotal = recentTotal ?? recent.count
|
||||
self.hosts = hosts
|
||||
}
|
||||
|
||||
/// Recent threads the feed leaves out, which the "N more" row counts.
|
||||
var moreRecent: Int { max(0, recentTotal - recent.count) }
|
||||
}
|
||||
|
||||
extension Feed {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case needsYou, working, recent, recentTotal, hosts
|
||||
}
|
||||
|
||||
/// `recentTotal` is newer than the rest, so a gateway that leaves it out has nothing past `recent`.
|
||||
init(from decoder: any Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.init(
|
||||
needsYou: try container.decode([FeedItem].self, forKey: .needsYou),
|
||||
working: try container.decode([FeedItem].self, forKey: .working),
|
||||
recent: try container.decode([FeedItem].self, forKey: .recent),
|
||||
recentTotal: try container.decodeIfPresent(Int.self, forKey: .recentTotal),
|
||||
hosts: try container.decode([HostSummary].self, forKey: .hosts))
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET /v1/recent`: every unsettled finished thread, newest first. Older ones may lack `lastMessage`.
|
||||
struct RecentResponse: Codable, Hashable, Sendable {
|
||||
var items: [FeedItem]
|
||||
}
|
||||
|
||||
/// `POST /v1/recent/settle`. `failed` counts threads T3 refused or whose host was offline.
|
||||
struct SettleRecentResponse: Codable, Hashable, Sendable {
|
||||
var settled: Int
|
||||
var failed: Int
|
||||
}
|
||||
|
||||
/// `GET /v1/summary`: the counts behind the complication.
|
||||
|
||||
Reference in new issue
Block a user