Watch: review fixes for action errors that vanished, feed refreshes dropped or overwritten around a change, a fresh thread screen per route, errors cleared on sign out, notification actions only while paired, cache writes off the main thread and capped at 30 threads, Ask before acting and Load earlier races, two-letter search, C# headings, and strictly encoded query values
This commit is contained in:
1 parent
99b300855e
commit
25be69fa30
14 files changed
+591
-94
No files matched your search
@@ -177,17 +177,15 @@ final class NotificationHandler: NSObject, UNUserNotificationCenterDelegate {
|
||||
await model.refreshFeed()
|
||||
return
|
||||
case .respond, .answer:
|
||||
guard model.mode != .unpaired, let response = command.response else { return }
|
||||
guard let response = command.response else { return }
|
||||
await attempt("Couldn't answer") {
|
||||
try await model.api.respond(hostId: response.hostId, threadId: response.threadId, request: response.request)
|
||||
}
|
||||
case let .reply(hostId, threadId, text):
|
||||
guard model.mode != .unpaired else { return }
|
||||
await attempt("Couldn't send your reply") {
|
||||
try await model.api.sendMessage(hostId: hostId, threadId: threadId, text: text)
|
||||
}
|
||||
case let .settle(hostId, threadId):
|
||||
guard model.mode != .unpaired else { return }
|
||||
await attempt("Couldn't settle") {
|
||||
try await model.api.settle(hostId: hostId, threadId: threadId)
|
||||
}
|
||||
@@ -197,21 +195,31 @@ final class NotificationHandler: NSObject, UNUserNotificationCenterDelegate {
|
||||
}
|
||||
|
||||
/// Runs a background action. If it fails, says so with a local notification, since nothing is
|
||||
/// on screen.
|
||||
/// on screen. Only a paired watch acts: after unpairing, or in demo mode, the action would go
|
||||
/// nowhere or to the demo gateway, so the notification says the watch is not paired instead.
|
||||
private func attempt(_ title: String, _ action: () async throws -> Void) async {
|
||||
guard AppModel.shared.isPaired else {
|
||||
await notify(title, "This watch isn't paired. Open WristCode to pair it.")
|
||||
return
|
||||
}
|
||||
AppModel.shared.beginChange()
|
||||
do {
|
||||
try await action()
|
||||
} catch let error as GatewayError where error.isStale {
|
||||
return
|
||||
} catch {
|
||||
guard let message = AppModel.shared.message(for: error) else { return }
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
content.body = message
|
||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||
try? await UNUserNotificationCenter.current().add(request)
|
||||
await notify(title, message)
|
||||
}
|
||||
}
|
||||
|
||||
private func notify(_ title: String, _ body: String) async {
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
content.body = body
|
||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||
try? await UNUserNotificationCenter.current().add(request)
|
||||
}
|
||||
}
|
||||
|
||||
/// The long look for `input` pushes. It shows the push's title and question, and sets the push's
|
||||
|
||||
Reference in new issue
Block a user