Files
plezy/lib/utils/global_key_utils.dart
T

24 lines
1.1 KiB
Dart
Raw Normal View History

2026-06-01 11:06:03 +02:00
import '../media/ids.dart';
String buildGlobalKey(ServerId serverId, String ratingKey) => '$serverId:$ratingKey';
2026-04-26 02:34:09 +02:00
/// Separator used by profile-owned rows whose public media identity is still
/// [buildGlobalKey]. Profile ids are generated by the app and do not contain
/// this character.
const String profileScopedGlobalKeySeparator = '|';
/// Builds a profile-owned sync-rule key from [profileId] and public media id.
2026-06-01 11:06:03 +02:00
String buildProfileScopedGlobalKey(String profileId, ServerId serverId, String ratingKey) {
2026-04-26 02:34:09 +02:00
return '$profileId$profileScopedGlobalKeySeparator${buildGlobalKey(serverId, ratingKey)}';
}
2026-02-04 11:11:01 +01:00
/// Parses a globalKey string (format: "serverId:ratingKey") into its components.
///
/// Returns `null` if the key does not contain a colon separator.
/// Uses [indexOf] so ratingKeys containing colons are handled correctly.
2026-06-01 11:06:03 +02:00
({ServerId serverId, String ratingKey})? parseGlobalKey(String globalKey) {
2026-02-04 11:11:01 +01:00
final idx = globalKey.indexOf(':');
2026-06-04 13:47:06 +02:00
if (idx <= 0) return null;
2026-06-01 11:06:03 +02:00
return (serverId: ServerId(globalKey.substring(0, idx)), ratingKey: globalKey.substring(idx + 1));
2026-02-04 11:11:01 +01:00
}