diff --git a/src/lib.rs b/src/lib.rs index 22610e4..2362a9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,6 @@ mod nav; mod note; mod notecache; mod post; -mod post_action_executor; mod profile; pub mod relay_pool_manager; mod result; diff --git a/src/post_action_executor.rs b/src/post_action_executor.rs deleted file mode 100644 index 1cbb577..0000000 --- a/src/post_action_executor.rs +++ /dev/null @@ -1,28 +0,0 @@ -use enostr::{FilledKeypair, RelayPool}; -use nostrdb::Note; -use tracing::info; - -use crate::{draft::Draft, post::NewPost, ui::note::PostAction}; - -pub struct PostActionExecutor {} - -impl PostActionExecutor { - pub fn execute<'a>( - poster: FilledKeypair<'_>, - action: &'a PostAction, - pool: &mut RelayPool, - draft: &mut Draft, - get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>, - ) { - match action { - PostAction::Post(np) => { - let note = get_note(np, &poster.secret_key.to_secret_bytes()); - - let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap()); - info!("sending {}", raw_msg); - pool.send(&enostr::ClientMessage::raw(raw_msg)); - draft.clear(); - } - } - } -} diff --git a/src/timeline/route.rs b/src/timeline/route.rs index a7c5a83..3aca1f6 100644 --- a/src/timeline/route.rs +++ b/src/timeline/route.rs @@ -4,12 +4,14 @@ use crate::{ draft::Drafts, imgcache::ImageCache, notecache::NoteCache, - post_action_executor::PostActionExecutor, thread::Threads, timeline::TimelineId, ui::{ self, - note::{post::PostResponse, QuoteRepostView}, + note::{ + post::{PostAction, PostResponse}, + QuoteRepostView, + }, }, }; @@ -59,9 +61,7 @@ pub fn render_timeline_route( ui::timeline::postbox_view(ndb, kp, draft, img_cache, note_cache, ui); if let Some(action) = response.action { - PostActionExecutor::execute(kp, &action, pool, draft, |np, seckey| { - np.to_note(seckey) - }); + PostAction::execute(kp, &action, pool, draft, |np, seckey| np.to_note(seckey)); } } @@ -118,7 +118,7 @@ pub fn render_timeline_route( }); if let Some(action) = &response.inner.action { - PostActionExecutor::execute(poster, action, pool, draft, |np, seckey| { + PostAction::execute(poster, action, pool, draft, |np, seckey| { np.to_reply(seckey, ¬e) }); } @@ -148,7 +148,7 @@ pub fn render_timeline_route( }); if let Some(action) = &response.inner.action { - PostActionExecutor::execute(poster, action, pool, draft, |np, seckey| { + PostAction::execute(poster, action, pool, draft, |np, seckey| { np.to_quote(seckey, ¬e) }); } diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs index 93b5db5..c0aaf79 100644 --- a/src/ui/note/post.rs +++ b/src/ui/note/post.rs @@ -6,8 +6,9 @@ use crate::ui; use crate::ui::{Preview, PreviewConfig, View}; use egui::widgets::text_edit::TextEdit; use egui::{Frame, Layout}; -use enostr::{FilledKeypair, FullKeypair}; -use nostrdb::{Config, Ndb, Transaction}; +use enostr::{FilledKeypair, FullKeypair, RelayPool}; +use nostrdb::{Config, Ndb, Note, Transaction}; +use tracing::info; use super::contents::render_note_preview; @@ -25,6 +26,27 @@ pub enum PostAction { Post(NewPost), } +impl PostAction { + pub fn execute<'b>( + poster: FilledKeypair<'_>, + action: &'b PostAction, + pool: &mut RelayPool, + draft: &mut Draft, + get_note: impl Fn(&'b NewPost, &[u8; 32]) -> Note<'b>, + ) { + match action { + PostAction::Post(np) => { + let note = get_note(np, &poster.secret_key.to_secret_bytes()); + + let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap()); + info!("sending {}", raw_msg); + pool.send(&enostr::ClientMessage::raw(raw_msg)); + draft.clear(); + } + } + } +} + pub struct PostResponse { pub action: Option, pub edit_response: egui::Response,