[backend/core] Fix editing of polls with no recorded votes

This commit is contained in:
Laura Hausmann 2024-05-16 18:54:18 +02:00
parent 1fae913a32
commit ea8ff6495c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -466,7 +466,7 @@ public class NoteService(
await db.PollVotes.Where(p => p.Note == note).ExecuteDeleteAsync();
note.Poll.Choices = poll.Choices;
note.Poll.Multiple = poll.Multiple;
note.Poll.Votes = poll.Votes.Count != poll.Choices.Count
note.Poll.Votes = poll.Votes == null! || poll.Votes.Count != poll.Choices.Count
? poll.Choices.Select(_ => 0).ToList()
: poll.Votes;
}
@ -483,7 +483,7 @@ public class NoteService(
poll.UserId = note.User.Id;
poll.UserHost = note.UserHost;
poll.NoteVisibility = note.Visibility;
if (poll.Votes.Count != poll.Choices.Count)
if (poll.Votes == null! || poll.Votes.Count != poll.Choices.Count)
poll.Votes = poll.Choices.Select(_ => 0).ToList();
await db.AddAsync(poll);