Trakt was the one service outside the tracker abstraction. TraktScrobbleService re-implemented the whole playback lifecycle beside TrackerCoordinator, and TraktSyncService pushed watched state from its own WatchStateNotifier subscription, so the player called two objects at every lifecycle point and one watch could be written twice. TraktTracker now implements RealtimeScrobbleTracker like Simkl; the duplicated player call sites collapse to one each, and Trakt shares the coordinator's ID resolver instead of re-fetching show ids every episode. Capabilities are split so a tracker declares what it is rather than being special-cased: ScrobblePolicy carries each service's own resend/seek rules, EpisodeHistoryTracker names the remote row a per-item history write targets, and SeriesProgressTracker covers one-counter-per-series services. Writes from all four trackers go through a shared TrackerWriteQueue, generalised from the Trakt-only queue, with the legacy Trakt payload migrated on load. Trakt becomes the fourth TrackersProvider slot and TraktAccountProvider is deleted, so one object owns the active session per profile. Two failure paths found while consolidating are fixed here too. The queue's retries only ran on profile bind, connect and app foreground, so a network blip mid-session left queued watches waiting for the next foreground. OfflineModeProvider now notifies on connectivity changes, not just offline-state or WiFi-flag changes, and main.dart flushes the queue when the network returns. The queue also counted every failure toward the five attempts that permanently drop an item, so a rate limit or a service having a bad hour could discard a pending watch - the loss the queue exists to prevent. Only an answer about the write itself now spends an attempt: 4xx counts, while rate limits, 5xx, recoverable token-refresh failures and requests that never arrived do not. A back-off answer also defers that service for the rest of the flush, so a queue holding many rows does not fire all of them at a service that just asked for quiet.
31 lines
1003 B
Dart
31 lines
1003 B
Dart
import 'fribb_mapping_row.dart';
|
|
|
|
/// External IDs for matching a Plex item to MAL / AniList / Simkl catalogs.
|
|
///
|
|
/// Populated from a [FribbMappingRow] via the resolver. Each service's tracker
|
|
/// picks the ID it needs (MAL uses [mal], AniList uses [anilist], etc.) and
|
|
/// no-ops when its ID is missing.
|
|
class AnimeIds {
|
|
final int? mal;
|
|
final int? anilist;
|
|
final int? simkl;
|
|
|
|
const AnimeIds({this.mal, this.anilist, this.simkl});
|
|
|
|
factory AnimeIds.fromFribb(FribbMappingRow row) =>
|
|
AnimeIds(mal: row.malId, anilist: row.anilistId, simkl: row.simklId);
|
|
|
|
/// Round-trips through the persisted tracker write queue.
|
|
Map<String, Object?> toJson() => {
|
|
if (mal != null) 'mal': mal,
|
|
if (anilist != null) 'anilist': anilist,
|
|
if (simkl != null) 'simkl': simkl,
|
|
};
|
|
|
|
factory AnimeIds.fromJson(Map<String, Object?> json) => AnimeIds(
|
|
mal: (json['mal'] as num?)?.toInt(),
|
|
anilist: (json['anilist'] as num?)?.toInt(),
|
|
simkl: (json['simkl'] as num?)?.toInt(),
|
|
);
|
|
}
|