From 8d3caf5375a8065281b917b1c24970580799a059 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Fri, 24 Apr 2026 19:17:26 -0400 Subject: [PATCH] feat(comments): implement recursive comment deletion in HardDeleteComment method --- .../lib/components/PasteCommentItem.svelte | 30 ++++++++++--------- SharpbinV3.Server/Services/CommentService.cs | 21 ++++++++++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte b/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte index aca089b..431b72d 100644 --- a/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte +++ b/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte @@ -209,26 +209,28 @@ > {replyOpen ? 'Cancel' : 'Reply'} -
- - {#if hasRole($user.roles, 4)} + {#if node.author?.uuid === $user.uuid || hasRole($user.roles, 4) || hasRole($user.roles, 2)} +
- {/if} -
+ {#if hasRole($user.roles, 4) || hasRole($user.roles, 2)} + + {/if} +
+ {/if} {/if} diff --git a/SharpbinV3.Server/Services/CommentService.cs b/SharpbinV3.Server/Services/CommentService.cs index 884eaa0..60a6cf9 100644 --- a/SharpbinV3.Server/Services/CommentService.cs +++ b/SharpbinV3.Server/Services/CommentService.cs @@ -78,7 +78,26 @@ namespace SharpbinV3.Server.Services public async Task HardDeleteComment(Comment comment) { - _db.Comments.Remove(comment); + var commentIdsToDelete = new HashSet { comment.Id }; + var currentLevelIds = new List { comment.Id }; + + while (currentLevelIds.Count != 0) + { + var childIds = await _db + .Comments.Where(c => c.ParentCommentID.HasValue && currentLevelIds.Contains(c.ParentCommentID.Value)) + .Select(c => c.Id) + .ToListAsync(); + + currentLevelIds = []; + foreach (var childId in childIds) + { + if (commentIdsToDelete.Add(childId)) + currentLevelIds.Add(childId); + } + } + + var commentsToDelete = await _db.Comments.Where(c => commentIdsToDelete.Contains(c.Id)).ToListAsync(); + _db.Comments.RemoveRange(commentsToDelete); var result = await _db.SaveChangesAsync(); return result > 0; }