Herz-Tipp meldet den Favoriten sofort deterministisch an die Cloud
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../services/melo_cloud_service.dart';
|
||||
import '../services/navidrome_service.dart';
|
||||
import 'database.dart';
|
||||
|
||||
@@ -6,11 +7,18 @@ import 'database.dart';
|
||||
/// nach jeder Mutation (für Feedback wie SnackBars — die Listen selbst
|
||||
/// beobachten UIs direkt über die watch()-Streams von [MeloDb]).
|
||||
class PlaylistService extends ChangeNotifier {
|
||||
PlaylistService(this.db, {NavidromeService? navidrome})
|
||||
: _navidrome = navidrome ?? NavidromeService();
|
||||
// `this._cloud` würde den öffentlichen Parameternamen `cloud` zu `_cloud`
|
||||
// (privat) ändern und die API brechen.
|
||||
PlaylistService(this.db, {NavidromeService? navidrome, MeloCloudService? cloud})
|
||||
: _navidrome = navidrome ?? NavidromeService(),
|
||||
// ignore: prefer_initializing_formals
|
||||
_cloud = cloud;
|
||||
final MeloDb db;
|
||||
final NavidromeService _navidrome;
|
||||
|
||||
/// Optional: ohne Cloud-Zugang entfällt der Sofort-Push stillschweigend.
|
||||
final MeloCloudService? _cloud;
|
||||
|
||||
Future<String> createPlaylist(String name, {String? description}) async {
|
||||
final id = await db.createPlaylist(name, description: description);
|
||||
notifyListeners();
|
||||
@@ -45,6 +53,26 @@ class PlaylistService extends ChangeNotifier {
|
||||
Future<void> toggleFavorite(String songId) async {
|
||||
await db.toggleFavorite(songId);
|
||||
notifyListeners();
|
||||
await _meldeFavorit(songId);
|
||||
}
|
||||
|
||||
/// Meldet den neuen Favoriten-Stand sofort an die Melo-Cloud.
|
||||
///
|
||||
/// Deterministisch (`set:true/false`), nicht als Umschalten: ein
|
||||
/// abweichender Server-Stand darf den Wunsch nicht invertieren. Nur für
|
||||
/// Titel mit cloudId, und Fehler werden still geschluckt — der nächste
|
||||
/// Abgleich pusht additiv nach.
|
||||
Future<void> _meldeFavorit(String songId) async {
|
||||
final cloud = _cloud;
|
||||
if (cloud == null || !cloud.istAngemeldet) return;
|
||||
final cloudId = (await db.songById(songId))?.cloudId;
|
||||
if (cloudId == null) return;
|
||||
final gesetzt = await db.watchIsFavorite(songId).first;
|
||||
try {
|
||||
await cloud.setzeFavorit(cloudId, gesetzt);
|
||||
} catch (e) {
|
||||
debugPrint('Favorit nicht gemeldet: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Lädt alle Favoriten vom Navidrome-Server und importiert sie lokal.
|
||||
|
||||
Reference in New Issue
Block a user