Watch: treat an empty threadId in a push as no thread
The gateway sends threadId "" on host notifications; tapping one now opens the feed instead of a thread that does not exist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9731fd621f
commit
7ad1045be4
2 files changed
+9
-3
No files matched your search
@@ -20,9 +20,13 @@ enum NotificationCommand: Equatable, Sendable {
|
||||
|
||||
/// `userInfo` holds the custom keys `hostId`, `threadId` and, for approvals, `requestId`.
|
||||
init(actionIdentifier: String, userInfo: [AnyHashable: Any], text: String?) {
|
||||
let hostId = userInfo["hostId"] as? String
|
||||
let threadId = userInfo["threadId"] as? String
|
||||
let requestId = userInfo["requestId"] as? String
|
||||
// The gateway sends `threadId: ""` on host notifications, so empty means absent.
|
||||
func value(_ key: String) -> String? {
|
||||
(userInfo[key] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
||||
}
|
||||
let hostId = value("hostId")
|
||||
let threadId = value("threadId")
|
||||
let requestId = value("requestId")
|
||||
let thread: Route? = if let hostId, let threadId { .thread(hostId: hostId, threadId: threadId) } else { nil }
|
||||
|
||||
switch actionIdentifier {
|
||||
|
||||
@@ -198,6 +198,8 @@ private let feedItemJSON = """
|
||||
// A host notification has no thread, so tapping it opens the feed.
|
||||
#expect(NotificationCommand(actionIdentifier: "com.apple.UNNotificationDefaultActionIdentifier", userInfo: [:], text: nil)
|
||||
== .open(nil))
|
||||
#expect(NotificationCommand(actionIdentifier: "com.apple.UNNotificationDefaultActionIdentifier", userInfo: ["hostId": "h", "threadId": ""], text: nil)
|
||||
== .open(nil))
|
||||
// Allow without a requestId cannot answer, so it opens the thread instead.
|
||||
#expect(NotificationCommand(actionIdentifier: "allow", userInfo: ["hostId": "h", "threadId": "t"], text: nil)
|
||||
== .open(.thread(hostId: "h", threadId: "t")))
|
||||
|
||||
Reference in new issue
Block a user