import 'TimelineIdentifiers.dart'; import 'entry_tree_item.dart'; class Timeline { final TimelineIdentifiers id; final List _posts = []; final Set _postsSet = {}; int _lowestStatusId = 0; int _highestStatusId = 0; int get highestStatusId => _highestStatusId; Timeline(this.id, {List? initialPosts}) { if (initialPosts != null) { addPosts(initialPosts); } } List get posts => List.unmodifiable(_posts); void addPosts(List 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; }