Allow deleting discussion comments

This commit is contained in:
Rūdolfs Ošiņš
2026-08-14 17:30:46 +02:00
parent 1ca4f76575
commit a7c35340ec
5 changed files with 34 additions and 7 deletions
+5 -7
View File
@@ -98,12 +98,6 @@
run: () => void | Promise<void>;
};
const canDelete = $derived(
Boolean(deleteComment) &&
currentUserNid !== undefined &&
utils.publicKeyFromDid(author.did) === currentUserNid,
);
const menuActions: MenuAction[] = $derived.by(() => {
const actions: MenuAction[] = [];
if (id) {
@@ -117,7 +111,11 @@
if (editComment) {
actions.push({ label: "Edit", icon: "edit", run: toggleEdit });
}
if (canDelete && deleteComment) {
// Gated by whoever passes it, exactly as `editComment` is — the protocol
// authorizes both the same way (a delegate, or the comment's own author),
// so a second, stricter rule here would only hide an action the node would
// have accepted.
if (deleteComment) {
actions.push({ label: "Delete", icon: "trash", run: deleteComment });
}
return actions;
+5
View File
@@ -42,6 +42,9 @@
authors: Author[],
reaction: string,
) => Promise<void>;
// Optional: a discussion whose host has no way to redact a comment simply
// does not offer the action.
deleteComment?: (commentId: string) => Promise<void>;
rid: string;
activityItems?: ActivityItem<A>[];
renderActivity?: Snippet<[A, { hideAuthor: boolean }]>;
@@ -58,6 +61,7 @@
createComment,
editComment,
reactOnComment,
deleteComment,
rid,
activityItems,
renderActivity,
@@ -272,6 +276,7 @@
repoDelegates.map(delegate => delegate.did),
)}
{editComment}
{deleteComment}
createReply={createComment}
{reactOnComment} />
<div class="connector"></div>
+1
View File
@@ -857,6 +857,7 @@
{config}
createComment={createDiscussionComment}
editComment={codeActions.editComment}
deleteComment={codeActions.deleteComment}
reactOnComment={codeActions.reactOnComment} />
</div>
{/snippet}
+1
View File
@@ -1877,6 +1877,7 @@
{config}
{createComment}
editComment={codeActions.editComment}
deleteComment={codeActions.deleteComment}
reactOnComment={codeActions.reactOnComment}
{rid}
{activityItems}
+22
View File
@@ -210,6 +210,27 @@
}
}
/// The protocol authorizes a redaction for a delegate or the comment's own
/// author, and refuses it outright for an issue's root comment — which is the
/// issue body, and never appears in these threads.
async function deleteComment(id: string) {
try {
await invoke("edit_issue", {
rid: repo.rid,
cobId: issue.id,
action: {
type: "comment.redact",
id,
},
opts: { announce: $nodeRunning && $announce },
});
} catch (error) {
console.error("Issue comment deletion failed: ", error);
} finally {
await reload();
}
}
async function updateTitle(newTitle: string) {
try {
await invoke("edit_issue", {
@@ -453,6 +474,7 @@
{config}
{createComment}
{editComment}
{deleteComment}
{reactOnComment}
rid={repo.rid}
{activityItems}