Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/SessionReadState.swift
T
weishu 5ef4304a4a fix: synchronize read state across web and native clients
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.
2026-11-01 09:52:51 +08:00

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
}