feat: copy damus.io link to clipboard

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-10-05 13:02:24 -04:00
parent e20861f8d6
commit f54d3b1596
3 changed files with 45 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ pub enum NoteContextSelection {
CopyNoteId, CopyNoteId,
CopyNoteJSON, CopyNoteJSON,
Broadcast(BroadcastContext), Broadcast(BroadcastContext),
CopyLink,
} }
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
@@ -27,7 +28,13 @@ pub struct ContextSelection {
} }
impl NoteContextSelection { 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 { match self {
NoteContextSelection::Broadcast(context) => { NoteContextSelection::Broadcast(context) => {
tracing::info!("Broadcasting note {}", hex::encode(note.id())); tracing::info!("Broadcasting note {}", hex::encode(note.id()));
@@ -58,6 +65,25 @@ impl NoteContextSelection {
Ok(json) => ui.ctx().copy_text(json), Ok(json) => ui.ctx().copy_text(json),
Err(err) => error!("error copying note json: {err}"), 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));
}
}
} }
} }
} }

View File

@@ -165,7 +165,12 @@ fn execute_note_action(
NoteAction::Context(context) => match ndb.get_note_by_key(txn, context.note_key) { NoteAction::Context(context) => match ndb.get_note_by_key(txn, context.note_key) {
Err(err) => tracing::error!("{err}"), Err(err) => tracing::error!("{err}"),
Ok(note) => { Ok(note) => {
context.action.process(ui, &note, pool); context.action.process(
ui,
&note,
pool,
*accounts.selected_account_pubkey().bytes() == *note.pubkey(),
);
} }
}, },
NoteAction::Media(media_action) => { NoteAction::Media(media_action) => {

View File

@@ -113,6 +113,18 @@ impl NoteContextButton {
stationary_arbitrary_menu_button(ui, button_response, |ui| { stationary_arbitrary_menu_button(ui, button_response, |ui| {
ui.set_max_width(200.0); 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 // Debug: Check what the tr! macro returns
let copy_text = tr!( let copy_text = tr!(
i18n, i18n,