37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
// lib/model/entry/extensions/remote_identity.dart
|
|
|
|
import 'package:aves/model/entry/entry.dart';
|
|
import 'package:aves/remote/remote_db_uris.dart';
|
|
|
|
extension EntryRemoteIdentity on AvesEntry {
|
|
/// Remote id operativo.
|
|
///
|
|
/// Prima prova a ricavarlo dalla uri:
|
|
/// aves-remote://rid/<remoteId>
|
|
///
|
|
/// Se non riesce, usa il vecchio campo remoteId.
|
|
///
|
|
/// Questo permette di iniziare a usare uri come sorgente principale,
|
|
/// senza rompere il codice vecchio che ha ancora remoteId valorizzato.
|
|
String? get effectiveRemoteId {
|
|
final fromUri = RemoteDbUris.remoteIdFromUri(uri);
|
|
if (fromUri != null && fromUri.trim().isNotEmpty) {
|
|
return fromUri.trim();
|
|
}
|
|
|
|
final rid = remoteId?.trim();
|
|
if (rid != null && rid.isNotEmpty) {
|
|
return rid;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// True se la entry ha un remote id utilizzabile,
|
|
/// anche se remoteId nel DB è vuoto ma la uri contiene l'id.
|
|
bool get hasEffectiveRemoteId => effectiveRemoteId != null;
|
|
|
|
/// True se la uri è una uri sintetica remota Aves.
|
|
bool get hasSyntheticRemoteUri => RemoteDbUris.isSynthetic(uri);
|
|
}
|
|
|