make PostActionExecutor for code reuse
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ 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;
|
||||||
|
|||||||
29
src/post_action_executor.rs
Normal file
29
src/post_action_executor.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use enostr::{FilledKeypair, RelayPool};
|
||||||
|
use nostrdb::Note;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
|
use crate::{draft::Drafts, post::NewPost, ui::note::PostAction};
|
||||||
|
|
||||||
|
pub struct PostActionExecutor {}
|
||||||
|
|
||||||
|
impl PostActionExecutor {
|
||||||
|
pub fn execute<'a>(
|
||||||
|
poster: &FilledKeypair<'_>,
|
||||||
|
action: &'a PostAction,
|
||||||
|
pool: &mut RelayPool,
|
||||||
|
drafts: &mut Drafts,
|
||||||
|
get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>,
|
||||||
|
clear_draft: impl Fn(&mut Drafts),
|
||||||
|
) {
|
||||||
|
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));
|
||||||
|
clear_draft(drafts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
use enostr::{FilledKeypair, RelayPool};
|
use enostr::{FilledKeypair, RelayPool};
|
||||||
use nostrdb::Ndb;
|
use nostrdb::Ndb;
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
use crate::{draft::Drafts, imgcache::ImageCache, notecache::NoteCache, ui};
|
use crate::{
|
||||||
|
draft::Drafts, imgcache::ImageCache, notecache::NoteCache,
|
||||||
|
post_action_executor::PostActionExecutor, ui,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{PostAction, PostResponse};
|
use super::PostResponse;
|
||||||
|
|
||||||
pub struct QuoteRepostView<'a> {
|
pub struct QuoteRepostView<'a> {
|
||||||
ndb: &'a Ndb,
|
ndb: &'a Ndb,
|
||||||
@@ -59,18 +61,16 @@ impl<'a> QuoteRepostView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(action) = &post_response.action {
|
if let Some(action) = &post_response.action {
|
||||||
match action {
|
PostActionExecutor::execute(
|
||||||
PostAction::Post(np) => {
|
&self.poster,
|
||||||
let seckey = self.poster.secret_key.to_secret_bytes();
|
action,
|
||||||
|
self.pool,
|
||||||
let note = np.to_quote(&seckey, self.quoting_note);
|
self.drafts,
|
||||||
|
|np, seckey| np.to_quote(seckey, self.quoting_note),
|
||||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
|drafts| {
|
||||||
info!("sending {}", raw_msg);
|
drafts.quote_mut(quoting_note_id).clear();
|
||||||
self.pool.send(&enostr::ClientMessage::raw(raw_msg));
|
},
|
||||||
self.drafts.quote_mut(quoting_note_id).clear();
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
post_response
|
post_response
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::draft::Drafts;
|
use crate::draft::Drafts;
|
||||||
use crate::imgcache::ImageCache;
|
use crate::imgcache::ImageCache;
|
||||||
use crate::notecache::NoteCache;
|
use crate::notecache::NoteCache;
|
||||||
|
use crate::post_action_executor::PostActionExecutor;
|
||||||
use crate::ui;
|
use crate::ui;
|
||||||
use crate::ui::note::{PostAction, PostResponse};
|
use crate::ui::note::PostResponse;
|
||||||
use enostr::{FilledKeypair, RelayPool};
|
use enostr::{FilledKeypair, RelayPool};
|
||||||
use nostrdb::Ndb;
|
use nostrdb::Ndb;
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
pub struct PostReplyView<'a> {
|
pub struct PostReplyView<'a> {
|
||||||
ndb: &'a Ndb,
|
ndb: &'a Ndb,
|
||||||
@@ -93,18 +93,16 @@ impl<'a> PostReplyView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(action) = &post_response.action {
|
if let Some(action) = &post_response.action {
|
||||||
match action {
|
PostActionExecutor::execute(
|
||||||
PostAction::Post(np) => {
|
&self.poster,
|
||||||
let seckey = self.poster.secret_key.to_secret_bytes();
|
action,
|
||||||
|
self.pool,
|
||||||
let note = np.to_reply(&seckey, self.note);
|
self.drafts,
|
||||||
|
|np, seckey| np.to_reply(seckey, self.note),
|
||||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
|drafts| {
|
||||||
info!("sending {}", raw_msg);
|
drafts.reply_mut(replying_to).clear();
|
||||||
self.pool.send(&enostr::ClientMessage::raw(raw_msg));
|
},
|
||||||
self.drafts.reply_mut(replying_to).clear();
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
use crate::post_action_executor::PostActionExecutor;
|
||||||
use crate::{
|
use crate::{
|
||||||
actionbar::BarAction, column::Columns, draft::Drafts, imgcache::ImageCache,
|
actionbar::BarAction, column::Columns, draft::Drafts, imgcache::ImageCache,
|
||||||
notecache::NoteCache, timeline::TimelineId, ui, ui::note::PostAction,
|
notecache::NoteCache, timeline::TimelineId, ui,
|
||||||
};
|
};
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::{Direction, Layout};
|
use egui::{Direction, Layout};
|
||||||
use egui_tabs::TabColor;
|
use egui_tabs::TabColor;
|
||||||
use enostr::{FilledKeypair, RelayPool};
|
use enostr::{FilledKeypair, RelayPool};
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, warn};
|
||||||
|
|
||||||
pub struct TimelineView<'a> {
|
pub struct TimelineView<'a> {
|
||||||
timeline_id: TimelineId,
|
timeline_id: TimelineId,
|
||||||
@@ -189,16 +190,16 @@ pub fn postbox_view<'a>(
|
|||||||
.ui(&txn, ui);
|
.ui(&txn, ui);
|
||||||
|
|
||||||
if let Some(action) = response.action {
|
if let Some(action) = response.action {
|
||||||
match action {
|
PostActionExecutor::execute(
|
||||||
PostAction::Post(np) => {
|
&key,
|
||||||
let seckey = key.secret_key.to_secret_bytes();
|
&action,
|
||||||
let note = np.to_note(&seckey);
|
pool,
|
||||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
drafts,
|
||||||
info!("sending {}", raw_msg);
|
|np, seckey| np.to_note(seckey),
|
||||||
pool.send(&enostr::ClientMessage::raw(raw_msg));
|
|drafts| {
|
||||||
drafts.compose_mut().clear();
|
drafts.compose_mut().clear();
|
||||||
}
|
},
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user