1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00
comunicmobile/lib/lists/forez_presences_set.dart

52 lines
1.5 KiB
Dart
Raw Normal View History

2021-04-22 13:41:35 +00:00
import 'package:comunic/lists/base_set.dart';
import 'package:comunic/models/forez_presence.dart';
/// Forez presence set
///
/// @author Pierre Hubert
class PresenceSet extends BaseSet<Presence> {
/// Get the presence of a specific user
PresenceSet getForUser(int? userID) =>
2021-04-22 13:41:35 +00:00
PresenceSet()..addAll(where((element) => element.userID == userID));
bool containsDate(DateTime dt) => any(
(element) =>
element.year == dt.year &&
element.month == dt.month &&
element.day == dt.day,
);
void removeDate(DateTime dt) => removeWhere(
(element) =>
element.year == dt.year &&
element.month == dt.month &&
element.day == dt.day,
);
void toggleDate(DateTime dt, int? userID) {
2021-04-22 13:41:35 +00:00
if (containsDate(dt))
removeDate(dt);
else
add(Presence.fromDateTime(dt, userID!));
2021-04-22 13:41:35 +00:00
}
int countAtDate(DateTime dt) => where(
(element) =>
element.year == dt.year &&
element.month == dt.month &&
element.day == dt.day,
).length;
/// Get the list of users present at a specified date
List<int> getUsersAtDate(DateTime dt) => where(
(element) =>
element.year == dt.year &&
element.month == dt.month &&
element.day == dt.day,
).map((e) => e.userID).toList();
/// Get the ID of all the users referenced in this set
Set<int> get usersID => map((element) => element.userID).toSet();
}