Files

32 lines
895 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace PollMaker.Internal;
internal sealed record PollState(string Question, string[] Options)
{
public List<HashSet<ulong>> Votes { get; } =
Enumerable.Range(0, Options.Length).Select(_ => new HashSet<ulong>()).ToList();
public bool IsOpen { get; private set; } = true;
public void Close() => IsOpen = false;
/// <summary>
/// Toggle the members vote.
/// Clicking the **same button** again removes their vote;
/// clicking a **different** button moves the vote.
/// </summary>
public void ToggleVote(int optionIdx, ulong userId)
{
if (!IsOpen) return;
if (Votes[optionIdx].Contains(userId))
{
Votes[optionIdx].Remove(userId);
return;
}
foreach (var set in Votes)
set.Remove(userId);
Votes[optionIdx].Add(userId);
}
}