mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat(comments): implement recursive comment deletion in HardDeleteComment method
This commit is contained in:
@@ -209,6 +209,7 @@
|
|||||||
>
|
>
|
||||||
{replyOpen ? 'Cancel' : 'Reply'}
|
{replyOpen ? 'Cancel' : 'Reply'}
|
||||||
</button>
|
</button>
|
||||||
|
{#if node.author?.uuid === $user.uuid || hasRole($user.roles, 4) || hasRole($user.roles, 2)}
|
||||||
<div class="ml-auto">
|
<div class="ml-auto">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -218,7 +219,7 @@
|
|||||||
>
|
>
|
||||||
<Trash2 class="inline h-3.5 w-3.5" />
|
<Trash2 class="inline h-3.5 w-3.5" />
|
||||||
</button>
|
</button>
|
||||||
{#if hasRole($user.roles, 4)}
|
{#if hasRole($user.roles, 4) || hasRole($user.roles, 2)}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="h-7 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
|
class="h-7 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
|
||||||
@@ -230,6 +231,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if replyOpen}
|
{#if replyOpen}
|
||||||
|
|||||||
@@ -78,7 +78,26 @@ namespace SharpbinV3.Server.Services
|
|||||||
|
|
||||||
public async Task<bool> HardDeleteComment(Comment comment)
|
public async Task<bool> HardDeleteComment(Comment comment)
|
||||||
{
|
{
|
||||||
_db.Comments.Remove(comment);
|
var commentIdsToDelete = new HashSet<long> { comment.Id };
|
||||||
|
var currentLevelIds = new List<long> { 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();
|
var result = await _db.SaveChangesAsync();
|
||||||
return result > 0;
|
return result > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user