relatica/lib/models/connection.dart

85 lines
1.9 KiB
Dart
Raw Normal View History

class Connection {
final ConnectionStatus status;
final String name;
2022-12-28 20:56:27 +00:00
final String handle;
final String id;
final Uri profileUrl;
final String network;
final Uri avatarUrl;
2022-12-28 20:56:27 +00:00
Connection({this.status = ConnectionStatus.unknown,
this.name = '',
this.handle = '',
this.id = '',
Uri? profileUrl,
this.network = '',
Uri? avatarUrl})
: profileUrl = profileUrl ?? Uri(),
avatarUrl = avatarUrl ?? Uri();
2022-12-28 20:56:27 +00:00
Connection copy({ConnectionStatus? status,
String? name,
String? handle,
String? id,
Uri? profileUrl,
String? network,
Uri? avatarUrl}) =>
2022-11-22 19:42:26 +00:00
Connection(
status: status ?? this.status,
name: name ?? this.name,
2022-12-28 20:56:27 +00:00
handle: handle ?? this.handle,
2022-11-22 19:42:26 +00:00
id: id ?? this.id,
profileUrl: profileUrl ?? this.profileUrl,
network: network ?? this.network,
avatarUrl: avatarUrl ?? this.avatarUrl,
);
@override
String toString() {
2022-12-28 20:56:27 +00:00
return 'Connection{status: $status, name: $name, id: $id, handle: $handle, profileUrl: $profileUrl, network: $network, avatar: $avatarUrl}';
}
2022-12-14 15:50:17 +00:00
@override
bool operator ==(Object other) =>
identical(this, other) ||
2022-12-28 20:56:27 +00:00
other is Connection && runtimeType == other.runtimeType &&
id == other.id;
2022-12-14 15:50:17 +00:00
@override
int get hashCode => id.hashCode;
}
enum ConnectionStatus {
youFollowThem,
theyFollowYou,
mutual,
2022-11-22 19:42:26 +00:00
you,
none,
2022-12-14 15:50:17 +00:00
unknown,
}
extension FriendStatusWriter on ConnectionStatus {
2022-12-14 15:50:17 +00:00
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";
2022-11-22 19:42:26 +00:00
case ConnectionStatus.you:
return "You";
2022-12-14 15:50:17 +00:00
case ConnectionStatus.unknown:
return 'Unknown';
}
}
}