mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Allow deleting discussion comments
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -857,6 +857,7 @@
|
||||
{config}
|
||||
createComment={createDiscussionComment}
|
||||
editComment={codeActions.editComment}
|
||||
deleteComment={codeActions.deleteComment}
|
||||
reactOnComment={codeActions.reactOnComment} />
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
@@ -1877,6 +1877,7 @@
|
||||
{config}
|
||||
{createComment}
|
||||
editComment={codeActions.editComment}
|
||||
deleteComment={codeActions.deleteComment}
|
||||
reactOnComment={codeActions.reactOnComment}
|
||||
{rid}
|
||||
{activityItems}
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user