[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:
parent
d625a34e2a
commit
6f55afe60a
1 changed files with 11 additions and 3 deletions
|
@ -623,12 +623,20 @@ public class NoteService(
|
||||||
note.Poll.Votes = poll.Votes == null! || poll.Votes.Count != poll.Choices.Count
|
note.Poll.Votes = poll.Votes == null! || poll.Votes.Count != poll.Choices.Count
|
||||||
? poll.Choices.Select(_ => 0).ToList()
|
? poll.Choices.Select(_ => 0).ToList()
|
||||||
: poll.Votes;
|
: 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)
|
else if (poll.Votes.Count == poll.Choices.Count)
|
||||||
{
|
{
|
||||||
note.Poll.Votes = poll.Votes;
|
note.Poll.Votes = 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
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue