notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit a85db81beb91112ede64b7e72159024151af3bde
parent 027971366c3ed32d12e75ffabe5dd2ed58c3fc3c
Author: alltheseas <alltheseas@users.noreply.github.com>
Date:   Tue,  4 Nov 2025 00:41:23 -0600

Rename note copy actions to nevent

Diffstat:
Mcrates/notedeck/src/note/context.rs | 56+++++++++++++++++++++++---------------------------------
Mcrates/notedeck_columns/src/actionbar.rs | 10+++-------
Mcrates/notedeck_ui/src/note/context.rs | 8++++----
3 files changed, 30 insertions(+), 44 deletions(-)

diff --git a/crates/notedeck/src/note/context.rs b/crates/notedeck/src/note/context.rs @@ -15,10 +15,10 @@ pub enum BroadcastContext { pub enum NoteContextSelection { CopyText, CopyPubkey, - CopyNoteId, + CopyNevent, CopyNoteJSON, Broadcast(BroadcastContext), - CopyLink, + CopyNeventLink, } #[derive(Debug, Eq, PartialEq, Clone)] @@ -27,18 +27,23 @@ pub struct ContextSelection { pub action: NoteContextSelection, } -const MAX_RELAY_HINTS: usize = 3; - -/// Collects at most `MAX_RELAY_HINTS` relay URLs where the note was actually observed. -/// We intentionally skip pool-based fallbacks: NIP-19 hints should only advertise relays -/// that are likely to store the event, and emitting no hint is preferable to speculating. +/// Collects relay URLs where the note was actually observed. fn relay_hints_for_note(note: &Note<'_>, txn: &Transaction) -> Vec<String> { note.relays(txn) - .take(MAX_RELAY_HINTS) .map(|relay| relay.to_owned()) .collect() } +fn note_nip19_event_bech(note: &Note<'_>, txn: &Transaction) -> Option<String> { + let relay_hints = relay_hints_for_note(note, txn); + let nip19event = nostr::nips::nip19::Nip19Event::new( + nostr::event::EventId::from_byte_array(*note.id()), + relay_hints, + ); + + nostr::nips::nip19::ToBech32::to_bech32(&nip19event).ok() +} + impl NoteContextSelection { pub fn process_selection( &self, @@ -46,7 +51,6 @@ impl NoteContextSelection { note: &Note<'_>, pool: &mut RelayPool, txn: &Transaction, - note_author_is_selected_acc: bool, ) { match self { NoteContextSelection::Broadcast(context) => { @@ -69,38 +73,24 @@ impl NoteContextSelection { ui.ctx().copy_text(bech); } } - NoteContextSelection::CopyNoteId => { - let relay_hints = relay_hints_for_note(note, txn); - let nip19event = nostr::nips::nip19::Nip19Event::new( - nostr::event::EventId::from_byte_array(*note.id()), - relay_hints, - ); - let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else { - return; - }; - ui.ctx().copy_text(bech); + NoteContextSelection::CopyNevent => { + if let Some(bech) = note_nip19_event_bech(note, txn) { + ui.ctx().copy_text(bech); + } } NoteContextSelection::CopyNoteJSON => match note.json() { Ok(json) => ui.ctx().copy_text(json), Err(err) => error!("error copying note json: {err}"), }, - NoteContextSelection::CopyLink => { + NoteContextSelection::CopyNeventLink => { let damus_url = |s| format!("https://damus.io/{s}"); - if note_author_is_selected_acc { - let relay_hints = relay_hints_for_note(note, txn); - let nip19event = nostr::nips::nip19::Nip19Event::new( - nostr::event::EventId::from_byte_array(*note.id()), - relay_hints, - ); - let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else { - return; - }; + if let Some(bech) = note_nip19_event_bech(note, txn) { ui.ctx().copy_text(damus_url(bech)); - } else { - let Some(bech) = NoteId::new(*note.id()).to_bech() else { - return; - }; + return; + } + // Fallback to event id without relay hints if encoding fails. + if let Some(bech) = NoteId::new(*note.id()).to_bech() { ui.ctx().copy_text(damus_url(bech)); } } diff --git a/crates/notedeck_columns/src/actionbar.rs b/crates/notedeck_columns/src/actionbar.rs @@ -189,13 +189,9 @@ 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_selection( - ui, - &note, - pool, - txn, - accounts.selected_account_pubkey().bytes() == note.pubkey(), - ); + context + .action + .process_selection(ui, &note, pool, txn); } }, NoteAction::Media(media_action) => { diff --git a/crates/notedeck_ui/src/note/context.rs b/crates/notedeck_ui/src/note/context.rs @@ -74,12 +74,12 @@ impl NoteContextButton { if ui .button(tr!( i18n, - "Copy Link", - "Copy the damus.io link to this note to clipboard" + "Copy nevent Link", + "Copy the damus.io nevent link for this note to clipboard" )) .clicked() { - context_selection = Some(NoteContextSelection::CopyLink); + context_selection = Some(NoteContextSelection::CopyNeventLink); ui.close_menu(); } @@ -114,7 +114,7 @@ impl NoteContextButton { )) .clicked() { - context_selection = Some(NoteContextSelection::CopyNoteId); + context_selection = Some(NoteContextSelection::CopyNevent); ui.close_menu(); } if ui