Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/SessionShare.swift
T
wushenghuaandHAPI 19b2435ea8 feat(ios): H5-style session rows and fix stuck queued actions
Session rows now match the web sidebar: the second line shows the last
two path components, active shares get a "Shared" pill, relative ages
read like the H5 list (now, 5 min ago, 10 hours ago, 2 days ago, then a
date), and the list font scale reaches 60%.

The running spinner is drawn from a timeline instead of ProgressView:
UIKit-backed spinners stop animating when a List cell is reconfigured,
which read as a spinner that often failed. Working rows also keep their
spinner while a pending approval is shown, as on web.

Queued-message actions no longer look dead. Cancelling a row the hub
reports as `busy` because it is already indeterminate used to restore
the row unchanged; it now keeps a `queueDismissed` hold (web #1839), so
Cancel and Retry take effect while the durable record stays available
for a late consume. Steer is hidden for flavors that cannot take it
(agy needs acp, cursor needs acp) via a port of the web steering gate.

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

Co-Authored-By: HAPI <noreply@hapi.run>
2026-12-05 12:11:13 +08:00

84 lines
2.7 KiB
Swift

import Foundation
/// An active public share for one session (`SessionShare`,
/// `shared/src/apiTypes.ts`). The access code is never returned by list/get
/// endpoints — only when the share is created or regenerated.
public struct SessionShare: Codable, Equatable, Sendable, Identifiable {
public var id: String
public var sessionId: String
public var shareToken: String
public var createdAt: Int
public var updatedAt: Int
public init(
id: String,
sessionId: String,
shareToken: String,
createdAt: Int,
updatedAt: Int
) {
self.id = id
self.sessionId = sessionId
self.shareToken = shareToken
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
/// `POST /api/session-shares` — the raw access code is shown exactly once.
public struct SessionShareCreateResponse: Codable, Equatable, Sendable {
public var share: SessionShare
public var accessCode: String
public init(share: SessionShare, accessCode: String) {
self.share = share
self.accessCode = accessCode
}
}
/// `GET /api/session-shares/session/:id` (null when no share is active).
public struct SessionShareEnvelope: Codable, Equatable, Sendable {
public var share: SessionShare?
public init(share: SessionShare?) {
self.share = share
}
}
/// One entry of `GET /api/session-shares`. The hub also returns the session
/// summary; the list only needs the share's session id, so the extra field is
/// deliberately not decoded.
public struct SessionShareListEntry: Codable, Equatable, Sendable {
public var share: SessionShare
public init(share: SessionShare) {
self.share = share
}
}
/// `GET /api/session-shares` — every active share in the namespace.
public struct SessionShareListResponse: Codable, Equatable, Sendable {
public var shares: [SessionShareListEntry]
public init(shares: [SessionShareListEntry]) {
self.shares = shares
}
}
/// The browser-facing share URL: the hub origin plus the web app's
/// `/shared-session/<token>` route (web `buildSessionShareUrl`). A native
/// client has no PWA origin of its own, so the hub origin is the share host.
public enum SessionShareLink {
public static func url(baseURL: URL, shareToken: String) -> URL? {
guard let scheme = baseURL.scheme, let host = baseURL.host else { return nil }
let token = shareToken.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
?? shareToken
var components = URLComponents()
components.scheme = scheme
components.host = host
components.port = baseURL.port
components.path = "/shared-session/\(token)"
return components.url
}
}