Skip to content

[codex] Use catalog API for iOS history - #18

Merged
Quick104 merged 2 commits into
mainfrom
codex/history-catalog-api
Jun 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
codex/history-catalog-api

Conversation

@Quick104

@Quick104 Quick104 commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Route the iOS History screen through the catalog history source instead of the legacy personal history endpoint.
  • Page results with limit, offset, and catalog snapshots so the full watch history loads while scrolling.
  • Show the exact catalog total when available while preserving the cached first page behavior.

Validation

  • Regenerated the Xcode project with XcodeGen.
  • Built the Silo iOS scheme for an iOS simulator with code signing disabled.
  • Ran git diff --check.

Summary by CodeRabbit

  • New Features
    • Added paginated loading for watch history, with seamless “load more” as users scroll.
    • Improved history count display to reflect exact totals when available (and “+” lower-bound counts when not).
    • Added more responsive loading, empty, and error states, including pull-to-refresh and retry behavior.
  • Refactor
    • Streamlined history screen logic by moving state management and paging behavior into a dedicated view model.

@Quick104
Quick104 marked this pull request as ready for review June 23, 2026 19:51
@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new historyCatalog method is added to ContinuumAPI to query the catalog endpoint with source=history and pagination parameters. HistoryViewModel manages pagination state, cache restoration on reset, snapshot pinning for consistent paging, and a computed countLabel. HistoryView is refactored to delegate state to the view model and display a CatalogGrid with load-more support instead of a LazyVGrid.

Changes

Paginated Watch History

Layer / File(s) Summary
historyCatalog API method
iosApp/iosApp/Networking/ContinuumAPI.swift
Adds historyCatalog(offset:limit:snapshot:includeTotal:) that builds a /api/v1/catalog query with source=history, optional snapshot, and conditional include_total, delegating to catalog(query:).
HistoryViewModel pagination and state management
iosApp/iosApp/Screens/Personal/HistoryViewModel.swift
New @Observable @MainActor view model managing items, isLoading, error, hasMore, totalItems, and countLabel. Implements load(reset:) to restore cached first page on reset, pin snapshots for consistent paging, advance cursors on subsequent pages, and surface errors only when content is empty. Computes countLabel to display exact totals or lower-bound "+" counts when more pages remain.
HistoryView delegation and UI wiring
iosApp/iosApp/Screens/Personal/HistoryView.swift
Replaces local @State fields (items, isLoading, error) with a @State viewModel. Updates empty/error/loading branches to use viewModel properties. Replaces LazyVGrid-based gridContent with ScrollView + CatalogGrid wired to viewModel.items, viewModel.isLoading, viewModel.hasMore, and onLoadMore calling viewModel.load(reset: false). Updates .task and .refreshable to call viewModel.load(reset: true).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Use catalog API for iOS history' clearly and concisely identifies the main change: adopting the catalog API for the iOS history feature instead of the legacy endpoint.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/history-catalog-api

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/Screens/Personal/HistoryView.swift`:
- Around line 98-101: The totalItems property is not being cleared when
response.totalExact is false, causing the countLabel to display stale data from
previous responses. In the conditional block where response.totalExact == false
is checked (around line 122), add a line to reset totalItems to nil alongside
the other state resets like hasMore, nextOffset, and snapshot. This ensures that
when the total count is not exact, the old exact total value is cleared and
won't be displayed in the countLabel after refresh or pagination state changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fcbc0b0d-9379-4be2-9a7e-67c78d655e21

📥 Commits

Reviewing files that changed from the base of the PR and between 7c75c2a and 21e7568.

📒 Files selected for processing (2)
  • iosApp/iosApp/Networking/ContinuumAPI.swift
  • iosApp/iosApp/Screens/Personal/HistoryView.swift

Move the History screen's loading/paging logic out of the view into an @observable HistoryViewModel, matching the BrowseViewModel pattern.

- Defer the paging-cursor reset until a refresh succeeds: a failed pull-to-refresh previously zeroed the offset/snapshot while keeping the stale list, so the next load-more re-fetched and duplicated page 1. The cursor is now committed only on success, and kept intact on error so load-more resumes correctly.

- Collapse the item-count label into a single readable expression.

Built Silo (iOS) and SiloTV (tvOS) schemes with code signing disabled.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/Screens/Personal/HistoryViewModel.swift`:
- Around line 97-100: In the advanceCursor method, the condition checking
response.totalExact is incorrectly using `!= false` which evaluates to true when
totalExact is nil, causing omitted counts from load-more responses to overwrite
previously-known exact totals. Change the condition from `response.totalExact !=
false` to `response.totalExact == true` to only update the totalItems when the
server explicitly confirms exactness.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c4f6f4e-d2aa-4164-b7a6-d943ac1b7fea

📥 Commits

Reviewing files that changed from the base of the PR and between 21e7568 and 9d3c757.

📒 Files selected for processing (2)
  • iosApp/iosApp/Screens/Personal/HistoryView.swift
  • iosApp/iosApp/Screens/Personal/HistoryViewModel.swift

Comment on lines +97 to +100
private func advanceCursor(with response: CatalogResponse, from requestOffset: Int) {
if response.totalExact != false {
totalItems = response.total
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n iosApp/iosApp/Screens/Personal/HistoryViewModel.swift | head -120 | tail -40

Repository: Silo-Server/silo-apple

Length of output: 2035


🏁 Script executed:

find . -type f -name "*.swift" | xargs grep -l "CatalogResponse" | head -5

Repository: Silo-Server/silo-apple

Length of output: 420


🏁 Script executed:

grep -A 10 "struct CatalogResponse" iosApp/iosApp/Networking/Models.swift

Repository: Silo-Server/silo-apple

Length of output: 470


🏁 Script executed:

grep -B 5 -A 15 "var totalExact" iosApp/iosApp/Networking/Models.swift

Repository: Silo-Server/silo-apple

Length of output: 160


Change condition to check explicitly for true to avoid overwriting exact totals with omitted values.

In advanceCursor, the condition response.totalExact != false evaluates to true when totalExact is nil, causing Line 99 to overwrite a previously-known exact total with a placeholder from load-more responses that omit the count. Per the method's intent (documented in the comment), omitted counts should not disturb a pinned exact total. Change the condition to response.totalExact == true to only update when the server explicitly confirms exactness.

Suggested fix
 private func advanceCursor(with response: CatalogResponse, from requestOffset: Int) {
-    if response.totalExact != false {
+    if response.totalExact == true {
         totalItems = response.total
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private func advanceCursor(with response: CatalogResponse, from requestOffset: Int) {
if response.totalExact != false {
totalItems = response.total
}
private func advanceCursor(with response: CatalogResponse, from requestOffset: Int) {
if response.totalExact == true {
totalItems = response.total
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Screens/Personal/HistoryViewModel.swift` around lines 97 - 100,
In the advanceCursor method, the condition checking response.totalExact is
incorrectly using `!= false` which evaluates to true when totalExact is nil,
causing omitted counts from load-more responses to overwrite previously-known
exact totals. Change the condition from `response.totalExact != false` to
`response.totalExact == true` to only update the totalItems when the server
explicitly confirms exactness.

@Quick104
Quick104 merged commit 278c5dc into main Jun 23, 2026
1 check passed
@Quick104
Quick104 deleted the codex/history-catalog-api branch June 23, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant