relatica/lib/models/TimelineIdentifiers.dart

80 lines
1.7 KiB
Dart
Raw Normal View History

2022-11-17 16:04:14 +00:00
enum TimelineType {
home,
global,
local,
circle,
2022-11-17 16:04:14 +00:00
profile,
2022-12-08 18:37:30 +00:00
self;
String toLabel() {
switch (this) {
case TimelineType.home:
return 'My Network';
2022-12-08 18:37:30 +00:00
case TimelineType.global:
return 'Global Fediverse';
2022-12-08 18:37:30 +00:00
case TimelineType.local:
return 'Local Fediverse';
case TimelineType.circle:
return 'Circles';
2022-12-08 18:37:30 +00:00
case TimelineType.profile:
return 'Profile';
case TimelineType.self:
return 'My Posts';
2022-12-08 18:37:30 +00:00
}
}
2022-11-17 16:04:14 +00:00
}
class TimelineIdentifiers {
final TimelineType timeline;
final String auxData;
final String label;
2022-11-22 05:21:41 +00:00
const TimelineIdentifiers({
required this.timeline,
this.auxData = '',
this.label = '',
});
2022-11-17 16:04:14 +00:00
String toHumanKey() {
return auxData.isEmpty ? timeline.name : '${timeline.name}_$auxData';
}
String toLabel() {
if (label.isNotEmpty) {
return label;
}
if (timeline != TimelineType.circle) {
return timeline.toLabel();
}
return '${timeline.toLabel()} $auxData';
}
2022-11-17 16:04:14 +00:00
factory TimelineIdentifiers.home() =>
const TimelineIdentifiers(timeline: TimelineType.home);
2022-11-17 16:04:14 +00:00
2022-12-17 17:17:47 +00:00
factory TimelineIdentifiers.profile(String profileId) => TimelineIdentifiers(
timeline: TimelineType.profile,
auxData: profileId,
);
2022-11-17 16:04:14 +00:00
@override
String toString() {
return auxData.isEmpty
? 'TimelineIdentifiers{timeline: $timeline)'
: 'TimelineIdentifiers{timeline: $timeline, auxData: $auxData}';
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
2022-12-17 17:17:47 +00:00
other is TimelineIdentifiers &&
runtimeType == other.runtimeType &&
timeline == other.timeline &&
auxData == other.auxData;
@override
int get hashCode => timeline.hashCode ^ auxData.hashCode;
2022-11-17 16:04:14 +00:00
}