remove PostActionExecutor

Just use PostAction::execute

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-09-26 08:00:12 -07:00
parent 13d6873eb1
commit dbb164970c
4 changed files with 31 additions and 38 deletions

View File

@@ -25,7 +25,6 @@ mod nav;
mod note; mod note;
mod notecache; mod notecache;
mod post; mod post;
mod post_action_executor;
mod profile; mod profile;
pub mod relay_pool_manager; pub mod relay_pool_manager;
mod result; mod result;

View File

@@ -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();
}
}
}
}

View File

@@ -4,12 +4,14 @@ use crate::{
draft::Drafts, draft::Drafts,
imgcache::ImageCache, imgcache::ImageCache,
notecache::NoteCache, notecache::NoteCache,
post_action_executor::PostActionExecutor,
thread::Threads, thread::Threads,
timeline::TimelineId, timeline::TimelineId,
ui::{ ui::{
self, 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); ui::timeline::postbox_view(ndb, kp, draft, img_cache, note_cache, ui);
if let Some(action) = response.action { if let Some(action) = response.action {
PostActionExecutor::execute(kp, &action, pool, draft, |np, seckey| { PostAction::execute(kp, &action, pool, draft, |np, seckey| np.to_note(seckey));
np.to_note(seckey)
});
} }
} }
@@ -118,7 +118,7 @@ pub fn render_timeline_route(
}); });
if let Some(action) = &response.inner.action { 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, &note) np.to_reply(seckey, &note)
}); });
} }
@@ -148,7 +148,7 @@ pub fn render_timeline_route(
}); });
if let Some(action) = &response.inner.action { 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, &note) np.to_quote(seckey, &note)
}); });
} }

View File

@@ -6,8 +6,9 @@ use crate::ui;
use crate::ui::{Preview, PreviewConfig, View}; use crate::ui::{Preview, PreviewConfig, View};
use egui::widgets::text_edit::TextEdit; use egui::widgets::text_edit::TextEdit;
use egui::{Frame, Layout}; use egui::{Frame, Layout};
use enostr::{FilledKeypair, FullKeypair}; use enostr::{FilledKeypair, FullKeypair, RelayPool};
use nostrdb::{Config, Ndb, Transaction}; use nostrdb::{Config, Ndb, Note, Transaction};
use tracing::info;
use super::contents::render_note_preview; use super::contents::render_note_preview;
@@ -25,6 +26,27 @@ pub enum PostAction {
Post(NewPost), 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 struct PostResponse {
pub action: Option<PostAction>, pub action: Option<PostAction>,
pub edit_response: egui::Response, pub edit_response: egui::Response,