mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-17 16:54:18 +01:00
feat: copy damus.io link to clipboard
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ pub enum NoteContextSelection {
|
||||
CopyNoteId,
|
||||
CopyNoteJSON,
|
||||
Broadcast(BroadcastContext),
|
||||
CopyLink,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
@@ -27,7 +28,13 @@ pub struct ContextSelection {
|
||||
}
|
||||
|
||||
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 {
|
||||
NoteContextSelection::Broadcast(context) => {
|
||||
tracing::info!("Broadcasting note {}", hex::encode(note.id()));
|
||||
@@ -58,6 +65,25 @@ impl NoteContextSelection {
|
||||
Ok(json) => ui.ctx().copy_text(json),
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,12 @@ 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(ui, ¬e, pool);
|
||||
context.action.process(
|
||||
ui,
|
||||
¬e,
|
||||
pool,
|
||||
*accounts.selected_account_pubkey().bytes() == *note.pubkey(),
|
||||
);
|
||||
}
|
||||
},
|
||||
NoteAction::Media(media_action) => {
|
||||
|
||||
@@ -113,6 +113,18 @@ impl NoteContextButton {
|
||||
stationary_arbitrary_menu_button(ui, button_response, |ui| {
|
||||
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
|
||||
let copy_text = tr!(
|
||||
i18n,
|
||||
|
||||
Reference in New Issue
Block a user