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

44 lines
931 B
Dart
Raw Normal View History

2022-03-10 19:28:07 +00:00
import 'package:comunic/lists/abstract_list.dart';
2019-05-10 17:15:11 +00:00
import 'package:comunic/models/post.dart';
/// Posts List
///
/// Contains method to easily process a list of posts
///
/// @author Pierre HUBERT
2022-03-10 19:28:07 +00:00
class PostsList extends AbstractList<Post> {
2019-05-10 17:15:11 +00:00
// Get the list of users ID in this set
Set<int?> get usersID {
Set<int?> set = Set();
2019-05-10 17:15:11 +00:00
forEach((p) {
set.add(p.userID);
if (p.userPageID != null && p.userPageID! > 0) set.add(p.userPageID);
2019-05-16 12:52:22 +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();
2019-06-10 07:47:02 +00:00
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 {
2022-03-10 19:28:07 +00:00
if (isEmpty) return 0;
return this.elementAt(length - 1).id;
}
2019-06-10 07:47:02 +00:00
}