From 2b5ca8d5917def40fbfc2118a999eaafdeb9a096 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 5 Dec 2024 09:04:06 +0100 Subject: [PATCH] Avoid announcing changes when node is stopped Also in the edge case that the front-end didn't update and the node just stopped in between we fallback gracefully instead of returning an error on the back-end. --- crates/radicle-types/src/traits/issue.rs | 4 +++- crates/radicle-types/src/traits/thread.rs | 8 ++++++-- src/views/repo/Issue.svelte | 13 +++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/radicle-types/src/traits/issue.rs b/crates/radicle-types/src/traits/issue.rs index bdee4dc..53ce0b6 100644 --- a/crates/radicle-types/src/traits/issue.rs +++ b/crates/radicle-types/src/traits/issue.rs @@ -114,7 +114,9 @@ pub trait IssuesMut: Profile { )?; if opts.announce() { - node.announce_refs(rid)?; + if let Err(e) = node.announce_refs(rid) { + eprintln!("Not able to announce changes: {}", e) + } } Ok::<_, Error>(cobs::issue::Issue::new(issue.id(), &issue, &aliases)) diff --git a/crates/radicle-types/src/traits/thread.rs b/crates/radicle-types/src/traits/thread.rs index 94b2698..2ed718e 100644 --- a/crates/radicle-types/src/traits/thread.rs +++ b/crates/radicle-types/src/traits/thread.rs @@ -61,7 +61,9 @@ pub trait Thread: Profile { )?; if opts.announce() { - node.announce_refs(rid)?; + if let Err(e) = node.announce_refs(rid) { + eprintln!("Not able to announce changes: {}", e) + } } Ok(cobs::thread::Comment::::new( @@ -102,7 +104,9 @@ pub trait Thread: Profile { )?; if opts.announce() { - node.announce_refs(rid)?; + if let Err(e) = node.announce_refs(rid) { + eprintln!("Not able to announce changes: {}", e) + } } Ok(cobs::thread::Comment::::new( diff --git a/src/views/repo/Issue.svelte b/src/views/repo/Issue.svelte index 80c7248..3ad7d9e 100644 --- a/src/views/repo/Issue.svelte +++ b/src/views/repo/Issue.svelte @@ -12,6 +12,7 @@ import * as roles from "@app/lib/roles"; import { invoke } from "@app/lib/invoke"; + import { nodeRunning } from "@app/lib/events"; import { publicKeyFromDid, scrollIntoView } from "@app/lib/utils"; import { announce } from "@app/components/AnnounceSwitch.svelte"; @@ -159,7 +160,7 @@ await invoke("create_issue_comment", { rid: repo.rid, new: { id: issue.id, body, embeds }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); // Update second column issue comment count without reloading the whole // issue list. @@ -179,7 +180,7 @@ await invoke("create_issue_comment", { rid: repo.rid, new: { id: issue.id, body, embeds, replyTo }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); // Update second column issue comment count without reloading the whole // issue list. @@ -205,7 +206,7 @@ body, embeds, }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); } catch (error) { console.error("Issue comment editing failed: ", error); @@ -229,7 +230,7 @@ id, title, }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); // Update second column issue title without reloading the whole issue list. const issueIndex = issues.findIndex(i => i.id === issue.id); @@ -262,7 +263,7 @@ ({ did }) => publicKeyFromDid(did) === publicKey, ), }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); } catch (error) { console.error("Editing reactions failed", error); @@ -280,7 +281,7 @@ type: "lifecycle", state, }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); // Update second column issue icon without reloading the whole issue list. const issueIndex = issues.findIndex(i => i.id === issue.id);