refactor: centralize globalKey construction via buildGlobalKey()

This commit is contained in:
edde746
2026-02-23 17:53:20 +01:00
parent ef2c464dd4
commit e23f472d78
21 changed files with 65 additions and 48 deletions
+2 -1
View File
@@ -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)';
+3
View File
@@ -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.
+3 -1
View File
@@ -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);
+1 -1
View File
@@ -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';
+2 -1
View File
@@ -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)';