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:
@@ -7,14 +7,22 @@ import UIKit
|
||||
// does. Now Playing is the system's, fed by Playback's now-playing info and remote commands.
|
||||
|
||||
/// An item as a car's list needs it: db.rs EntryRow, the fields used.
|
||||
struct CarEpisode: Decodable {
|
||||
struct Enclosure: Decodable {
|
||||
struct CarEpisode {
|
||||
struct Enclosure {
|
||||
let id: Int
|
||||
let url: String
|
||||
let mime: String?
|
||||
let deadair: Double?
|
||||
/// Set once ipx has the file; `/media/{id}` answers 404 before that.
|
||||
let path: String?
|
||||
|
||||
init(_ e: Ipx_EncRow) {
|
||||
id = Int(e.id)
|
||||
url = e.url
|
||||
mime = e.hasMime ? e.mime : nil
|
||||
deadair = e.hasDeadair ? Double(e.deadair) : nil
|
||||
path = e.hasPath ? e.path : nil
|
||||
}
|
||||
}
|
||||
|
||||
let guid: String
|
||||
@@ -25,6 +33,16 @@ struct CarEpisode: Decodable {
|
||||
let position: Double
|
||||
let enclosures: [Enclosure]
|
||||
|
||||
init(_ e: Ipx_EntryRow) {
|
||||
guid = e.guid
|
||||
feed_id = e.feedID
|
||||
title = e.hasTitle ? e.title : nil
|
||||
image = e.hasImage ? e.image : nil
|
||||
duration = e.hasDuration ? Double(e.duration) : nil
|
||||
position = Double(e.position)
|
||||
enclosures = e.enclosures.map(Enclosure.init)
|
||||
}
|
||||
|
||||
/// The file to play: the first downloaded one that is sound (items.ts isPlayable, less video,
|
||||
/// which a car would play the sound of with nothing to say so). An item with none is not listed
|
||||
/// (#443): a post's picture or a file still to come is nothing a car can play.
|
||||
@@ -69,7 +87,7 @@ struct CarEpisode: Decodable {
|
||||
}
|
||||
|
||||
/// A subscription, from `/api/feeds`.
|
||||
struct CarFeed: Decodable {
|
||||
struct CarFeed {
|
||||
let id: String
|
||||
let title: String?
|
||||
let image: String?
|
||||
@@ -80,10 +98,16 @@ struct CarFeed: Decodable {
|
||||
let group: String?
|
||||
|
||||
var name: String { title ?? id }
|
||||
}
|
||||
|
||||
private struct CarPage: Decodable {
|
||||
let entries: [CarEpisode]
|
||||
init(_ f: Ipx_FeedRow) {
|
||||
id = f.id
|
||||
title = f.hasTitle ? f.title : nil
|
||||
image = f.hasImage ? f.image : nil
|
||||
unread = Int(f.unread)
|
||||
entries = Int(f.entries)
|
||||
downloaded = Int(f.downloaded)
|
||||
group = f.hasGroup ? f.group : nil
|
||||
}
|
||||
}
|
||||
|
||||
final class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
|
||||
@@ -143,19 +167,18 @@ final class CarScreen: NSObject, CPTabBarTemplateDelegate {
|
||||
}
|
||||
|
||||
private func loadFeeds() async {
|
||||
guard let data = await API.get("/api/feeds"),
|
||||
let rows = try? JSONDecoder().decode([CarFeed].self, from: data) else { return }
|
||||
guard let rows = await API.get(Ipx_FeedRows.self, "/api/feeds")?.items.map(CarFeed.init) else { return }
|
||||
feeds = Dictionary(rows.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a })
|
||||
}
|
||||
|
||||
private func episodes(in list: CPListTemplate, from path: String, empty: String, oneFeed: Bool = false) async {
|
||||
guard let data = await API.get(path), let page = try? JSONDecoder().decode(CarPage.self, from: data) else {
|
||||
guard let page = await API.get(Ipx_EntryPage.self, path) else {
|
||||
unreachable(list)
|
||||
return
|
||||
}
|
||||
let kept = Set(Offline.shared.store.paths)
|
||||
let playing = Playback.shared.current
|
||||
let rows: [CPListItem] = page.entries.compactMap { e in
|
||||
let rows: [CPListItem] = page.entries.map(CarEpisode.init).compactMap { e in
|
||||
let feed = feeds[e.feed_id]
|
||||
guard let item = e.item(feedTitle: feed?.name ?? e.feed_id, feedImage: feed?.image, kept: kept) else {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user