notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

post_action_executor.rs (817B)


      1 use enostr::{FilledKeypair, RelayPool};
      2 use nostrdb::Note;
      3 use tracing::info;
      4 
      5 use crate::{draft::Draft, post::NewPost, ui::note::PostAction};
      6 
      7 pub struct PostActionExecutor {}
      8 
      9 impl PostActionExecutor {
     10     pub fn execute<'a>(
     11         poster: FilledKeypair<'_>,
     12         action: &'a PostAction,
     13         pool: &mut RelayPool,
     14         draft: &mut Draft,
     15         get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>,
     16     ) {
     17         match action {
     18             PostAction::Post(np) => {
     19                 let note = get_note(np, &poster.secret_key.to_secret_bytes());
     20 
     21                 let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
     22                 info!("sending {}", raw_msg);
     23                 pool.send(&enostr::ClientMessage::raw(raw_msg));
     24                 draft.clear();
     25             }
     26         }
     27     }
     28 }