add evil fedi feature: deanonymized polls
This commit is contained in:
parent
ea14120f9f
commit
cabbfa077c
2 changed files with 72 additions and 1 deletions
|
@ -29,6 +29,7 @@ source=(
|
|||
"iceshrimp.net.install"
|
||||
"iceshrimp.net.hook"
|
||||
"iceshrimp.net-uncap-polls.patch"
|
||||
"iceshrimp.net-deanonymize-polls-endpoint.patch"
|
||||
)
|
||||
|
||||
sha512sums=('SKIP'
|
||||
|
@ -37,7 +38,8 @@ sha512sums=('SKIP'
|
|||
'0665aa7af2b2aa4405289ce9119439ddcc6b9e6c81dc8e3b9ed5d8ecdc4a39d49c950d41d3098ce99fe294ce51a2dee55ec7248c1756783b0e9aad0bde4654fa'
|
||||
'0a0467df278f3bd739114725b373f5ec6c7296f609f0a9bcb4f8142b44856fc63e32f76390adf757005035dc691a4c54a662cc8a287572b61e215c29e3d3cbf2'
|
||||
'085d94b31e8eb3109b18251381766799d45c351ec6c7ec45d6edad1915ed89fa9b32765f6deaec191a501274b791000e75ecd052af46bf5341af619b1c7a9bf7'
|
||||
'57dbdb3e73ea273c78c19befaf3d8e1f7dc079630d69eed1ffaf05636969d69e3b5f541d3c915b19edf6eb66398cbdd4b6a57e38f3e8088a259b8bd47f9b4ff7')
|
||||
'57dbdb3e73ea273c78c19befaf3d8e1f7dc079630d69eed1ffaf05636969d69e3b5f541d3c915b19edf6eb66398cbdd4b6a57e38f3e8088a259b8bd47f9b4ff7'
|
||||
'13c921c8137792b67201b81f364b4b60443c01cee023723af71d7f64de908e05998cf7ead7b5e50f49426e8d32612d5242ec79927cde21215173a0c6a8d05b3b')
|
||||
|
||||
pkgver() {
|
||||
cd "${srcdir}/iceshrimp.net"
|
||||
|
@ -55,6 +57,7 @@ rid() {
|
|||
prepare() {
|
||||
cd "${srcdir}/iceshrimp.net"
|
||||
git apply ../iceshrimp.net-uncap-polls.patch
|
||||
git apply ../iceshrimp.net-deanonymize-polls-endpoint.patch
|
||||
}
|
||||
|
||||
build() {
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
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; }
|
Loading…
Add table
Reference in a new issue