refactor: migrate models to freezed + json_serializable
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'profile_connection.freezed.dart';
|
||||
|
||||
/// A binding between a [Profile] and a [Connection], carrying the
|
||||
/// per-profile user-level token used when the profile is active.
|
||||
///
|
||||
@@ -9,47 +13,19 @@
|
||||
///
|
||||
/// For Jellyfin: [userToken] mirrors the Connection's accessToken (one
|
||||
/// user per connection); [userIdentifier] is the Jellyfin user id.
|
||||
class ProfileConnection {
|
||||
final String profileId;
|
||||
final String connectionId;
|
||||
final String? userToken;
|
||||
final String userIdentifier;
|
||||
final bool isDefault;
|
||||
final DateTime? tokenAcquiredAt;
|
||||
final DateTime? lastUsedAt;
|
||||
@freezed
|
||||
sealed class ProfileConnection with _$ProfileConnection {
|
||||
const ProfileConnection._();
|
||||
|
||||
const ProfileConnection({
|
||||
required this.profileId,
|
||||
required this.connectionId,
|
||||
this.userToken,
|
||||
required this.userIdentifier,
|
||||
this.isDefault = false,
|
||||
this.tokenAcquiredAt,
|
||||
this.lastUsedAt,
|
||||
});
|
||||
const factory ProfileConnection({
|
||||
required String profileId,
|
||||
required String connectionId,
|
||||
String? userToken,
|
||||
required String userIdentifier,
|
||||
@Default(false) bool isDefault,
|
||||
DateTime? tokenAcquiredAt,
|
||||
DateTime? lastUsedAt,
|
||||
}) = _ProfileConnection;
|
||||
|
||||
bool get hasToken => userToken != null && userToken!.isNotEmpty;
|
||||
|
||||
ProfileConnection copyWith({
|
||||
String? profileId,
|
||||
String? connectionId,
|
||||
String? userToken,
|
||||
bool clearUserToken = false,
|
||||
String? userIdentifier,
|
||||
bool? isDefault,
|
||||
DateTime? tokenAcquiredAt,
|
||||
bool clearTokenAcquiredAt = false,
|
||||
DateTime? lastUsedAt,
|
||||
bool clearLastUsedAt = false,
|
||||
}) {
|
||||
return ProfileConnection(
|
||||
profileId: profileId ?? this.profileId,
|
||||
connectionId: connectionId ?? this.connectionId,
|
||||
userToken: clearUserToken ? null : (userToken ?? this.userToken),
|
||||
userIdentifier: userIdentifier ?? this.userIdentifier,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
tokenAcquiredAt: clearTokenAcquiredAt ? null : (tokenAcquiredAt ?? this.tokenAcquiredAt),
|
||||
lastUsedAt: clearLastUsedAt ? null : (lastUsedAt ?? this.lastUsedAt),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user