add poll support

Fixes #130
This commit is contained in:
Henry Hiles 2026-11-02 12:03:52 -05:00
commit f6aaf49164
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -0,0 +1,25 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
class const PollVotes({
/// Each user's answers, by user ID
final IMap<String, IList<String>> votes = const .empty(),
final String? endEventId,
final int undecryptable = 0,
}) {
bool get hasEnded => endEventId != null;
IMap<String, IList<String>> get votersByAnswer => votes.entries.fold(
const .empty(),
(acc, entry) => entry.value.fold(
acc,
(acc, answer) => acc.update(
answer,
(voters) => voters.add(entry.key),
ifAbsent: () => .new([entry.key]),
),
),
);
int get voterCount =>
votes.values.where((answers) => answers.isNotEmpty).length;
}