68 lines
2.3 KiB
Diff
68 lines
2.3 KiB
Diff
diff --git a/Iceshrimp.Backend/Controllers/Web/NoteController.cs b/Iceshrimp.Backend/Controllers/Web/NoteController.cs
|
|
index 26cc0a89..44d87891 100644
|
|
--- a/Iceshrimp.Backend/Controllers/Web/NoteController.cs
|
|
+++ b/Iceshrimp.Backend/Controllers/Web/NoteController.cs
|
|
@@ -561,6 +561,45 @@ public class NoteController(
|
|
return res.Poll!;
|
|
}
|
|
|
|
+ [HttpGet("{id}/votes")]
|
|
+ [Authenticate]
|
|
+ [Authorize]
|
|
+ [ProducesResults(HttpStatusCode.OK)]
|
|
+ [ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
|
|
+ public async Task<List<EvilPollVote>> GetPollVotes(string id)
|
|
+ {
|
|
+ var user = HttpContext.GetUserOrFail();
|
|
+
|
|
+ _ = await db.Notes.Where(p => p.Id == id).EnsureVisibleFor(user).FirstOrDefaultAsync()
|
|
+ ?? throw GracefulException.NotFound("Note not found");
|
|
+
|
|
+ var votes = await db.PollVotes
|
|
+ .Where(p => p.NoteId == id)
|
|
+ .Select(p => new {p.UserId, p.Choice})
|
|
+ .ToListAsync()
|
|
+ ?? throw GracefulException.NotFound("Poll votes not found");
|
|
+
|
|
+ List<EvilPollVote> pollVotes = [];
|
|
+
|
|
+ var users = await db.Users
|
|
+ .Where(p => votes.Select(v => v.UserId).Distinct().ToList().Contains(p.Id))
|
|
+ .ToListAsync();
|
|
+
|
|
+ // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
|
|
+ foreach (var vote in votes)
|
|
+ {
|
|
+ var usernameInfo = users.Where(p => p.Id == vote.UserId).Select(p => new {p.Username, p.Host}).FirstOrDefault();
|
|
+ pollVotes.Add(new EvilPollVote
|
|
+ {
|
|
+ UserId = vote.UserId,
|
|
+ Username = $"@{usernameInfo!.Username}@{usernameInfo.Host}",
|
|
+ Choice = vote.Choice
|
|
+ });
|
|
+ }
|
|
+
|
|
+ return pollVotes;
|
|
+ }
|
|
+
|
|
[HttpPost]
|
|
[Authenticate]
|
|
[Authorize]
|
|
diff --git a/Iceshrimp.Shared/Schemas/Web/NoteResponse.cs b/Iceshrimp.Shared/Schemas/Web/NoteResponse.cs
|
|
index 7557fea7..498becd9 100644
|
|
--- a/Iceshrimp.Shared/Schemas/Web/NoteResponse.cs
|
|
+++ b/Iceshrimp.Shared/Schemas/Web/NoteResponse.cs
|
|
@@ -68,6 +68,13 @@ public class NotePollSchema
|
|
public required int? VotersCount { get; set; }
|
|
}
|
|
|
|
+public class EvilPollVote
|
|
+{
|
|
+ public required string UserId { get; set; }
|
|
+ public required string Username { get; set; }
|
|
+ public required int Choice { get; set; }
|
|
+}
|
|
+
|
|
public class NotePollChoice
|
|
{
|
|
public required string Value { get; set; }
|