Skip to main content

cosmic_applet_avestruz/handlers/
share.rs

1// SPDX-License-Identifier: MIT
2
3//! Sharing a note: copying a link to it that anyone can open.
4
5use cosmic::iced::clipboard;
6use cosmic::prelude::*;
7use nostr_sdk::prelude::EventId;
8
9use crate::messages::Message;
10use crate::nostr::share::share_link;
11use crate::state::AppModel;
12
13impl AppModel {
14    /// Put a link to the note `id` on the clipboard (see
15    /// [`share_link`]), naming the relays it was seen on, and have its
16    /// row say so. Nothing is copied of a note that is no longer at hand:
17    /// its row is not there to be pressed.
18    pub fn handle_copy_share_link(&mut self, id: EventId) -> Task<cosmic::Action<Message>> {
19        let Some(note) = self.note_at_hand(id) else {
20            return Task::none();
21        };
22        let seen_on = self.seen_on.get(&id).map(Vec::as_slice).unwrap_or_default();
23        let link = share_link(note.id, note.author, note.kind, seen_on);
24        self.share_copied = Some(id);
25        self.picture_copied = None;
26        clipboard::write(link)
27    }
28}