refactor: centralize globalKey construction via buildGlobalKey()
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import '../models/plex_metadata.dart';
|
||||
import 'app_logger.dart';
|
||||
import 'base_notifier.dart';
|
||||
import 'global_key_utils.dart';
|
||||
import 'hierarchical_event_mixin.dart';
|
||||
|
||||
/// Event representing a media item deletion with parent chain for hierarchical invalidation
|
||||
@@ -42,7 +43,7 @@ class DeletionEvent with HierarchicalEventMixin {
|
||||
required this.mediaType,
|
||||
this.leafCount = 1,
|
||||
this.isDownloadOnly = false,
|
||||
}) : globalKey = '$serverId:$ratingKey';
|
||||
}) : globalKey = buildGlobalKey(serverId, ratingKey);
|
||||
|
||||
@override
|
||||
String toString() => 'DeletionEvent(deleted: $globalKey, type: $mediaType, parents: $parentChain)';
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/// Builds a globalKey string from [serverId] and [ratingKey].
|
||||
String buildGlobalKey(String serverId, String ratingKey) => '$serverId:$ratingKey';
|
||||
|
||||
/// Parses a globalKey string (format: "serverId:ratingKey") into its components.
|
||||
///
|
||||
/// Returns `null` if the key does not contain a colon separator.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'global_key_utils.dart';
|
||||
|
||||
/// Mixin providing hierarchical event matching methods.
|
||||
///
|
||||
/// Events that represent changes to media items often need to check if they
|
||||
@@ -24,7 +26,7 @@ mixin HierarchicalEventMixin {
|
||||
|
||||
/// Check if this event affects a specific globalKey.
|
||||
bool affectsGlobalKey(String globalKey) =>
|
||||
this.globalKey == globalKey || parentChain.any((pk) => '$serverId:$pk' == globalKey);
|
||||
this.globalKey == globalKey || parentChain.any((pk) => buildGlobalKey(serverId, pk) == globalKey);
|
||||
|
||||
/// Check if this event affects any item in a collection.
|
||||
bool affectsAnyOf(Iterable<String> ratingKeys) => ratingKeys.any(affectsItem);
|
||||
|
||||
@@ -77,7 +77,7 @@ Future<bool?> navigateToVideoPlayer(
|
||||
|
||||
if (isOffline) {
|
||||
// Offline mode: resolve local file path for the external player
|
||||
final globalKey = '${metadata.serverId}:${metadata.ratingKey}';
|
||||
final globalKey = metadata.globalKey;
|
||||
final videoPath = await downloadProvider.getVideoFilePath(globalKey);
|
||||
if (videoPath != null && context.mounted) {
|
||||
final videoUrl = videoPath.contains('://') ? videoPath : 'file://$videoPath';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import '../models/plex_metadata.dart';
|
||||
import 'app_logger.dart';
|
||||
import 'base_notifier.dart';
|
||||
import 'global_key_utils.dart';
|
||||
import 'hierarchical_event_mixin.dart';
|
||||
|
||||
/// Types of watch state changes
|
||||
@@ -47,7 +48,7 @@ class WatchStateEvent with HierarchicalEventMixin {
|
||||
required this.mediaType,
|
||||
this.viewOffset,
|
||||
this.isNowWatched,
|
||||
}) : globalKey = '$serverId:$ratingKey';
|
||||
}) : globalKey = buildGlobalKey(serverId, ratingKey);
|
||||
|
||||
@override
|
||||
String toString() => 'WatchStateEvent($changeType, $globalKey, parents: $parentChain)';
|
||||
|
||||
Reference in New Issue
Block a user