Skip to content

feat: auto-refresh of recently played history#1123

Merged
simon-the-shark merged 3 commits intomainfrom
auto-refresh
Mar 29, 2026
Merged

feat: auto-refresh of recently played history#1123
simon-the-shark merged 3 commits intomainfrom
auto-refresh

Conversation

@MarmoPL
Copy link
Copy Markdown
Member

@MarmoPL MarmoPL commented Mar 27, 2026

I've made it to auto-refresh whenever new song appears on currently playing + fallback every 60 seconds. Why? Becuase as for my findings the recently played list does not have the newly played song as fast as the currently played endpoint so it wouldnt update until next new song is played. I think this is a good middle-ground

This change also adresses what greptile told was wrong in the other branch

@MarmoPL MarmoPL requested a review from simon-the-shark March 27, 2026 15:59
@MarmoPL MarmoPL self-assigned this Mar 27, 2026
@MarmoPL MarmoPL linked an issue Mar 27, 2026 that may be closed by this pull request
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR implements automatic refresh of the recently-played history list in the Radio LUZ feature. It wires up a StreamController in RadioAudioHandlerBridge to emit events when the now-playing track title changes, exposes that stream via a new radioTrackChangedProvider, and has historyEntryRepository listen to it so the cache is invalidated whenever a new song is detected. A 60-second periodic fallback refresh is added as well. Finally, a RefreshIndicator is wrapped around the main ListView to give users a manual pull-to-refresh gesture.\n\nKey changes:\n- radio_audio_handler.dart — adds a broadcast StreamController<String> (_trackChangedController) with an isClosed guard (addressing the previously reported race condition) to emit when the track title transitions.\n- history_entry_repository.dart — registers a 60 s periodic timer via setRefresh and a ref.listen on radioTrackChangedProvider to call invalidateSelf() on track changes.\n- radio_luz_view.dart — wraps the content ListView in a RefreshIndicator that awaits historyEntryRepositoryProvider.future on pull.

Confidence Score: 4/5

Safe to merge with awareness of one minor redundant network request on startup; no correctness or data-loss issues

The previously reported race condition is correctly addressed with the isClosed guard. The Riverpod patterns used (ref.listen + invalidateSelf inside an async provider, setRefresh) are idiomatic and sound. The only remaining issue is that _lastTrackTitle initialising to null causes one spurious track-changed event ~15 s after the page loads, triggering an unnecessary extra history fetch per session. This is a P2 concern — it wastes one network call at startup but does not break any user-facing behaviour or produce incorrect data.

lib/features/radio_luz/service/radio_audio_handler.dart — the _lastTrackTitle initialisation

Important Files Changed

Filename Overview
lib/features/radio_luz/service/radio_audio_handler.dart Adds a broadcast StreamController to emit track-change events; addresses prior race condition with an isClosed guard; _lastTrackTitle starts null, causing the first fetch to always emit a spurious change event
lib/features/radio_luz/data/repository/history_entry_repository.dart Adds a 60-second periodic auto-refresh via setRefresh and a ref.listen on radioTrackChangedProvider to invalidate the history cache on track changes; valid Riverpod pattern
lib/features/radio_luz/presentation/radio_luz_view.dart Wraps the ListView in a RefreshIndicator that awaits historyEntryRepositoryProvider.future on pull-to-refresh; clean addition with no structural issues

Sequence Diagram

sequenceDiagram
    participant UI as RadioLuzView
    participant HR as historyEntryRepository
    participant TCP as radioTrackChangedProvider
    participant RA as RadioAudioHandlerBridge
    participant API as Radio LUZ API

    UI->>HR: watch (page open, t=0)
    HR->>API: getRecentlyPlayed()
    API-->>HR: history list
    HR-->>UI: IList<HistoryEntry>

    Note over HR: setRefresh(60s) timer started
    Note over HR: ref.listen(radioTrackChangedProvider) set up

    loop Every 15 s
        RA->>API: getNowPlaying()
        API-->>RA: nowPlaying
        alt track title changed
            RA->>TCP: trackChanged.add(title)
            TCP-->>HR: AsyncValue<String> (hasValue)
            HR->>HR: invalidateSelf()
            HR->>API: getRecentlyPlayed()
            API-->>HR: updated history
            HR-->>UI: IList<HistoryEntry> (refreshed)
        end
    end

    Note over HR: Fallback: 60 s timer fires invalidateSelf()

    UI->>HR: pull-to-refresh → ref.refresh(future)
    HR->>API: getRecentlyPlayed()
    API-->>HR: history list
    HR-->>UI: IList<HistoryEntry>
Loading

Reviews (2): Last reviewed commit: "fix: greptile changes" | Re-trigger Greptile

@simon-the-shark simon-the-shark merged commit 4cb2d6a into main Mar 29, 2026
8 checks passed
@simon-the-shark simon-the-shark deleted the auto-refresh branch March 29, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(radio-luz): "now playing" list does not refresh

2 participants