diff --git a/desktop/crates/radicle-tauri/src/commands/cob/patch.rs b/desktop/crates/radicle-tauri/src/commands/cob/patch.rs index 2ad210cd0..574ad6e55 100644 --- a/desktop/crates/radicle-tauri/src/commands/cob/patch.rs +++ b/desktop/crates/radicle-tauri/src/commands/cob/patch.rs @@ -76,8 +76,9 @@ pub fn delete_patch( pub fn create_patch_review( ctx: tauri::State, args: models::patch::CreateReviewArgs, + opts: cobs::CobOptions, ) -> Result { - ctx.create_patch_review(args) + ctx.create_patch_review(args, opts) } #[tauri::command] diff --git a/desktop/crates/radicle-types/src/traits/patch.rs b/desktop/crates/radicle-types/src/traits/patch.rs index 8d9793465..c832779af 100644 --- a/desktop/crates/radicle-types/src/traits/patch.rs +++ b/desktop/crates/radicle-types/src/traits/patch.rs @@ -88,8 +88,10 @@ pub trait PatchesMut: Profile { fn create_patch_review( &self, args: models::patch::CreateReviewArgs, + opts: cobs::CobOptions, ) -> Result { let profile = self.profile(); + let mut node = Node::new(profile.home().socket_from_env()); let repo = profile.storage.repository(args.rid)?; let signer = profile.signer()?; let mut patches = profile.patches_mut(&repo, &signer)?; @@ -116,16 +118,28 @@ pub trait PatchesMut: Profile { args.labels, )?; - for comment in args.comments { - patch.review_comment( - review_id, - comment.body, - comment.location.map(Into::into), - None, - vec![], - )?; + // The review is written by now, so it is announced even if a comment + // fails: a retry can't add the missing comments, as it would hit the + // check above. + let comments = args.comments.into_iter().try_for_each(|comment| { + patch + .review_comment( + review_id, + comment.body, + comment.location.map(Into::into), + None, + vec![], + ) + .map(|_| ()) + }); + + if opts.announce() + && let Err(e) = node.announce_refs_for(args.rid, [profile.public_key]) + { + log::error!("Not able to announce changes: {}", e) } + comments?; Ok(review_id) } diff --git a/desktop/crates/test-http-api/src/api.rs b/desktop/crates/test-http-api/src/api.rs index 7c085cd9f..f8c90668c 100644 --- a/desktop/crates/test-http-api/src/api.rs +++ b/desktop/crates/test-http-api/src/api.rs @@ -1697,13 +1697,14 @@ async fn edit_patch_handler( #[serde(rename_all = "camelCase")] struct CreatePatchReviewBody { pub args: models::patch::CreateReviewArgs, + pub opts: CobOptions, } async fn create_patch_review_handler( Ctx(ctx): Ctx, - Json(CreatePatchReviewBody { args }): Json, + Json(CreatePatchReviewBody { args, opts }): Json, ) -> impl IntoResponse { - let review_id = ctx.create_patch_review(args)?; + let review_id = ctx.create_patch_review(args, opts)?; Ok::<_, Error>(Json(review_id)) } diff --git a/desktop/src/components/DraftReviewBar.svelte b/desktop/src/components/DraftReviewBar.svelte index 7672d43c9..200dadfec 100644 --- a/desktop/src/components/DraftReviewBar.svelte +++ b/desktop/src/components/DraftReviewBar.svelte @@ -8,10 +8,12 @@ import type { DraftReview } from "@app/lib/draftReviewStorage"; import { draftReviewStorage } from "@app/lib/draftReviewStorage"; + import { nodeRunning } from "@app/lib/events"; import { motion } from "@app/lib/motion"; import { formatAnchor } from "@app/lib/pierreComments"; import { isPublishableReview, verdictBadge } from "@app/lib/utils"; + import { announce } from "@app/components/AnnounceSwitch.svelte"; import Button from "@app/components/Button.svelte"; import Icon from "@app/components/Icon.svelte"; import Popover from "@app/components/Popover.svelte"; @@ -204,7 +206,10 @@ labels: draftReview.labels, }); const revisionId = draftReview.revisionId; - await draftReviewStorage.publish(draftReview.id); + await draftReviewStorage.publish( + draftReview.id, + $nodeRunning && $announce, + ); await onPublish(revisionId); } catch (error) { // The draft is only discarded once the review is on the network, so diff --git a/desktop/src/components/ReviewPage.svelte b/desktop/src/components/ReviewPage.svelte index 66a2172b2..432bd0820 100644 --- a/desktop/src/components/ReviewPage.svelte +++ b/desktop/src/components/ReviewPage.svelte @@ -15,6 +15,7 @@ import type { Config } from "@bindings/config/Config"; import type { FileDiff } from "@bindings/diff/FileDiff"; + import { pinned } from "@radicle-gui/ui/lib/query.svelte"; import { untrack } from "svelte"; import type { CommentOwner } from "@app/lib/codeCommentActions"; @@ -67,6 +68,7 @@ import Icon from "@app/components/Icon.svelte"; import Id from "@app/components/Id.svelte"; import Markdown from "@app/components/Markdown.svelte"; + import NewerBanner from "@app/components/NewerBanner.svelte"; import NodeId from "@app/components/NodeId.svelte"; import PierreDiff from "@app/components/PierreDiff.svelte"; import PierreTree from "@app/components/PierreTree.svelte"; @@ -203,6 +205,7 @@ savingSummary = false; editingSummary = false; await loadPatch(); + pinnedSummary.apply(); } } @@ -531,7 +534,19 @@ const verdict = $derived(review.verdict); const timestamp = $derived(review.timestamp); - const summary = $derived(review.summary?.trim() ?? ""); + // The summary is what the reader reads, so an edit by its author doesn't + // replace it until the reader asks for it, as with an issue's description. + // Comments and the verdict follow the patch as it changes. + const pinnedSummary = pinned(() => review.summary ?? ""); + // svelte-ignore state_referenced_locally + let pinnedReviewId = review.id; + $effect.pre(() => { + if (review.id !== pinnedReviewId) { + pinnedReviewId = review.id; + pinnedSummary.apply(); + } + }); + const summary = $derived(pinnedSummary.current.trim()); const backCaption = $derived( fromView === "changes" ? "Back to changes" : "Back to activity", ); @@ -955,6 +970,12 @@ {/if} + {#if pinnedSummary.stale && !editingSummary} + pinnedSummary.apply()} /> + {/if} {#if editingSummary}
{ await saveSummary(content, review.embeds); diff --git a/desktop/src/lib/draftReviewStorage.ts b/desktop/src/lib/draftReviewStorage.ts index b781f7b3a..5d777f666 100644 --- a/desktop/src/lib/draftReviewStorage.ts +++ b/desktop/src/lib/draftReviewStorage.ts @@ -253,7 +253,7 @@ export const draftReviewStorage = { }); }, - async publish(id: string) { + async publish(id: string, announce: boolean) { const draftReviewStored = storage.value[id]; if (!draftReviewStored) { throw new Error( @@ -276,6 +276,7 @@ export const draftReviewStorage = { location: storedComment.location ?? null, })), } satisfies CreateReviewArgs, + opts: { announce }, }); draftReviewStorage.delete(id); diff --git a/desktop/src/lib/writes.ts b/desktop/src/lib/writes.ts index 60e0e3b19..a11b474d8 100644 --- a/desktop/src/lib/writes.ts +++ b/desktop/src/lib/writes.ts @@ -32,8 +32,8 @@ export const mappedWrites = [ ]; // The keys a command's write affects, so that the user's own changes show -// whether or not the node announces them: it doesn't with announcing off, for -// reviews, or while it is stopped. Views that apply pinned state still wait +// whether or not the node announces them: it doesn't with announcing off or +// while it is stopped. Views that apply pinned state still wait // for their own refetch. export function writtenKeys( cmd: string, diff --git a/desktop/tests/e2e/repo/editingEmbeds.spec.ts b/desktop/tests/e2e/repo/editingEmbeds.spec.ts index bf72f62e8..f354e1f5d 100644 --- a/desktop/tests/e2e/repo/editingEmbeds.spec.ts +++ b/desktop/tests/e2e/repo/editingEmbeds.spec.ts @@ -73,6 +73,7 @@ async function reviewWithEmbed(page: Page, peer: RadiclePeer) { // Only reviews with comments get a page of their own. comments: [{ body: "Loud enough", location: null }], }, + opts: { announce: false }, })) as string; await api(page, peer, "edit_patch", { rid, @@ -257,6 +258,7 @@ test("ticking a task in a review of an older revision keeps its embeds", async ( labels: [], comments: [], }, + opts: { announce: false }, })) as string; await api(page, peer, "edit_patch", { rid, diff --git a/desktop/tests/unit/draftReviewStorage.test.ts b/desktop/tests/unit/draftReviewStorage.test.ts index 5e8e63389..41c7659b5 100644 --- a/desktop/tests/unit/draftReviewStorage.test.ts +++ b/desktop/tests/unit/draftReviewStorage.test.ts @@ -193,7 +193,7 @@ describe("draftReviewStorage", () => { const where = location("a.ts", "new", 3); drafts.addComment(id, { body: "nit", location: where }); - await drafts.publish(id); + await drafts.publish(id, true); expect(invoke).toHaveBeenCalledWith("create_patch_review", { args: { @@ -204,6 +204,7 @@ describe("draftReviewStorage", () => { labels: ["ok"], comments: [{ body: "nit", location: where }], }, + opts: { announce: true }, }); expect(drafts.get(id, alice)).toBeUndefined(); }); @@ -224,7 +225,7 @@ describe("draftReviewStorage", () => { ); const drafts = await load(); - await drafts.publish("old"); + await drafts.publish("old", false); expect(invoke.mock.calls[0][1].args.comments).toEqual([ { body: "general remark", location: null }, @@ -236,14 +237,14 @@ describe("draftReviewStorage", () => { const drafts = await load(); const id = drafts.create("rad:repo", "patch", "rev", aliceNid); - await expect(drafts.publish(id)).rejects.toThrow("offline"); + await expect(drafts.publish(id, false)).rejects.toThrow("offline"); expect(drafts.get(id, alice)?.id).toBe(id); }); test("rejects a draft that doesn't exist", async () => { const drafts = await load(); - await expect(drafts.publish("missing")).rejects.toThrow( + await expect(drafts.publish("missing", false)).rejects.toThrow( "Review missing does not exist", ); expect(invoke).not.toHaveBeenCalled();