mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-21 09:14:19 +01:00
remove PostActionExecutor
Just use PostAction::execute Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<PostAction>,
|
||||
pub edit_response: egui::Response,
|
||||
|
||||
Reference in New Issue
Block a user