make PostActionExecutor for code reuse
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use enostr::{FilledKeypair, RelayPool};
|
||||
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> {
|
||||
ndb: &'a Ndb,
|
||||
@@ -59,18 +61,16 @@ impl<'a> QuoteRepostView<'a> {
|
||||
};
|
||||
|
||||
if let Some(action) = &post_response.action {
|
||||
match action {
|
||||
PostAction::Post(np) => {
|
||||
let seckey = self.poster.secret_key.to_secret_bytes();
|
||||
|
||||
let note = np.to_quote(&seckey, self.quoting_note);
|
||||
|
||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
||||
info!("sending {}", raw_msg);
|
||||
self.pool.send(&enostr::ClientMessage::raw(raw_msg));
|
||||
self.drafts.quote_mut(quoting_note_id).clear();
|
||||
}
|
||||
}
|
||||
PostActionExecutor::execute(
|
||||
&self.poster,
|
||||
action,
|
||||
self.pool,
|
||||
self.drafts,
|
||||
|np, seckey| np.to_quote(seckey, self.quoting_note),
|
||||
|drafts| {
|
||||
drafts.quote_mut(quoting_note_id).clear();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
post_response
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::draft::Drafts;
|
||||
use crate::imgcache::ImageCache;
|
||||
use crate::notecache::NoteCache;
|
||||
use crate::post_action_executor::PostActionExecutor;
|
||||
use crate::ui;
|
||||
use crate::ui::note::{PostAction, PostResponse};
|
||||
use crate::ui::note::PostResponse;
|
||||
use enostr::{FilledKeypair, RelayPool};
|
||||
use nostrdb::Ndb;
|
||||
use tracing::info;
|
||||
|
||||
pub struct PostReplyView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
@@ -93,18 +93,16 @@ impl<'a> PostReplyView<'a> {
|
||||
};
|
||||
|
||||
if let Some(action) = &post_response.action {
|
||||
match action {
|
||||
PostAction::Post(np) => {
|
||||
let seckey = self.poster.secret_key.to_secret_bytes();
|
||||
|
||||
let note = np.to_reply(&seckey, self.note);
|
||||
|
||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
||||
info!("sending {}", raw_msg);
|
||||
self.pool.send(&enostr::ClientMessage::raw(raw_msg));
|
||||
self.drafts.reply_mut(replying_to).clear();
|
||||
}
|
||||
}
|
||||
PostActionExecutor::execute(
|
||||
&self.poster,
|
||||
action,
|
||||
self.pool,
|
||||
self.drafts,
|
||||
|np, seckey| np.to_reply(seckey, self.note),
|
||||
|drafts| {
|
||||
drafts.reply_mut(replying_to).clear();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user