From ea8ff6495c017e523df68a7995b14b5fb2c03dd1 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 16 May 2024 18:54:18 +0200 Subject: [PATCH] [backend/core] Fix editing of polls with no recorded votes --- Iceshrimp.Backend/Core/Services/NoteService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/NoteService.cs b/Iceshrimp.Backend/Core/Services/NoteService.cs index 5d811940..2b31c3e8 100644 --- a/Iceshrimp.Backend/Core/Services/NoteService.cs +++ b/Iceshrimp.Backend/Core/Services/NoteService.cs @@ -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); @@ -718,7 +718,7 @@ public class NoteService( return null; } - + if (note.PublishedAt is null or { Year: < 2007 } || note.PublishedAt > DateTime.Now + TimeSpan.FromDays(3)) throw GracefulException.UnprocessableEntity("Note.PublishedAt is nonsensical");