Files
plezy/lib/profiles/active_plex_identity.dart
edde746 6eb0805f8d refactor(profiles): delete dead client accessors, the write-only focus aspect, and test-only registry API
getServerBoundPlexClient/getClientForLibrary existed only for their own unit tests; MetadataEditAdapter.backend and Plex's unreachable prefKey fallback and music-kind branches had no production path (edit is double-gated on supportsKind); MainScreenFocusScope's focus aspect, isSidebarFocused, and focusContent were write-only; resolveActivePlexIdentity.preferredAccount was never passed; ProfileRegistry.get was unused outside tests — its removal exposed a stale test contract, now pinned correctly: list() deliberately never serves plex_home rows.
2026-08-17 19:02:24 +02:00

44 lines
1.4 KiB
Dart

import '../connection/connection.dart';
import '../connection/connection_registry.dart';
import 'active_profile_provider.dart';
import 'profile_connection_registry.dart';
class ActivePlexIdentity {
const ActivePlexIdentity({required this.account, this.userUuid});
final PlexAccountConnection account;
final String? userUuid;
}
Future<ActivePlexIdentity?> resolveActivePlexIdentity({
required ActiveProfileProvider activeProfile,
required ConnectionRegistry connections,
required ProfileConnectionRegistry profileConnections,
}) async {
await activeProfile.initialize();
final profile = activeProfile.active;
final parentId = profile?.parentConnectionId;
if (parentId != null) {
final account = await connections.getPlexAccount(parentId);
if (account != null) {
return ActivePlexIdentity(account: account, userUuid: profile?.plexHomeUserUuid);
}
}
if (profile != null) {
final pcs = await profileConnections.listForProfile(profile.id);
for (final pc in pcs) {
final account = await connections.getPlexAccount(pc.connectionId);
if (account != null) {
return ActivePlexIdentity(account: account, userUuid: pc.userIdentifier.isEmpty ? null : pc.userIdentifier);
}
}
return null;
}
final accounts = await connections.listPlexAccounts();
if (accounts.isEmpty) return null;
return ActivePlexIdentity(account: accounts.first);
}