Revert driller
This reverts commitcec49c83bd. Revert "update NoteContentsDriller to NoteContext" This reverts commit65bd6a65f9. Revert "introduce the driller" This reverts commit95d618e7fe.
This commit is contained in:
@@ -14,18 +14,21 @@ use egui::{vec2, Frame, Layout, Margin, Pos2, ScrollArea, Sense, TextBuffer};
|
||||
use enostr::{FilledKeypair, FullKeypair, NoteId, Pubkey, RelayPool};
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
|
||||
use notedeck::supported_mime_hosted_at_url;
|
||||
use notedeck::{supported_mime_hosted_at_url, Images, NoteCache};
|
||||
use tracing::error;
|
||||
|
||||
use super::contents::{render_note_preview, NoteContext};
|
||||
use super::contents::render_note_preview;
|
||||
|
||||
pub struct PostView<'a, 'd> {
|
||||
note_context: &'a mut NoteContext<'d>,
|
||||
pub struct PostView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
draft: &'a mut Draft,
|
||||
post_type: PostType,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
poster: FilledKeypair<'a>,
|
||||
id_source: Option<egui::Id>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -80,23 +83,29 @@ pub struct PostResponse {
|
||||
pub edit_response: egui::Response,
|
||||
}
|
||||
|
||||
impl<'a, 'd> PostView<'a, 'd> {
|
||||
impl<'a> PostView<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
note_context: &'a mut NoteContext<'d>,
|
||||
ndb: &'a Ndb,
|
||||
draft: &'a mut Draft,
|
||||
post_type: PostType,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
poster: FilledKeypair<'a>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
) -> Self {
|
||||
let id_source: Option<egui::Id> = None;
|
||||
PostView {
|
||||
note_context,
|
||||
ndb,
|
||||
draft,
|
||||
img_cache,
|
||||
note_cache,
|
||||
poster,
|
||||
id_source,
|
||||
post_type,
|
||||
inner_rect,
|
||||
note_options,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,21 +121,17 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
|
||||
// TODO: refactor pfp control to do all of this for us
|
||||
let poster_pfp = self
|
||||
.note_context
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.poster.pubkey.bytes())
|
||||
.as_ref()
|
||||
.ok()
|
||||
.and_then(|p| {
|
||||
Some(ui::ProfilePic::from_profile(self.note_context.img_cache, p)?.size(pfp_size))
|
||||
});
|
||||
.and_then(|p| Some(ui::ProfilePic::from_profile(self.img_cache, p)?.size(pfp_size)));
|
||||
|
||||
if let Some(pfp) = poster_pfp {
|
||||
ui.add(pfp);
|
||||
} else {
|
||||
ui.add(
|
||||
ui::ProfilePic::new(self.note_context.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
.size(pfp_size),
|
||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url()).size(pfp_size),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -223,15 +228,9 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
hint_rect
|
||||
};
|
||||
|
||||
if let Ok(res) = self.note_context.ndb.search_profile(txn, mention_str, 10)
|
||||
{
|
||||
let resp = SearchResultsView::new(
|
||||
self.note_context.img_cache,
|
||||
self.note_context.ndb,
|
||||
txn,
|
||||
&res,
|
||||
)
|
||||
.show_in_rect(hint_rect, ui);
|
||||
if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
|
||||
let resp = SearchResultsView::new(self.img_cache, self.ndb, txn, &res)
|
||||
.show_in_rect(hint_rect, ui);
|
||||
|
||||
match resp {
|
||||
ui::search_results::SearchResultsResponse::SelectResult(
|
||||
@@ -239,10 +238,7 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
) => {
|
||||
if let Some(hint_index) = selection {
|
||||
if let Some(pk) = res.get(hint_index) {
|
||||
let record = self
|
||||
.note_context
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, pk);
|
||||
let record = self.ndb.get_profile_by_pubkey(txn, pk);
|
||||
|
||||
self.draft.buffer.select_mention_and_replace_name(
|
||||
mention.index,
|
||||
@@ -322,10 +318,13 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
ui.set_max_width(avail_size.x * 0.8);
|
||||
render_note_preview(
|
||||
ui,
|
||||
self.note_context,
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
txn,
|
||||
id.bytes(),
|
||||
nostrdb::NoteKey::new(0),
|
||||
self.note_options,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -405,11 +404,11 @@ impl<'a, 'd> PostView<'a, 'd> {
|
||||
};
|
||||
|
||||
if let Some(cache_type) =
|
||||
supported_mime_hosted_at_url(&mut self.note_context.img_cache.urls, &media.url)
|
||||
supported_mime_hosted_at_url(&mut self.img_cache.urls, &media.url)
|
||||
{
|
||||
render_images(
|
||||
ui,
|
||||
self.note_context.img_cache,
|
||||
self.img_cache,
|
||||
&media.url,
|
||||
crate::images::ImageType::Content(width, height),
|
||||
cache_type,
|
||||
@@ -712,25 +711,21 @@ mod preview {
|
||||
impl App for PostPreview {
|
||||
fn update(&mut self, app: &mut AppContext<'_>, ui: &mut egui::Ui) {
|
||||
let txn = Transaction::new(app.ndb).expect("txn");
|
||||
let mut note_context = NoteContext {
|
||||
ndb: app.ndb,
|
||||
img_cache: app.img_cache,
|
||||
note_cache: app.note_cache,
|
||||
options: NoteOptions::default(),
|
||||
};
|
||||
|
||||
PostView::new(
|
||||
&mut note_context,
|
||||
app.ndb,
|
||||
&mut self.draft,
|
||||
PostType::New,
|
||||
app.img_cache,
|
||||
app.note_cache,
|
||||
self.poster.to_filled(),
|
||||
ui.available_rect_before_wrap(),
|
||||
NoteOptions::default(),
|
||||
)
|
||||
.ui(&txn, ui);
|
||||
}
|
||||
}
|
||||
|
||||
impl Preview for PostView<'_, '_> {
|
||||
impl Preview for PostView<'_> {
|
||||
type Prev = PostPreview;
|
||||
|
||||
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||
|
||||
Reference in New Issue
Block a user