12
src/post.rs
12
src/post.rs
@@ -96,20 +96,16 @@ impl NewPost {
|
||||
self.content,
|
||||
enostr::NoteId::new(*quoting.id()).to_bech().unwrap()
|
||||
);
|
||||
let builder = NoteBuilder::new().kind(1).content(&new_content);
|
||||
|
||||
let builder = builder
|
||||
NoteBuilder::new()
|
||||
.kind(1)
|
||||
.content(&new_content)
|
||||
.start_tag()
|
||||
.tag_str("q")
|
||||
.tag_str(&hex::encode(quoting.id()))
|
||||
.sign(seckey);
|
||||
|
||||
let builder = builder
|
||||
.start_tag()
|
||||
.tag_str("p")
|
||||
.tag_str(&hex::encode(quoting.pubkey()));
|
||||
|
||||
builder
|
||||
.tag_str(&hex::encode(quoting.pubkey()))
|
||||
.sign(seckey)
|
||||
.build()
|
||||
.expect("expected build to work")
|
||||
|
||||
@@ -2,18 +2,17 @@ use enostr::{FilledKeypair, RelayPool};
|
||||
use nostrdb::Note;
|
||||
use tracing::info;
|
||||
|
||||
use crate::{draft::Drafts, post::NewPost, ui::note::PostAction};
|
||||
use crate::{draft::Draft, post::NewPost, ui::note::PostAction};
|
||||
|
||||
pub struct PostActionExecutor {}
|
||||
|
||||
impl PostActionExecutor {
|
||||
pub fn execute<'a>(
|
||||
poster: &FilledKeypair<'_>,
|
||||
poster: FilledKeypair<'_>,
|
||||
action: &'a PostAction,
|
||||
pool: &mut RelayPool,
|
||||
drafts: &mut Drafts,
|
||||
draft: &mut Draft,
|
||||
get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>,
|
||||
clear_draft: impl Fn(&mut Drafts),
|
||||
) {
|
||||
match action {
|
||||
PostAction::Post(np) => {
|
||||
@@ -22,7 +21,7 @@ impl PostActionExecutor {
|
||||
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
|
||||
info!("sending {}", raw_msg);
|
||||
pool.send(&enostr::ClientMessage::raw(raw_msg));
|
||||
clear_draft(drafts);
|
||||
draft.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::{
|
||||
draft::Drafts,
|
||||
imgcache::ImageCache,
|
||||
notecache::NoteCache,
|
||||
post_action_executor::PostActionExecutor,
|
||||
thread::Threads,
|
||||
timeline::TimelineId,
|
||||
ui::{
|
||||
@@ -115,12 +116,7 @@ pub fn render_timeline_route(
|
||||
}
|
||||
|
||||
TimelineRoute::Quote(id) => {
|
||||
let txn = if let Ok(txn) = Transaction::new(ndb) {
|
||||
txn
|
||||
} else {
|
||||
ui.label("Quote of unknown note");
|
||||
return None;
|
||||
};
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
|
||||
let note = if let Ok(note) = ndb.get_note_by_id(&txn, id.bytes()) {
|
||||
note
|
||||
@@ -130,17 +126,22 @@ pub fn render_timeline_route(
|
||||
};
|
||||
|
||||
let id = egui::Id::new(("post", col, note.key().unwrap()));
|
||||
if let Some(poster) = accounts.selected_or_first_nsec() {
|
||||
let response = egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
QuoteRepostView::new(ndb, poster, pool, note_cache, img_cache, drafts, ¬e)
|
||||
.id_source(id)
|
||||
.show(ui)
|
||||
});
|
||||
|
||||
Some(TimelineRouteResponse::post(response.inner))
|
||||
} else {
|
||||
None
|
||||
let poster = accounts.selected_or_first_nsec()?;
|
||||
let draft = drafts.quote_mut(note.id());
|
||||
|
||||
let response = egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
QuoteRepostView::new(ndb, poster, note_cache, img_cache, draft, ¬e)
|
||||
.id_source(id)
|
||||
.show(ui)
|
||||
});
|
||||
|
||||
if let Some(action) = &response.inner.action {
|
||||
PostActionExecutor::execute(poster, action, pool, draft, |np, seckey| {
|
||||
np.to_quote(seckey, ¬e)
|
||||
});
|
||||
}
|
||||
Some(TimelineRouteResponse::post(response.inner))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,9 +206,7 @@ mod preview {
|
||||
PostPreview {
|
||||
ndb,
|
||||
img_cache: ImageCache::new(".".into()),
|
||||
note_cache: NoteCache {
|
||||
cache: Default::default(),
|
||||
},
|
||||
note_cache: NoteCache::default(),
|
||||
draft: Draft::new(),
|
||||
poster: FullKeypair::generate(),
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
use enostr::{FilledKeypair, RelayPool};
|
||||
use enostr::FilledKeypair;
|
||||
use nostrdb::Ndb;
|
||||
|
||||
use crate::{
|
||||
draft::Drafts, imgcache::ImageCache, notecache::NoteCache,
|
||||
post_action_executor::PostActionExecutor, ui,
|
||||
};
|
||||
use crate::{draft::Draft, imgcache::ImageCache, notecache::NoteCache, ui};
|
||||
|
||||
use super::PostResponse;
|
||||
|
||||
pub struct QuoteRepostView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
poster: FilledKeypair<'a>,
|
||||
pool: &'a mut RelayPool,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
drafts: &'a mut Drafts,
|
||||
draft: &'a mut Draft,
|
||||
quoting_note: &'a nostrdb::Note<'a>,
|
||||
id_source: Option<egui::Id>,
|
||||
}
|
||||
@@ -23,20 +19,18 @@ impl<'a> QuoteRepostView<'a> {
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
poster: FilledKeypair<'a>,
|
||||
pool: &'a mut RelayPool,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
drafts: &'a mut Drafts,
|
||||
draft: &'a mut Draft,
|
||||
quoting_note: &'a nostrdb::Note<'a>,
|
||||
) -> Self {
|
||||
let id_source: Option<egui::Id> = None;
|
||||
QuoteRepostView {
|
||||
ndb,
|
||||
poster,
|
||||
pool,
|
||||
note_cache,
|
||||
img_cache,
|
||||
drafts,
|
||||
draft,
|
||||
quoting_note,
|
||||
id_source,
|
||||
}
|
||||
@@ -47,10 +41,9 @@ impl<'a> QuoteRepostView<'a> {
|
||||
let quoting_note_id = self.quoting_note.id();
|
||||
|
||||
let post_response = {
|
||||
let draft = self.drafts.quote_mut(quoting_note_id);
|
||||
ui::PostView::new(
|
||||
self.ndb,
|
||||
draft,
|
||||
self.draft,
|
||||
crate::draft::DraftSource::Quote(quoting_note_id),
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
@@ -60,19 +53,6 @@ impl<'a> QuoteRepostView<'a> {
|
||||
.ui(self.quoting_note.txn().unwrap(), ui)
|
||||
};
|
||||
|
||||
if let Some(action) = &post_response.action {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -94,14 +94,11 @@ impl<'a> PostReplyView<'a> {
|
||||
|
||||
if let Some(action) = &post_response.action {
|
||||
PostActionExecutor::execute(
|
||||
&self.poster,
|
||||
self.poster,
|
||||
action,
|
||||
self.pool,
|
||||
self.drafts,
|
||||
self.drafts.reply_mut(replying_to),
|
||||
|np, seckey| np.to_reply(seckey, self.note),
|
||||
|drafts| {
|
||||
drafts.reply_mut(replying_to).clear();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,16 +190,9 @@ pub fn postbox_view<'a>(
|
||||
.ui(&txn, ui);
|
||||
|
||||
if let Some(action) = response.action {
|
||||
PostActionExecutor::execute(
|
||||
&key,
|
||||
&action,
|
||||
pool,
|
||||
drafts,
|
||||
|np, seckey| np.to_note(seckey),
|
||||
|drafts| {
|
||||
drafts.compose_mut().clear();
|
||||
},
|
||||
);
|
||||
PostActionExecutor::execute(key, &action, pool, drafts.compose_mut(), |np, seckey| {
|
||||
np.to_note(seckey)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user