notedeck

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

commit 8b0086ac6b99ae6fcf5e312029aefe45ecff2466
parent 8353a737042b055e620c27335b5a466c5ead241b
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  4 Dec 2025 01:13:57 -0800

Merge copy nevent by elsat #1183

William Casarin (2):
      context: fix capitalization

alltheseas (6):
      Switch Copy Note ID to nevent
      Include relay hints when copying note IDs
      Refine nevent relay hints
      Rename note copy actions to nevent
      Format with cargo fmt
      Update context.rs

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

diff --git a/crates/notedeck/src/note/context.rs b/crates/notedeck/src/note/context.rs @@ -1,5 +1,5 @@ use enostr::{ClientMessage, NoteId, Pubkey, RelayPool}; -use nostrdb::{Note, NoteKey}; +use nostrdb::{Note, NoteKey, Transaction}; use tracing::error; /// When broadcasting notes, this determines whether to broadcast @@ -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,13 +27,28 @@ pub struct ContextSelection { pub action: NoteContextSelection, } +/// Collects relay URLs where the note was actually observed. +fn relay_hints_for_note(note: &Note<'_>, txn: &Transaction) -> Vec<String> { + note.relays(txn).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, ui: &mut egui::Ui, note: &Note<'_>, pool: &mut RelayPool, - note_author_is_selected_acc: bool, + txn: &Transaction, ) { match self { NoteContextSelection::Broadcast(context) => { @@ -56,8 +71,8 @@ impl NoteContextSelection { ui.ctx().copy_text(bech); } } - NoteContextSelection::CopyNoteId => { - if let Some(bech) = NoteId::new(*note.id()).to_bech() { + NoteContextSelection::CopyNevent => { + if let Some(bech) = note_nip19_event_bech(note, txn) { ui.ctx().copy_text(bech); } } @@ -65,22 +80,15 @@ impl NoteContextSelection { 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 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; - }; + 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 @@ -190,12 +190,7 @@ 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, - 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 Note Link", + "Copy the damus.io note link for this note to clipboard" )) .clicked() { - context_selection = Some(NoteContextSelection::CopyLink); + context_selection = Some(NoteContextSelection::CopyNeventLink); ui.close_menu(); } @@ -110,11 +110,11 @@ impl NoteContextButton { .button(tr!( i18n, "Copy Note ID", - "Copy the unique note identifier to clipboard" + "Copy the note identifier to clipboard" )) .clicked() { - context_selection = Some(NoteContextSelection::CopyNoteId); + context_selection = Some(NoteContextSelection::CopyNevent); ui.close_menu(); } if ui