commit f54d3b15963630f8963ecb51cb462d76966a0590
parent e20861f8d677f48eac16afeb725f15521f6be66f
Author: kernelkind <kernelkind@gmail.com>
Date: Sun, 5 Oct 2025 13:02:24 -0400
feat: copy damus.io link to clipboard
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/crates/notedeck/src/note/context.rs b/crates/notedeck/src/note/context.rs
@@ -18,6 +18,7 @@ pub enum NoteContextSelection {
CopyNoteId,
CopyNoteJSON,
Broadcast(BroadcastContext),
+ CopyLink,
}
#[derive(Debug, Eq, PartialEq, Clone)]
@@ -27,7 +28,13 @@ pub struct ContextSelection {
}
impl NoteContextSelection {
- pub fn process(&self, ui: &mut egui::Ui, note: &Note<'_>, pool: &mut RelayPool) {
+ pub fn process(
+ &self,
+ ui: &mut egui::Ui,
+ note: &Note<'_>,
+ pool: &mut RelayPool,
+ note_author_is_selected_acc: bool,
+ ) {
match self {
NoteContextSelection::Broadcast(context) => {
tracing::info!("Broadcasting note {}", hex::encode(note.id()));
@@ -58,6 +65,25 @@ impl NoteContextSelection {
Ok(json) => ui.ctx().copy_text(json),
Err(err) => error!("error copying note json: {err}"),
},
+ NoteContextSelection::CopyLink => {
+ let damus_url = |s| format!("https://damus.io/{s}");
+ if note_author_is_selected_acc {
+ let nip19event = nostr::nips::nip19::Nip19Event::new(
+ nostr::event::EventId::from_byte_array(*note.id()),
+ pool.urls(),
+ );
+ let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else {
+ return;
+ };
+ ui.ctx().copy_text(damus_url(bech));
+ } else {
+ let Some(bech) = NoteId::new(*note.id()).to_bech() else {
+ return;
+ };
+
+ ui.ctx().copy_text(damus_url(bech));
+ }
+ }
}
}
}
diff --git a/crates/notedeck_columns/src/actionbar.rs b/crates/notedeck_columns/src/actionbar.rs
@@ -165,7 +165,12 @@ fn execute_note_action(
NoteAction::Context(context) => match ndb.get_note_by_key(txn, context.note_key) {
Err(err) => tracing::error!("{err}"),
Ok(note) => {
- context.action.process(ui, ¬e, pool);
+ context.action.process(
+ ui,
+ ¬e,
+ pool,
+ *accounts.selected_account_pubkey().bytes() == *note.pubkey(),
+ );
}
},
NoteAction::Media(media_action) => {
diff --git a/crates/notedeck_ui/src/note/context.rs b/crates/notedeck_ui/src/note/context.rs
@@ -113,6 +113,18 @@ impl NoteContextButton {
stationary_arbitrary_menu_button(ui, button_response, |ui| {
ui.set_max_width(200.0);
+ if ui
+ .button(tr!(
+ i18n,
+ "Copy Link",
+ "Copy the damus.io link to this note to clipboard"
+ ))
+ .clicked()
+ {
+ context_selection = Some(NoteContextSelection::CopyLink);
+ ui.close_menu();
+ }
+
// Debug: Check what the tr! macro returns
let copy_text = tr!(
i18n,