iOS app asks ipx in protobuf, not JSON (#469)

The badge's and CarPlay's reads (/api/feeds, the entry lists) and the
player's writes (position, flags) now go as application/x-protobuf, the
messages generated from crates/wire/proto by ios/scripts/proto.sh into
Sources/Wire, committed so the build needs no protoc. SwiftProtobuf is
pinned to the generator's version, 1.41.0, whose code refuses another.

A read whose answer is not protobuf counts as no answer: a server from
before #465 answers JSON whatever it is asked, and JSON can decode as a
message of nothing, which would have set the badge to zero.

The outbox keeps its stored key, `json`, for the body, and marks the
new writes protobuf, so places saved offline by an older build are
still sent, as JSON.

Built for the simulator with Xcode 27.2; not run against a server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ray Slakinski
2026-11-16 19:00:10 -05:00
parent a96be2f14c
commit baa6661622
13 changed files with 6118 additions and 51 deletions

View File

@@ -11,22 +11,13 @@ import UserNotifications
enum Badge {
static let taskId = "net.sdf1.ipx.refresh"
private struct Row: Decodable {
let id: String
let group: String?
let unread: Int?
let hide_from_all: Bool?
}
/// web/src/feeds.ts `unreadInAll`: a feed counts unless it, or the OPML it came from, is
/// hidden from All Subscriptions. Nil when the body is not a feed list, so an error page
/// does not turn the badge to zero.
static func unread(inAll body: Data) -> Int? {
guard let rows = try? JSONDecoder().decode([Row].self, from: body) else { return nil }
let hidden = Set(rows.filter { $0.hide_from_all == true }.map(\.id))
/// hidden from All Subscriptions.
static func unread(inAll rows: [Ipx_FeedRow]) -> Int {
let hidden = Set(rows.filter(\.hideFromAll).map(\.id))
return rows.reduce(0) { n, f in
if f.hide_from_all == true || f.group.map(hidden.contains) == true { return n }
return n + max(0, f.unread ?? 0)
if f.hideFromAll || (f.hasGroup && hidden.contains(f.group)) { return n }
return n + max(0, Int(f.unread))
}
}
@@ -69,10 +60,11 @@ enum Badge {
return true
}
/// All Subscriptions' unread count from ipx, or nil when it cannot be had.
/// All Subscriptions' unread count from ipx, or nil when it cannot be had: an answer that is
/// not a feed list leaves the badge as it was rather than turning it to zero.
static func fetch() async -> Int? {
guard let data = await API.get("/api/feeds") else { return nil }
return unread(inAll: data)
guard let feeds = await API.get(Ipx_FeedRows.self, "/api/feeds") else { return nil }
return unread(inAll: feeds.items)
}
// MARK: - while the app is closed