(
prev: InternalState,
updates: {
messages?: DecryptedMessage[]
pending?: DecryptedMessage[]
pendingOverflowCount?: number
pendingVisibleCount?: number
pendingOverflowVisibleCount?: number
hasMore?: boolean
oldestPositionAt?: number | null
oldestPositionSeq?: number | null
isLoading?: boolean
isLoadingMore?: boolean
warning?: string | null
atBottom?: boolean
}
)
| 529 | } |
| 530 | |
| 531 | function buildState( |
| 532 | prev: InternalState, |
| 533 | updates: { |
| 534 | messages?: DecryptedMessage[] |
| 535 | pending?: DecryptedMessage[] |
| 536 | pendingOverflowCount?: number |
| 537 | pendingVisibleCount?: number |
| 538 | pendingOverflowVisibleCount?: number |
| 539 | hasMore?: boolean |
| 540 | oldestPositionAt?: number | null |
| 541 | oldestPositionSeq?: number | null |
| 542 | isLoading?: boolean |
| 543 | isLoadingMore?: boolean |
| 544 | warning?: string | null |
| 545 | atBottom?: boolean |
| 546 | } |
| 547 | ): InternalState { |
| 548 | const messages = updates.messages ?? prev.messages |
| 549 | const pending = updates.pending ?? prev.pending |
| 550 | const pendingOverflowCount = updates.pendingOverflowCount ?? prev.pendingOverflowCount |
| 551 | const pendingOverflowVisibleCount = updates.pendingOverflowVisibleCount ?? prev.pendingOverflowVisibleCount |
| 552 | let pendingVisibleCount = updates.pendingVisibleCount ?? prev.pendingVisibleCount |
| 553 | const pendingChanged = pending !== prev.pending |
| 554 | if (pendingChanged && updates.pendingVisibleCount === undefined) { |
| 555 | pendingVisibleCount = countVisiblePendingMessages(prev.sessionId, pending) |
| 556 | } |
| 557 | if (pendingChanged) { |
| 558 | syncPendingVisibilityCache(prev.sessionId, pending) |
| 559 | } |
| 560 | const pendingCount = pendingVisibleCount + pendingOverflowVisibleCount |
| 561 | const { oldestSeq, newestSeq } = deriveSeqBounds(messages) |
| 562 | const messagesVersion = messages === prev.messages ? prev.messagesVersion : prev.messagesVersion + 1 |
| 563 | |
| 564 | return { |
| 565 | ...prev, |
| 566 | messages, |
| 567 | pending, |
| 568 | pendingOverflowCount, |
| 569 | pendingVisibleCount, |
| 570 | pendingOverflowVisibleCount, |
| 571 | pendingCount, |
| 572 | oldestSeq, |
| 573 | oldestPositionAt: updates.oldestPositionAt !== undefined ? updates.oldestPositionAt : prev.oldestPositionAt, |
| 574 | oldestPositionSeq: updates.oldestPositionSeq !== undefined ? updates.oldestPositionSeq : prev.oldestPositionSeq, |
| 575 | newestSeq, |
| 576 | hasMore: updates.hasMore !== undefined ? updates.hasMore : prev.hasMore, |
| 577 | isLoading: updates.isLoading !== undefined ? updates.isLoading : prev.isLoading, |
| 578 | isLoadingMore: updates.isLoadingMore !== undefined ? updates.isLoadingMore : prev.isLoadingMore, |
| 579 | warning: updates.warning !== undefined ? updates.warning : prev.warning, |
| 580 | atBottom: updates.atBottom !== undefined ? updates.atBottom : prev.atBottom, |
| 581 | messagesVersion, |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /** Trim `messages` down to `limit` while preserving every queued user message. |
| 586 | * Queued rows must survive trimming on both windows: the `messages-consumed` |
no test coverage detected