desktop: Announce published reviews

Publishing a review was the only patch write that didn't announce, so
other instances of the app on the same node never learned of it. A
review's summary now also stays as it is while someone else edits it,
showing that a newer one is available, as an issue's description does.
This commit is contained in:
Rūdolfs Ošiņš
2026-11-20 19:32:17 +01:00
parent 5efbdb5ed1
commit e9c519068d
9 changed files with 67 additions and 21 deletions
@@ -76,8 +76,9 @@ pub fn delete_patch(
pub fn create_patch_review(
ctx: tauri::State<AppState>,
args: models::patch::CreateReviewArgs,
opts: cobs::CobOptions,
) -> Result<ReviewId, Error> {
ctx.create_patch_review(args)
ctx.create_patch_review(args, opts)
}
#[tauri::command]
@@ -88,8 +88,10 @@ pub trait PatchesMut: Profile {
fn create_patch_review(
&self,
args: models::patch::CreateReviewArgs,
opts: cobs::CobOptions,
) -> Result<cob::patch::ReviewId, Error> {
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)
}
+3 -2
View File
@@ -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<CreatePatchReviewBody>,
Json(CreatePatchReviewBody { args, opts }): Json<CreatePatchReviewBody>,
) -> impl IntoResponse {
let review_id = ctx.create_patch_review(args)?;
let review_id = ctx.create_patch_review(args, opts)?;
Ok::<_, Error>(Json(review_id))
}
+6 -1
View File
@@ -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
+23 -2
View File
@@ -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}
</div>
{#if pinnedSummary.stale && !editingSummary}
<NewerBanner
message="The summary has been edited."
margin="0 0 0.5rem"
onShow={() => pinnedSummary.apply()} />
{/if}
{#if editingSummary}
<div>
<ExtendedTextarea
@@ -975,7 +996,7 @@
<Markdown
{rid}
breaks
content={review.summary ?? ""}
content={pinnedSummary.current}
toggleTaskItem={isOwnPublishedReview
? async content => {
await saveSummary(content, review.embeds);
+2 -1
View File
@@ -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);
+2 -2
View File
@@ -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,
@@ -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,
@@ -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();