diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index cc5270923..fc9e77c07 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -45,6 +45,14 @@ caption?: string; // Marks a comment that is part of an unpublished draft review. draft?: boolean; + // Marks a comment whose thread has been dealt with. The review sidebar says + // this with a checkmark against a dimmed row; everywhere else the comment is + // shown at full strength, so it needs to say so itself. + resolved?: boolean; + // Names who resolved it, for the badge's tooltip. The comment carries only + // the flag, so the caller has to look this up (see `resolutionsByComment`); + // where it cannot, the badge says what it always said. + resolvedCaption?: string; origin?: CommentOrigin; timestamp?: number; lastEdit?: Edit; @@ -72,6 +80,8 @@ embeds, caption = "commented", draft = false, + resolved = false, + resolvedCaption, origin, timestamp, lastEdit, @@ -232,6 +242,23 @@ font: var(--txt-body-m-regular); color: var(--color-text-quaternary); } + /* Shaped and coloured like the verdict badge a review is headed with (see + `ReviewItem`), so the two green "this went well" marks read as one thing said + in two places. + + The font is declared rather than inherited: inside a diff this card is + slotted into Pierre's shadow tree, whose own font size is larger, and the + captions beside it each set their own — so an inheriting chip came out the + biggest thing on the line. */ + .resolved-chip { + flex-shrink: 0; + white-space: nowrap; + padding: 0.125rem 0.375rem; + border-radius: var(--border-radius-sm); + background-color: var(--color-feedback-success-bg); + color: var(--color-feedback-success-text); + font: var(--txt-body-s-regular); + } .menu { border: 1px solid var(--color-border-subtle); border-radius: var(--border-radius-md); @@ -286,6 +313,13 @@ • edited {/if} + {#if resolved} + + Resolved + + {/if}
{#if reactions && reactOnComment} Promise; + changeCommentStatus?: ( + commentId: string, + resolved: boolean, + ) => Promise; + // Whether the protocol lets the reader resolve a given comment. Without it + // the action is hidden, which is what a standalone revision comment gets. + canResolveComment?: (commentId: string) => boolean; + resolvedBy?: (commentId: string) => Resolution | undefined; } const { @@ -49,6 +58,9 @@ editComment, deleteComment, reactOnComment, + changeCommentStatus, + canResolveComment, + resolvedBy, }: Props = $props(); const noop = () => Promise.resolve(); @@ -69,6 +81,9 @@ editComment: editComment ?? noop, deleteComment, reactOnComment, + changeCommentStatus, + canResolveComment, + resolvedBy, }; } diff --git a/src/components/ReviewCommentList.svelte b/src/components/ReviewCommentList.svelte index 18357f787..94a411abe 100644 --- a/src/components/ReviewCommentList.svelte +++ b/src/components/ReviewCommentList.svelte @@ -4,9 +4,15 @@ import type { Comment } from "@bindings/cob/thread/Comment"; import type { Thread } from "@bindings/cob/thread/Thread"; + import type { Resolution } from "@app/lib/commentResolutions"; import type { CommentAnchor } from "@app/lib/pierreComments"; import { anchorOf, formatAnchorLines } from "@app/lib/pierreComments"; - import { pluralize, publicKeyFromDid, truncateId } from "@app/lib/utils"; + import { + formatResolvedCaption, + pluralize, + publicKeyFromDid, + truncateId, + } from "@app/lib/utils"; import Icon from "@app/components/Icon.svelte"; import Path from "@app/components/Path.svelte"; @@ -22,9 +28,19 @@ /// landed somewhere it did not. selectedId?: string; onSelect: (commentId: string, anchor: CommentAnchor | undefined) => void; + // Who resolved a comment, for the checkmark to name — the same tooltip the + // `Resolved` badge in the diff carries. + resolvedBy?: (commentId: string) => Resolution | undefined; } - const { groups, selectedId, onSelect }: Props = $props(); + const { groups, selectedId, onSelect, resolvedBy }: Props = $props(); + + function resolvedTitle(commentId: string): string { + const resolution = resolvedBy?.(commentId); + return resolution + ? formatResolvedCaption(resolution.author, resolution.timestamp) + : "Marked as resolved"; + } const threads = $derived(groups.flatMap(group => group.threads)); const resolved = $derived( @@ -234,7 +250,9 @@ {authorName(thread.root.author)} commented {#if isResolved} - + + + {/if} {#if lines} {lines} diff --git a/src/components/ReviewPage.svelte b/src/components/ReviewPage.svelte index 86ead6b97..c057cd8b6 100644 --- a/src/components/ReviewPage.svelte +++ b/src/components/ReviewPage.svelte @@ -2,6 +2,8 @@ import type { CommentOrigin } from "@app/components/Comment.svelte"; import type { PatchView } from "@app/views/repo/router"; import type { Author } from "@bindings/cob/Author"; + import type { Operation } from "@bindings/cob/Operation"; + import type { Action } from "@bindings/cob/patch/Action"; import type { Patch } from "@bindings/cob/patch/Patch"; import type { Review } from "@bindings/cob/patch/Review"; import type { Revision } from "@bindings/cob/patch/Revision"; @@ -18,6 +20,7 @@ import type { CommentOwner } from "@app/lib/codeCommentActions"; import { commentActions } from "@app/lib/codeCommentActions"; import type { CodeComments } from "@app/lib/codeComments"; + import { resolutionsByComment } from "@app/lib/commentResolutions"; import { diffOptions } from "@app/lib/diffOptions.svelte"; import { fileDiffPath, fileMetaOf, fullFileLoader } from "@app/lib/diffText"; import { nodeRunning } from "@app/lib/events"; @@ -64,23 +67,40 @@ repoDelegates: Author[]; review: Review; revisions: Revision[]; + // The patch's operation log, which is the only place that records who + // resolved a comment (see `resolutionsByComment`). + activity: Operation[]; rid: string; status: Patch["state"]["status"] | undefined; // The tab this review was opened from, so leaving it returns there. fromView?: PatchView; + // An output binding, as on the Changes tab: the topbar renders the toggle + // and reads this, while the collapsing happens here. + filesExpanded?: boolean; + // Whether there is anything to collapse. The view shows only the files a + // comment is anchored in, so a review with none has no file column at all + // and the topbar's toggle would act on nothing. + hasFiles?: boolean; } - const { + /* eslint-disable prefer-const */ + let { config, loadPatch, patch, repoDelegates, review, revisions, + activity, rid, status, fromView, + // Only ever written by `setAllFilesCollapsed`, which the topbar calls. + // eslint-disable-next-line no-useless-assignment + filesExpanded = $bindable(true), + hasFiles = $bindable(false), }: Props = $props(); + /* eslint-enable prefer-const */ const isOwnPublishedReview = $derived( review.author.did === didFromPublicKey(config.publicKey), @@ -395,6 +415,17 @@ // nothing about is context they can already read on the Changes tab. const commentedPaths = $derived(new Set(fileGroups.map(g => g.path))); + $effect(() => { + const next = commentedPaths.size > 0; + if (hasFiles !== next) { + hasFiles = next; + } + }); + + const resolutions = $derived(resolutionsByComment(activity)); + function resolvedBy(commentId: string) { + return resolutions.get(commentId); + } const reviewCodeComments: CodeComments = $derived({ config, @@ -409,6 +440,7 @@ deleteComment: codeActions.deleteComment, changeCommentStatus: codeActions.changeCommentStatus, canResolveComment, + resolvedBy, reactOnComment: codeActions.reactOnComment, }); @@ -466,6 +498,13 @@ let diffView = $state | undefined>(); + /// Forwarded to the diff so the topbar, which the patch view renders, can + /// collapse or expand every file. + export function setAllFilesCollapsed(collapsed: boolean) { + filesExpanded = !collapsed; + diffView?.setAllCollapsed(collapsed); + } + // The comment the sidebar last jumped to, marked at both ends — the row that // was clicked and the comment it points at. Held long enough to be noticed and // then dropped, so neither keeps a stale mark on it. @@ -922,6 +961,7 @@
diff --git a/src/components/Revision.svelte b/src/components/Revision.svelte index 40565a7f1..9c649ab68 100644 --- a/src/components/Revision.svelte +++ b/src/components/Revision.svelte @@ -18,6 +18,7 @@ import type { CommentOwner } from "@app/lib/codeCommentActions"; import { commentActions } from "@app/lib/codeCommentActions"; import type { CodeComments } from "@app/lib/codeComments"; + import { resolutionsByComment } from "@app/lib/commentResolutions"; import { STANDALONE_COMMENTS } from "@app/lib/commentSources"; import { diffOptions } from "@app/lib/diffOptions.svelte"; import { fileDiffPath, fileStatusLabel } from "@app/lib/diffText"; @@ -491,6 +492,13 @@ // The protocol lets the comment author, the review author or the revision // author resolve a review comment; delegates may do anything. Standalone // revision comments have no resolve action at all. + // A comment records only that it is resolved, so who did it has to come from + // the patch's operation log. + const resolutions = $derived(resolutionsByComment(activity)); + function resolvedBy(commentId: string) { + return resolutions.get(commentId); + } + function canResolveComment(commentId: string): boolean { const owner = ownerOf(commentId); if (owner?.kind !== "review") return false; @@ -588,6 +596,7 @@ deleteComment: codeActions.deleteComment, changeCommentStatus: codeActions.changeCommentStatus, canResolveComment, + resolvedBy, reactOnComment: codeActions.reactOnComment, repoDelegates, rid, @@ -613,6 +622,7 @@ deleteComment: codeActions.deleteComment, changeCommentStatus: codeActions.changeCommentStatus, canResolveComment, + resolvedBy, reactOnComment: codeActions.reactOnComment, repoDelegates, rid, @@ -1829,7 +1839,10 @@ createComment={createCodeComment} editComment={codeActions.editComment} deleteComment={codeActions.deleteComment} - reactOnComment={codeActions.reactOnComment} /> + reactOnComment={codeActions.reactOnComment} + changeCommentStatus={codeActions.changeCommentStatus} + {canResolveComment} + {resolvedBy} /> {/each}
{/if} diff --git a/src/components/Thread.svelte b/src/components/Thread.svelte index 027fd0528..ff390e80f 100644 --- a/src/components/Thread.svelte +++ b/src/components/Thread.svelte @@ -8,7 +8,8 @@ import { tick } from "svelte"; - import { scrollIntoView } from "@app/lib/utils"; + import type { Resolution } from "@app/lib/commentResolutions"; + import { formatResolvedCaption, scrollIntoView } from "@app/lib/utils"; import CommentComponent from "@app/components/Comment.svelte"; import ExtendedTextarea from "@app/components/ExtendedTextarea.svelte"; @@ -53,6 +54,9 @@ // A single comment to ring, so a jump from elsewhere can say where it // landed. Marks that one comment, root or reply, not the thread around it. highlightedCommentId?: string; + // Who resolved a comment, for its badge to name. Looked up rather than read + // off the comment, which carries only the flag (see `resolutionsByComment`). + resolvedBy?: (commentId: string) => Resolution | undefined; } const { @@ -71,8 +75,17 @@ origin, hoverNote, highlightedCommentId, + resolvedBy, }: Props = $props(); + function resolvedCaption(commentId: string): string | undefined { + const resolution = resolvedBy?.(commentId); + return ( + resolution && + formatResolvedCaption(resolution.author, resolution.timestamp) + ); + } + async function toggleReply() { showReplyForm = !showReplyForm; if (!showReplyForm) { @@ -200,6 +213,8 @@ id={reply.id} author={reply.author} caption="replied" + resolved={reply.resolved} + resolvedCaption={resolvedCaption(reply.id)} reactions={reply.reactions} timestamp={reply.edits[0].timestamp} body={reply.edits.slice(-1)[0].body} @@ -248,6 +263,8 @@ {draft} {origin} {hoverNote} + resolved={root.resolved} + resolvedCaption={resolvedCaption(root.id)} id={root.id} lastEdit={root.edits.length > 1 ? root.edits.at(-1) : undefined} author={root.author} @@ -265,8 +282,11 @@ + changeCommentStatus(root.id, !root.resolved)} /> {/if} diff --git a/src/lib/codeComments.ts b/src/lib/codeComments.ts index 3eeaed911..40d03364c 100644 --- a/src/lib/codeComments.ts +++ b/src/lib/codeComments.ts @@ -4,6 +4,8 @@ import type { Embed } from "@bindings/cob/thread/Embed"; import type { Thread } from "@bindings/cob/thread/Thread"; import type { Config } from "@bindings/config/Config"; +import type { Resolution } from "@app/lib/commentResolutions"; + /// Says where a comment lives when a view mixes comments from several places — /// a review's own comments and comments left directly on a revision look alike /// otherwise, but they differ in what can be done to them. @@ -23,6 +25,10 @@ export interface CodeComments { // Decided by the host: the protocol allows the comment author, the review // author or the revision author, and only the host knows all three. canResolveComment?: (commentId: string) => boolean; + // Who resolved a comment, for the resolved badge to name. Only the host can + // say: it comes from the patch's operation log rather than from the comment + // (see `resolutionsByComment`). + resolvedBy?: (commentId: string) => Resolution | undefined; config: Config; createComment: ( body: string, diff --git a/src/lib/commentResolutions.ts b/src/lib/commentResolutions.ts new file mode 100644 index 000000000..db233b203 --- /dev/null +++ b/src/lib/commentResolutions.ts @@ -0,0 +1,37 @@ +import type { Author } from "@bindings/cob/Author"; +import type { Operation } from "@bindings/cob/Operation"; +import type { Action } from "@bindings/cob/patch/Action"; + +export interface Resolution { + author: Author; + timestamp: number; +} + +/// Who last resolved each comment, taken from the patch's own operation log. +/// +/// A `Comment` records only *that* it is resolved: `radicle`'s thread applies the +/// resolve op without keeping hold of its actor, so the comment itself cannot say +/// who. The op that did it is authored, though, so the log still can. +/// +/// Unresolving drops the entry again, which is what leaves a comment that was +/// resolved and then reopened without one — matching `resolved: false` on the +/// comment. A revision's `resolves` set is deliberately not read: it records what +/// a revision claims to address and never marks a comment resolved. +export function resolutionsByComment( + activity: Operation[], +): Map { + const resolutions = new Map(); + for (const op of [...activity].sort((a, b) => a.timestamp - b.timestamp)) { + for (const action of op.actions) { + if (action.type === "review.comment.resolve") { + resolutions.set(action.comment, { + author: op.author, + timestamp: op.timestamp, + }); + } else if (action.type === "review.comment.unresolve") { + resolutions.delete(action.comment); + } + } + } + return resolutions; +} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d6a3db860..22b5a9e16 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -204,6 +204,10 @@ export function formatEditedCaption(author: Author, timestamp: number) { return `${author.alias ? author.alias : truncateDid(author.did)} edited ${absoluteTimestamp(timestamp)}`; } +export function formatResolvedCaption(author: Author, timestamp: number) { + return `${author.alias ? author.alias : truncateDid(author.did)} resolved this ${absoluteTimestamp(timestamp)}`; +} + export function pluralize(singular: string, count: number): string { if (count === 1) return singular; if (/(?:ch|sh|s|x|z)$/i.test(singular)) { diff --git a/src/views/repo/Patch.svelte b/src/views/repo/Patch.svelte index b2c02decf..b86c243b1 100644 --- a/src/views/repo/Patch.svelte +++ b/src/views/repo/Patch.svelte @@ -1546,6 +1546,7 @@ repoDelegates={repo.delegates} review={currentReview} {revisions} + {activity} rid={repo.rid} {status} fromView={patchView} />