[backend/core] Improve poll voter count fallback

This should fix erroneous voter counts for polls from instances that don't return as:votersCount.
This commit is contained in:
Laura Hausmann 2024-10-16 22:07:26 +02:00
parent d625a34e2a
commit 6f55afe60a
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -623,12 +623,20 @@ public class NoteService(
note.Poll.Votes = poll.Votes == null! || poll.Votes.Count != poll.Choices.Count
? poll.Choices.Select(_ => 0).ToList()
: poll.Votes;
note.Poll.VotersCount = poll.VotersCount ?? note.Poll.VotersCount;
note.Poll.VotersCount =
poll.VotersCount ??
(note.Poll.VotersCount == null
? null
: Math.Max(note.Poll.VotersCount.Value, note.Poll.Votes.Sum()));
}
else if (poll.Votes.Count == poll.Choices.Count)
{
note.Poll.Votes = poll.Votes;
note.Poll.VotersCount = poll.VotersCount ?? note.Poll.VotersCount;
note.Poll.Votes = poll.Votes;
note.Poll.VotersCount =
poll.VotersCount ??
(note.Poll.VotersCount == null
? null
: Math.Max(note.Poll.VotersCount.Value, note.Poll.Votes.Sum()));
}
}
else