address PR comments

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-09-18 11:07:11 -04:00
parent 06336a14ef
commit 6e77d20197
7 changed files with 36 additions and 72 deletions

View File

@@ -96,20 +96,16 @@ impl NewPost {
self.content, self.content,
enostr::NoteId::new(*quoting.id()).to_bech().unwrap() 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() .start_tag()
.tag_str("q") .tag_str("q")
.tag_str(&hex::encode(quoting.id())) .tag_str(&hex::encode(quoting.id()))
.sign(seckey);
let builder = builder
.start_tag() .start_tag()
.tag_str("p") .tag_str("p")
.tag_str(&hex::encode(quoting.pubkey())); .tag_str(&hex::encode(quoting.pubkey()))
builder
.sign(seckey) .sign(seckey)
.build() .build()
.expect("expected build to work") .expect("expected build to work")

View File

@@ -2,18 +2,17 @@ use enostr::{FilledKeypair, RelayPool};
use nostrdb::Note; use nostrdb::Note;
use tracing::info; use tracing::info;
use crate::{draft::Drafts, post::NewPost, ui::note::PostAction}; use crate::{draft::Draft, post::NewPost, ui::note::PostAction};
pub struct PostActionExecutor {} pub struct PostActionExecutor {}
impl PostActionExecutor { impl PostActionExecutor {
pub fn execute<'a>( pub fn execute<'a>(
poster: &FilledKeypair<'_>, poster: FilledKeypair<'_>,
action: &'a PostAction, action: &'a PostAction,
pool: &mut RelayPool, pool: &mut RelayPool,
drafts: &mut Drafts, draft: &mut Draft,
get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>, get_note: impl Fn(&'a NewPost, &[u8; 32]) -> Note<'a>,
clear_draft: impl Fn(&mut Drafts),
) { ) {
match action { match action {
PostAction::Post(np) => { PostAction::Post(np) => {
@@ -22,7 +21,7 @@ impl PostActionExecutor {
let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap()); let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
info!("sending {}", raw_msg); info!("sending {}", raw_msg);
pool.send(&enostr::ClientMessage::raw(raw_msg)); pool.send(&enostr::ClientMessage::raw(raw_msg));
clear_draft(drafts); draft.clear();
} }
} }
} }

View File

@@ -4,6 +4,7 @@ use crate::{
draft::Drafts, draft::Drafts,
imgcache::ImageCache, imgcache::ImageCache,
notecache::NoteCache, notecache::NoteCache,
post_action_executor::PostActionExecutor,
thread::Threads, thread::Threads,
timeline::TimelineId, timeline::TimelineId,
ui::{ ui::{
@@ -115,12 +116,7 @@ pub fn render_timeline_route(
} }
TimelineRoute::Quote(id) => { TimelineRoute::Quote(id) => {
let txn = if let Ok(txn) = Transaction::new(ndb) { let txn = Transaction::new(ndb).expect("txn");
txn
} else {
ui.label("Quote of unknown note");
return None;
};
let note = if let Ok(note) = ndb.get_note_by_id(&txn, id.bytes()) { let note = if let Ok(note) = ndb.get_note_by_id(&txn, id.bytes()) {
note note
@@ -130,17 +126,22 @@ pub fn render_timeline_route(
}; };
let id = egui::Id::new(("post", col, note.key().unwrap())); 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, &note)
.id_source(id)
.show(ui)
});
Some(TimelineRouteResponse::post(response.inner)) let poster = accounts.selected_or_first_nsec()?;
} else { let draft = drafts.quote_mut(note.id());
None
let response = egui::ScrollArea::vertical().show(ui, |ui| {
QuoteRepostView::new(ndb, poster, note_cache, img_cache, draft, &note)
.id_source(id)
.show(ui)
});
if let Some(action) = &response.inner.action {
PostActionExecutor::execute(poster, action, pool, draft, |np, seckey| {
np.to_quote(seckey, &note)
});
} }
Some(TimelineRouteResponse::post(response.inner))
} }
} }
} }

View File

@@ -206,9 +206,7 @@ mod preview {
PostPreview { PostPreview {
ndb, ndb,
img_cache: ImageCache::new(".".into()), img_cache: ImageCache::new(".".into()),
note_cache: NoteCache { note_cache: NoteCache::default(),
cache: Default::default(),
},
draft: Draft::new(), draft: Draft::new(),
poster: FullKeypair::generate(), poster: FullKeypair::generate(),
} }

View File

@@ -1,20 +1,16 @@
use enostr::{FilledKeypair, RelayPool}; use enostr::FilledKeypair;
use nostrdb::Ndb; use nostrdb::Ndb;
use crate::{ use crate::{draft::Draft, imgcache::ImageCache, notecache::NoteCache, ui};
draft::Drafts, imgcache::ImageCache, notecache::NoteCache,
post_action_executor::PostActionExecutor, ui,
};
use super::PostResponse; use super::PostResponse;
pub struct QuoteRepostView<'a> { pub struct QuoteRepostView<'a> {
ndb: &'a Ndb, ndb: &'a Ndb,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
pool: &'a mut RelayPool,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
drafts: &'a mut Drafts, draft: &'a mut Draft,
quoting_note: &'a nostrdb::Note<'a>, quoting_note: &'a nostrdb::Note<'a>,
id_source: Option<egui::Id>, id_source: Option<egui::Id>,
} }
@@ -23,20 +19,18 @@ impl<'a> QuoteRepostView<'a> {
pub fn new( pub fn new(
ndb: &'a Ndb, ndb: &'a Ndb,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
pool: &'a mut RelayPool,
note_cache: &'a mut NoteCache, note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
drafts: &'a mut Drafts, draft: &'a mut Draft,
quoting_note: &'a nostrdb::Note<'a>, quoting_note: &'a nostrdb::Note<'a>,
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
QuoteRepostView { QuoteRepostView {
ndb, ndb,
poster, poster,
pool,
note_cache, note_cache,
img_cache, img_cache,
drafts, draft,
quoting_note, quoting_note,
id_source, id_source,
} }
@@ -47,10 +41,9 @@ impl<'a> QuoteRepostView<'a> {
let quoting_note_id = self.quoting_note.id(); let quoting_note_id = self.quoting_note.id();
let post_response = { let post_response = {
let draft = self.drafts.quote_mut(quoting_note_id);
ui::PostView::new( ui::PostView::new(
self.ndb, self.ndb,
draft, self.draft,
crate::draft::DraftSource::Quote(quoting_note_id), crate::draft::DraftSource::Quote(quoting_note_id),
self.img_cache, self.img_cache,
self.note_cache, self.note_cache,
@@ -60,19 +53,6 @@ impl<'a> QuoteRepostView<'a> {
.ui(self.quoting_note.txn().unwrap(), ui) .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 post_response
} }

View File

@@ -94,14 +94,11 @@ impl<'a> PostReplyView<'a> {
if let Some(action) = &post_response.action { if let Some(action) = &post_response.action {
PostActionExecutor::execute( PostActionExecutor::execute(
&self.poster, self.poster,
action, action,
self.pool, self.pool,
self.drafts, self.drafts.reply_mut(replying_to),
|np, seckey| np.to_reply(seckey, self.note), |np, seckey| np.to_reply(seckey, self.note),
|drafts| {
drafts.reply_mut(replying_to).clear();
},
); );
} }

View File

@@ -190,16 +190,9 @@ pub fn postbox_view<'a>(
.ui(&txn, ui); .ui(&txn, ui);
if let Some(action) = response.action { if let Some(action) = response.action {
PostActionExecutor::execute( PostActionExecutor::execute(key, &action, pool, drafts.compose_mut(), |np, seckey| {
&key, np.to_note(seckey)
&action, });
pool,
drafts,
|np, seckey| np.to_note(seckey),
|drafts| {
drafts.compose_mut().clear();
},
);
} }
} }