feat(ios): jump notifications and session rows to the pending request

Complete the pending-request center's entry points:

- Push payloads already carry the request id for permission and input
  pushes; the notification tap now passes it through AppModel into the
  home screen instead of only the session id.
- Opening a session row whose summary still has pending requests lands on
  the first wait (async questions first, since they live in the collapsible
  bottom panel; approvals scroll to their tool row).
- ChatModel queues the jump until the detail's request dictionary arrives,
  so a cold notification start does not drop the target and a blocking
  target waits for the transcript to settle before scrolling.
- A focus token lets the split detail re-fire for the session that is
  already open.

Routing and pending-target presentation tests cover the new request id.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-12-01 06:47:01 +08:00
co-authored by HAPI Claude Code
parent a2f7b30ddd
commit d0b0fde6cb
9 changed files with 194 additions and 26 deletions
+17 -3
View File
@@ -49,6 +49,10 @@ final class AppModel {
/// navigation path against the active hub (switched to the owner first,
/// see ``openNotificationTarget(sessionId:hubUrl:)``).
var pendingOpenSessionId: String?
/// Specific pending request carried by the same notification tap
/// (`requestId`); nil for a plain ready/tap-to-open push, where the chat
/// opens at the first live request when the session has one.
var pendingOpenRequestId: String?
/// Incremented by `hapicompanion://sessions`; HomeView pops to the list.
private(set) var sessionListRequest = 0
@@ -97,8 +101,12 @@ final class AppModel {
activeHubKnowsSession: { [weak self] sessionId in
self?.session?.sessionStore.sessions.contains { $0.id == sessionId } ?? false
},
openSession: { [weak self] sessionId, hubUrl in
self?.openNotificationTarget(sessionId: sessionId, hubUrl: hubUrl)
openSession: { [weak self] sessionId, hubUrl, requestId in
self?.openNotificationTarget(
sessionId: sessionId,
hubUrl: hubUrl,
requestId: requestId
)
}
))
}
@@ -197,10 +205,15 @@ final class AppModel {
/// Notification tap: a located owning hub becomes active first, so the
/// new home screen consumes the target (`HomeView` is keyed by hub).
func openNotificationTarget(sessionId: String, hubUrl: String?) {
func openNotificationTarget(
sessionId: String,
hubUrl: String?,
requestId: String? = nil
) {
if let hubUrl, registry.hubs.contains(hubUrl), hasCredentials(for: hubUrl) {
switchHub(to: hubUrl)
}
pendingOpenRequestId = requestId
pendingOpenSessionId = sessionId
}
@@ -249,6 +262,7 @@ final class AppModel {
/// hub instead of opening whichever session happened to be first.
func openSessionList() {
pendingOpenSessionId = nil
pendingOpenRequestId = nil
sessionListRequest += 1
}
+8 -5
View File
@@ -97,8 +97,9 @@ final class PushCoordinator: NSObject {
let activeHubKnowsSession: @MainActor (String) -> Bool
/// Tap-through navigation: switch to the owning hub when one was
/// located (nil = stay on the active hub), then stash the target
/// session for the home screen (Android `pendingOpenSessionId`).
let openSession: @MainActor (_ sessionId: String, _ hubUrl: String?) -> Void
/// session (and the exact pending request, when the push names one)
/// for the home screen (Android `pendingOpenSessionId`).
let openSession: @MainActor (_ sessionId: String, _ hubUrl: String?, _ requestId: String?) -> Void
}
// MARK: - Observable state (Settings row)
@@ -375,7 +376,9 @@ extension PushCoordinator: UNUserNotificationCenterDelegate {
}
switch response.actionIdentifier {
case UNNotificationDefaultActionIdentifier:
await openSession(payload.sessionId)
// Permission and input pushes both carry the request id; a plain
// ready push has none and the chat falls back to its first wait.
await openSession(payload.sessionId, requestId: payload.requestId)
case ActionID.allow:
guard payload.type == .permissionRequest, payload.supportsActions,
let requestId = payload.requestId else { return }
@@ -412,14 +415,14 @@ extension PushCoordinator: UNUserNotificationCenterDelegate {
/// a session the active list does not know is located first (active hub
/// first, like the actions). A miss or an unreachable owner falls back
/// to the active hub.
private func openSession(_ sessionId: String) async {
private func openSession(_ sessionId: String, requestId: String?) async {
guard let environment else { return }
var owner: String?
if hubsActiveFirst().count > 1, !environment.activeHubKnowsSession(sessionId),
case .success(let hubUrl) = await actionRunner().locate(sessionId: sessionId) {
owner = hubUrl
}
environment.openSession(sessionId, owner)
environment.openSession(sessionId, owner, requestId)
}
private func actionRunner() -> PushActionRunner {