-
Notifications
You must be signed in to change notification settings - Fork 49
Switch Copy Note ID to nevent #1183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f39154e
d44939a
0279713
a85db81
c826ec0
da12774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -27,12 +27,25 @@ 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. | ||
|
||
| 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 { | ||
|
|
@@ -57,9 +70,15 @@ impl NoteContextSelection { | |
| } | ||
| } | ||
| NoteContextSelection::CopyNoteId => { | ||
|
||
| 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), | ||
|
|
@@ -68,9 +87,10 @@ impl NoteContextSelection { | |
| NoteContextSelection::CopyLink => { | ||
|
||
| 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()), | ||
| pool.urls(), | ||
| relay_hints, | ||
| ); | ||
| let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else { | ||
| return; | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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