notedeck

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

commit dbb164970c0e20e1b2ab1c97fb856b1116aa53b7
parent 13d6873eb182474931bef36de3d355e171dbb4f7
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 26 Sep 2024 08:00:12 -0700

remove PostActionExecutor

Just use PostAction::execute

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/lib.rs | 1-
Dsrc/post_action_executor.rs | 28----------------------------
Msrc/timeline/route.rs | 14+++++++-------
Msrc/ui/note/post.rs | 26++++++++++++++++++++++++--
4 files changed, 31 insertions(+), 38 deletions(-)

diff --git 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 @@ -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 @@ -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, &note) }); } @@ -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, &note) }); } diff --git 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<PostAction>, pub edit_response: egui::Response,