1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00
comunicmobile/lib/lists/posts_list.dart

58 lines
1.1 KiB
Dart
Raw Normal View History

2019-05-10 17:15:11 +00:00
import 'dart:collection';
import 'package:comunic/models/post.dart';
/// Posts List
///
/// Contains method to easily process a list of posts
///
/// @author Pierre HUBERT
class PostsList extends ListBase<Post> {
2021-03-13 14:14:54 +00:00
List<Post> _list = [];
2019-05-10 17:15:11 +00:00
int get length => _list.length;
set length(int l) => _list.length = l;
@override
Post operator [](int index) => _list[index];
@override
void operator []=(int index, Post value) => _list[index] = value;
// Get the list of users ID in this set
Set<int> get usersID {
Set<int> set = Set();
forEach((p) {
set.add(p.userID);
2019-06-10 07:47:02 +00:00
if (p.userPageID != null && p.userPageID > 0) set.add(p.userPageID);
2019-05-16 12:52:22 +00:00
2019-06-10 07:47:02 +00:00
if (p.comments != null) set.addAll(p.comments.usersID);
2019-05-10 17:15:11 +00:00
});
return set;
}
2019-06-10 07:47:02 +00:00
/// Get the list of groups in this list of posts
Set<int> get groupsID {
Set<int> set = Set();
forEach((p) {
if (p.isGroupPost) set.add(p.groupID);
});
return set;
}
/// Get the ID of the oldest post of this list. Returns 0 if the list is empty
int get oldestID {
if(isEmpty)
return 0;
return this.elementAt(length - 1).id;
}
2019-06-10 07:47:02 +00:00
}