Skip to content

Commit

Permalink
Avoid announcing changes when node is stopped
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebastinez authored and rudolfs committed Dec 6, 2024
1 parent 7d5ff0a commit ece9ee1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
8 changes: 6 additions & 2 deletions crates/radicle-types/src/traits/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -181,7 +183,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))
Expand Down
4 changes: 3 additions & 1 deletion crates/radicle-types/src/traits/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ pub trait PatchesMut: 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::patch::Patch::new(*patch.id(), &patch, &aliases))
Expand Down
8 changes: 6 additions & 2 deletions crates/radicle-types/src/traits/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<cobs::Never>::new(
Expand Down Expand Up @@ -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::<cobs::thread::CodeLocation>::new(
Expand Down
17 changes: 9 additions & 8 deletions src/views/repo/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -90,7 +91,7 @@
type: "label",
labels,
},
opts: { announce: $announce },
opts: { announce: $nodeRunning && $announce },
});
} catch (error) {
console.error("Editing labels failed", error);
Expand All @@ -110,7 +111,7 @@
type: "assign",
assignees,
},
opts: { announce: $announce },
opts: { announce: $nodeRunning && $announce },
});
} catch (error) {
console.error("Editing assignees failed", error);
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -205,7 +206,7 @@
body,
embeds,
},
opts: { announce: $announce },
opts: { announce: $nodeRunning && $announce },
});
} catch (error) {
console.error("Issue comment editing failed: ", error);
Expand All @@ -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);
Expand Down Expand Up @@ -262,7 +263,7 @@
({ did }) => publicKeyFromDid(did) === publicKey,
),
},
opts: { announce: $announce },
opts: { announce: $nodeRunning && $announce },
});
} catch (error) {
console.error("Editing reactions failed", error);
Expand All @@ -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);
Expand Down

0 comments on commit ece9ee1

Please sign in to comment.