diff --git a/crates/notedeck/src/note/context.rs b/crates/notedeck/src/note/context.rs index a804da5..59e973d 100644 --- 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 index d613395..34fe88d 100644 --- 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 index 051d94d..0e51caa 100644 --- 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,