From 6ed2974e42df9d10da755af6897b4eea4ee6d34a Mon Sep 17 00:00:00 2001 From: whoswhip Date: Thu, 18 Jun 2026 21:28:48 -0400 Subject: [PATCH] feat: allow staff members to see user's unlisted pastes; show dislikes in the paste lists --- .../src/lib/components/Paste.svelte | 36 ++++++++++++++----- .../Controllers/PasteController.cs | 2 ++ .../Controllers/UserController.cs | 7 ++++ SharpbinV3.Server/Services/PasteService.cs | 27 +++++++++++++- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/SharpbinV3.Client/src/lib/components/Paste.svelte b/SharpbinV3.Client/src/lib/components/Paste.svelte index e2c190e..28f24d6 100644 --- a/SharpbinV3.Client/src/lib/components/Paste.svelte +++ b/SharpbinV3.Client/src/lib/components/Paste.svelte @@ -12,7 +12,8 @@ Lock, EyeOff, Globe, - HatGlasses + HatGlasses, + ThumbsUp } from '@lucide/svelte'; import { syntaxes } from '$lib/consts'; import type { Paste } from '$lib/types/paste'; @@ -27,6 +28,8 @@ let { paste, now, showUser = true, compact = false }: Props = $props(); let syntax = $derived(syntaxes[paste.syntax] ?? syntaxes['plaintext']); + let netLikes = $derived(paste.likes - paste.dislikes); + let netLikeText = $derived(`${formatNumber(netLikes)} Like${netLikes === 1 ? '' : 's'}`); {#if compact} @@ -83,10 +86,18 @@ {/if} {/if} -
- - - {formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''} +
+ + + {formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''} + + + + {netLikeText} +
@@ -175,13 +186,20 @@
{/if} -
-
+
+
{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}
+ + {netLikeText} +
+
{formatBytes(paste.originalSize)}
-
+
{syntax.name}
diff --git a/SharpbinV3.Server/Controllers/PasteController.cs b/SharpbinV3.Server/Controllers/PasteController.cs index 6e209f9..4ce3423 100644 --- a/SharpbinV3.Server/Controllers/PasteController.cs +++ b/SharpbinV3.Server/Controllers/PasteController.cs @@ -397,6 +397,8 @@ namespace SharpbinV3.Server.Controllers Visibility = p.Visibility, ExpiresAt = p.ExpiresAt, EditedAt = p.EditedAt, + Likes = p.PositiveInteractionCount, + Dislikes = p.NegativeInteractionCount, Author = p.User != null && p.User.Visibility == 0 ? new UserSimpleDto diff --git a/SharpbinV3.Server/Controllers/UserController.cs b/SharpbinV3.Server/Controllers/UserController.cs index 34ac731..a663d89 100644 --- a/SharpbinV3.Server/Controllers/UserController.cs +++ b/SharpbinV3.Server/Controllers/UserController.cs @@ -285,6 +285,11 @@ namespace SharpbinV3.Server.Controllers { if (user.Visibility == Visibility.Private && !requesterIsStaff) return NotFound(); + + if (requesterIsStaff) + pasteQuery = pasteQuery.Where(p => p.Visibility != Visibility.Private); + else if (user.Visibility == Visibility.Unlisted) + pasteQuery = pasteQuery.Where(p => p.Visibility != Visibility.Private); else if (user.Visibility != Visibility.Unlisted) pasteQuery = pasteQuery.Where(p => p.Visibility == Visibility.Public); } @@ -314,6 +319,8 @@ namespace SharpbinV3.Server.Controllers Visibility = p.Visibility, EditedAt = p.EditedAt, ExpiresAt = p.ExpiresAt, + Likes = p.Interactions.Count(i => i.Type == Interaction.Positive), + Dislikes = p.Interactions.Count(i => i.Type == Interaction.Negative), }) .ToListAsync(); diff --git a/SharpbinV3.Server/Services/PasteService.cs b/SharpbinV3.Server/Services/PasteService.cs index cdb5f67..a47c4d3 100644 --- a/SharpbinV3.Server/Services/PasteService.cs +++ b/SharpbinV3.Server/Services/PasteService.cs @@ -206,7 +206,32 @@ namespace SharpbinV3.Server.Services if (publicOnly) query = query.Where(p => p.Visibility == 0); - return await query.OrderByDescending(p => p.PID).Skip(offset).Take(count).Include(p => p.User).ToListAsync(); + var pastes = await query.OrderByDescending(p => p.PID).Skip(offset).Take(count).Include(p => p.User).ToListAsync(); + + if (pastes.Count == 0) + return pastes; + + var pasteIds = pastes.Select(p => p.PID).ToArray(); + var interactionCounts = ( + await _db + .PasteInteractions.Where(pi => pasteIds.Contains(pi.PasteID)) + .GroupBy(pi => new { pi.PasteID, pi.Type }) + .Select(g => new + { + g.Key.PasteID, + g.Key.Type, + Count = g.Count(), + }) + .ToListAsync() + ).ToDictionary(counts => (counts.PasteID, counts.Type), counts => counts.Count); + + foreach (var paste in pastes) + { + paste.PositiveInteractionCount = interactionCounts.GetValueOrDefault((paste.PID, Interaction.Positive)); + paste.NegativeInteractionCount = interactionCounts.GetValueOrDefault((paste.PID, Interaction.Negative)); + } + + return pastes; } public async Task GetUserInteraction(Paste paste, Guid userUUID)