mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 14:29:22 +00:00
38 lines
997 B
Dart
38 lines
997 B
Dart
import 'package:comunic/lists/abstract_list.dart';
|
|
import 'package:comunic/models/membership.dart';
|
|
|
|
/// Memberships list
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
class MembershipList extends AbstractList<Membership> {
|
|
/// Get the IDs of all the users included in some way in this list
|
|
Set<int> get usersId {
|
|
final s = Set<int>();
|
|
|
|
forEach((m) {
|
|
switch (m.type) {
|
|
case MembershipType.FRIEND:
|
|
s.add(m.friend.id);
|
|
break;
|
|
case MembershipType.GROUP:
|
|
break;
|
|
case MembershipType.CONVERSATION:
|
|
s.addAll(m.conversation.members);
|
|
break;
|
|
}
|
|
});
|
|
|
|
return s;
|
|
}
|
|
|
|
/// Get the ID of the groups included in this list
|
|
Set<int> get groupsId => where((f) => f.type == MembershipType.GROUP)
|
|
.map((f) => f.groupID)
|
|
.toSet();
|
|
|
|
/// Remove a friend membership from the list
|
|
void removeFriend(int friendID) => remove(firstWhere(
|
|
(f) => f.type == MembershipType.FRIEND && f.friend.id == friendID));
|
|
}
|