From 2d87b5fdb24c9e73c054d7e3c029fb7676aac7e8 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 frontend didn't update and the node just stopped in between we fallback gracefully instead of returning an error on the backend. --- 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 bc88180..cbe30f2 100644 --- a/crates/radicle-types/src/traits/issue.rs +++ b/crates/radicle-types/src/traits/issue.rs @@ -115,7 +115,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 fa2ad4b..a3a57f1 100644 --- a/crates/radicle-types/src/traits/thread.rs +++ b/crates/radicle-types/src/traits/thread.rs @@ -62,7 +62,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( @@ -103,7 +105,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 1da20f0..9cba474 100644 --- a/src/views/repo/Issue.svelte +++ b/src/views/repo/Issue.svelte @@ -32,6 +32,7 @@ import Layout from "./Layout.svelte"; import Sidebar from "@app/components/Sidebar.svelte"; + import { nodeRunning } from "@app/lib/events"; interface Props { repo: RepoInfo; @@ -113,7 +114,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. @@ -133,7 +134,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. @@ -159,7 +160,7 @@ body, embeds, }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); } catch (error) { console.error("Issue comment editing failed: ", error); @@ -183,7 +184,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); @@ -216,7 +217,7 @@ ({ did }) => publicKeyFromDid(did) === publicKey, ), }, - opts: { announce: $announce }, + opts: { announce: $nodeRunning && $announce }, }); } catch (error) { console.error("Editing reactions failed", error); @@ -234,7 +235,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);