mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-07 01:21:37 +00:00
Track readable content revisions and durable read cursors in the hub. Acknowledge only rendered foreground tails, persist offline read operations, and preserve newer manual unread choices across devices. Migrate existing history to a read baseline and cover pagination receipts with shared native conformance fixtures.
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
public struct SessionReadState: Codable, Equatable, Sendable {
|
|
public var readRevision: Int
|
|
public var manualUnread: Bool
|
|
public var version: Int
|
|
|
|
public init(readRevision: Int = 0, manualUnread: Bool = false, version: Int = 0) {
|
|
self.readRevision = readRevision
|
|
self.manualUnread = manualUnread
|
|
self.version = version
|
|
}
|
|
|
|
public static func merge(_ current: Self?, _ incoming: Self?) -> Self? {
|
|
guard let incoming else { return current }
|
|
guard let current else { return incoming }
|
|
var next = incoming.version > current.version ? incoming : current
|
|
next.readRevision = max(current.readRevision, incoming.readRevision)
|
|
return next
|
|
}
|
|
}
|
|
|
|
public struct SessionReadStateRequest: Codable, Equatable, Sendable {
|
|
public var type: String
|
|
public var readRevision: Int?
|
|
public var expectedVersion: Int
|
|
|
|
public init(type: String = "read", readRevision: Int? = nil, expectedVersion: Int) {
|
|
self.type = type
|
|
self.readRevision = readRevision
|
|
self.expectedVersion = expectedVersion
|
|
}
|
|
}
|
|
|
|
public struct SessionReadStateResponse: Codable, Equatable, Sendable {
|
|
public var readState: SessionReadState
|
|
public var contentRevision: Int
|
|
}
|