Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions crates/notedeck/src/note/context.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,12 +27,25 @@ pub struct ContextSelection {
pub action: NoteContextSelection,
}

const MAX_RELAY_HINTS: usize = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why cap it at 3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we had an issue on the ios side of massive nevent links that look really bad


/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would delete these lines, "where the note was actually observed" suffices IMO

fn relay_hints_for_note(note: &Note<'_>, txn: &Transaction) -> Vec<String> {
note.relays(txn)
.take(MAX_RELAY_HINTS)
.map(|relay| relay.to_owned())
.collect()
}

impl NoteContextSelection {
pub fn process_selection(
&self,
ui: &mut egui::Ui,
note: &Note<'_>,
pool: &mut RelayPool,
txn: &Transaction,
note_author_is_selected_acc: bool,
) {
match self {
Expand All @@ -57,9 +70,15 @@ impl NoteContextSelection {
}
}
NoteContextSelection::CopyNoteId => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should either rename CopyNoteId -> CopyNevent or create a new CopyNevent if we want to preserve copying the note id specifically

if let Some(bech) = NoteId::new(*note.id()).to_bech() {
ui.ctx().copy_text(bech);
}
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::CopyNoteJSON => match note.json() {
Ok(json) => ui.ctx().copy_text(json),
Expand All @@ -68,9 +87,10 @@ impl NoteContextSelection {
NoteContextSelection::CopyLink => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename this from CopyLink -> CopyNeventLink. It's confusing, since elsewhere we have an action for copying a profile link

let damus_url = |s| format!("https://damus.io/{s}");
if note_author_is_selected_acc {
let relay_hints = relay_hints_for_note(note, txn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use this for both, not just if the note author is the selected account

let nip19event = nostr::nips::nip19::Nip19Event::new(
nostr::event::EventId::from_byte_array(*note.id()),
pool.urls(),
relay_hints,
);
let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else {
return;
Expand Down
1 change: 1 addition & 0 deletions crates/notedeck_columns/src/actionbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ fn execute_note_action(
ui,
&note,
pool,
txn,
accounts.selected_account_pubkey().bytes() == note.pubkey(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/notedeck_ui/src/note/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl NoteContextButton {
if ui
.button(tr!(
i18n,
"Copy Note ID",
"Copy the unique note identifier to clipboard"
"Copy nevent ID",
"Copy the nevent identifier to clipboard"
))
.clicked()
{
Expand Down