relatica/lib/models/connection.dart

93 wiersze
2.1 KiB
Dart

class Connection {
final ConnectionStatus status;
final String name;
final String handle;
final String id;
final Uri profileUrl;
final String network;
final Uri avatarUrl;
Connection({this.status = ConnectionStatus.unknown,
this.name = '',
this.handle = '',
this.id = '',
Uri? profileUrl,
this.network = '',
Uri? avatarUrl})
: profileUrl = profileUrl ?? Uri(),
avatarUrl = avatarUrl ?? Uri();
bool get isEmpty =>
name.isEmpty &&
id.isEmpty &&
network.isEmpty &&
status == ConnectionStatus.unknown;
bool get isNotEmpty => !isEmpty;
Connection copy({ConnectionStatus? status,
String? name,
String? handle,
String? id,
Uri? profileUrl,
String? network,
Uri? avatarUrl}) =>
Connection(
status: status ?? this.status,
name: name ?? this.name,
handle: handle ?? this.handle,
id: id ?? this.id,
profileUrl: profileUrl ?? this.profileUrl,
network: network ?? this.network,
avatarUrl: avatarUrl ?? this.avatarUrl,
);
@override
String toString() {
return 'Connection{status: $status, name: $name, id: $id, handle: $handle, profileUrl: $profileUrl, network: $network, avatar: $avatarUrl}';
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Connection && runtimeType == other.runtimeType &&
id == other.id;
@override
int get hashCode => id.hashCode;
}
enum ConnectionStatus {
youFollowThem,
theyFollowYou,
mutual,
you,
none,
unknown,
}
extension FriendStatusWriter on ConnectionStatus {
String label() {
switch (this) {
case ConnectionStatus.youFollowThem:
return "You Follow Them";
case ConnectionStatus.theyFollowYou:
return "They Follow You";
case ConnectionStatus.mutual:
return "Follow each other";
case ConnectionStatus.none:
return "Not connected";
case ConnectionStatus.you:
return "You";
case ConnectionStatus.unknown:
return 'Unknown';
}
}
}