mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-19 00:03:32 +00:00
54 lines
1.3 KiB
Dart
54 lines
1.3 KiB
Dart
import 'TimelineIdentifiers.dart';
|
|
import 'entry_tree_item.dart';
|
|
|
|
class Timeline {
|
|
final TimelineIdentifiers id;
|
|
final List<EntryTreeItem> _posts = [];
|
|
final Set<EntryTreeItem> _postsSet = {};
|
|
int _lowestStatusId = 0;
|
|
int _highestStatusId = 0;
|
|
|
|
int get highestStatusId => _highestStatusId;
|
|
|
|
Timeline(this.id, {List<EntryTreeItem>? initialPosts}) {
|
|
if (initialPosts != null) {
|
|
addPosts(initialPosts);
|
|
}
|
|
}
|
|
|
|
List<EntryTreeItem> get posts => List.unmodifiable(_posts);
|
|
|
|
void addPosts(List<EntryTreeItem> newPosts) {
|
|
for (final p in newPosts) {
|
|
final id = int.parse(p.id);
|
|
if (_lowestStatusId > id) {
|
|
_lowestStatusId = id;
|
|
}
|
|
|
|
if (_highestStatusId < id) {
|
|
_highestStatusId = id;
|
|
}
|
|
_postsSet.add(p);
|
|
}
|
|
_posts.clear();
|
|
_posts.addAll(_postsSet);
|
|
_posts.sort((p1, p2) {
|
|
return p2.entry.backdatedTimestamp.compareTo(p1.entry.backdatedTimestamp);
|
|
});
|
|
}
|
|
|
|
void clear() {
|
|
_posts.clear();
|
|
_postsSet.clear();
|
|
_lowestStatusId = 0;
|
|
_highestStatusId = 0;
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Timeline && runtimeType == other.runtimeType && id == other.id;
|
|
|
|
@override
|
|
int get hashCode => id.hashCode;
|
|
}
|