commit 0de538af1a775bf9f954d80bf221659b75009962 Author: William Casarin Date: Thu Sep 26 08:00:12 2024 -0700 remove PostActionExecutor Just use PostAction::execute Signed-off-by: William Casarin diff --git a/src/lib.rs b/src/lib.rs index 22610e4ce258..2362a9dfcd9b 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/nav.rs b/src/nav.rs index dadde3c1f1c8..0b5a5051027d 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -1,6 +1,5 @@ use crate::{ account_manager::render_accounts_route, - post_action_executor::PostActionExecutor, relay_pool_manager::RelayPoolManager, route::Route, thread::thread_unsubscribe, @@ -66,7 +65,7 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) { .ui(&txn, ui); if let Some(action) = post_response.action { - PostActionExecutor::execute(kp, &action, &mut app.pool, draft, |np, seckey| { + PostAction::execute(kp, &action, &mut app.pool, draft, |np, seckey| { np.to_note(seckey) }); } diff --git a/src/post_action_executor.rs b/src/post_action_executor.rs deleted file mode 100644 index 1cbb5772ac82..000000000000 --- 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 0ec381f67372..941002e5b79b 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, + }, }, }; @@ -104,7 +106,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) }); } @@ -134,7 +136,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 93b5db5aab49..c0aaf7983a57 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,