mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
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.
This commit is contained in:
@@ -322,6 +322,7 @@ public enum MessageWindowLogic {
|
||||
oldest = responseOldest ?? previous.oldestPosition
|
||||
}
|
||||
var next = settingMessages(previous, trim.kept)
|
||||
next.readThroughRevision = max(previous.readThroughRevision ?? 0, page.readThroughRevision ?? 0, trim.kept.compactMap(\.contentRevision).max() ?? 0)
|
||||
next.hasMore = page.hasMore || (!replaceServerRows && previous.hasMore) || !trim.dropped.isEmpty
|
||||
next.epoch = page.epoch
|
||||
next.oldestPosition = oldest
|
||||
@@ -379,6 +380,7 @@ public enum MessageWindowLogic {
|
||||
return merged
|
||||
}
|
||||
merged.epoch = page.epoch
|
||||
merged.readThroughRevision = max(merged.readThroughRevision ?? 0, page.readThroughRevision ?? 0, merged.messages.compactMap(\.contentRevision).max() ?? 0)
|
||||
merged.newestPosition = maxPosition(nextAfter, merged.newestPosition)
|
||||
merged.warning = nil
|
||||
return merged
|
||||
@@ -581,6 +583,9 @@ public enum MessageWindowLogic {
|
||||
if merged.epoch == nil || merged.requiresLatestReset {
|
||||
return merged
|
||||
}
|
||||
if let revision = merged.readThroughRevision {
|
||||
merged.readThroughRevision = max(revision, incoming.compactMap(\.contentRevision).max() ?? 0)
|
||||
}
|
||||
let incomingNewest = derivePosition(incoming, .newest)
|
||||
let currentNewest = merged.newestPosition
|
||||
if let incomingNewest, currentNewest == nil || incomingNewest > currentNewest! {
|
||||
@@ -802,7 +807,11 @@ public enum MessageWindowLogic {
|
||||
source: MessageWindowState,
|
||||
target: MessageWindowState
|
||||
) -> MessageWindowState {
|
||||
var next = settingMessages(createState(sessionId: target.sessionId), source.messages)
|
||||
var next = settingMessages(createState(sessionId: target.sessionId), source.messages.map { message in
|
||||
WindowMessage(id: message.id, seq: message.seq, localId: message.localId, content: message.content,
|
||||
createdAt: message.createdAt, invokedAt: message.invokedAt,
|
||||
scheduledAt: message.scheduledAt, status: message.status)
|
||||
})
|
||||
next.hasMore = source.hasMore
|
||||
next.tailRevision = source.tailRevision
|
||||
next.oldestPosition = source.oldestPosition
|
||||
|
||||
Reference in New Issue
Block a user