update NoteContentsDriller to NoteContext

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-03-07 12:29:56 -08:00
parent 95d618e7fe
commit 65bd6a65f9
11 changed files with 146 additions and 146 deletions

View File

@@ -16,7 +16,7 @@ use crate::{
column::NavTitle, column::NavTitle,
configure_deck::ConfigureDeckView, configure_deck::ConfigureDeckView,
edit_deck::{EditDeckResponse, EditDeckView}, edit_deck::{EditDeckResponse, EditDeckView},
note::{contents::NoteContentsDriller, PostAction, PostType}, note::{contents::NoteContext, PostAction, PostType},
profile::EditProfileView, profile::EditProfileView,
support::SupportView, support::SupportView,
RelayView, View, RelayView, View,
@@ -243,7 +243,7 @@ fn render_nav_body(
col: usize, col: usize,
inner_rect: egui::Rect, inner_rect: egui::Rect,
) -> Option<RenderNavAction> { ) -> Option<RenderNavAction> {
let mut driller = NoteContentsDriller { let mut note_context = NoteContext {
ndb: ctx.ndb, ndb: ctx.ndb,
img_cache: ctx.img_cache, img_cache: ctx.img_cache,
note_cache: ctx.note_cache, note_cache: ctx.note_cache,
@@ -258,7 +258,7 @@ fn render_nav_body(
col, col,
depth, depth,
ui, ui,
&mut driller, &mut note_context,
), ),
Route::Accounts(amr) => { Route::Accounts(amr) => {
let mut action = render_accounts_route( let mut action = render_accounts_route(
@@ -305,7 +305,7 @@ fn render_nav_body(
let draft = app.drafts.reply_mut(note.id()); let draft = app.drafts.reply_mut(note.id());
let response = egui::ScrollArea::vertical().show(ui, |ui| { let response = egui::ScrollArea::vertical().show(ui, |ui| {
ui::PostReplyView::new(&mut driller, poster, draft, &note, inner_rect) ui::PostReplyView::new(&mut note_context, poster, draft, &note, inner_rect)
.id_source(id) .id_source(id)
.show(ui) .show(ui)
}); });
@@ -333,7 +333,7 @@ fn render_nav_body(
let response = egui::ScrollArea::vertical().show(ui, |ui| { let response = egui::ScrollArea::vertical().show(ui, |ui| {
crate::ui::note::QuoteRepostView::new( crate::ui::note::QuoteRepostView::new(
&mut driller, &mut note_context,
poster, poster,
draft, draft,
&note, &note,
@@ -352,7 +352,7 @@ fn render_nav_body(
let txn = Transaction::new(ctx.ndb).expect("txn"); let txn = Transaction::new(ctx.ndb).expect("txn");
let post_response = let post_response =
ui::PostView::new(&mut driller, draft, PostType::New, kp, inner_rect).ui(&txn, ui); ui::PostView::new(&mut note_context, draft, PostType::New, kp, inner_rect).ui(&txn, ui);
post_response.action.map(Into::into) post_response.action.map(Into::into)
} }

View File

@@ -2,7 +2,7 @@ use crate::{
nav::RenderNavAction, nav::RenderNavAction,
profile::ProfileAction, profile::ProfileAction,
timeline::{TimelineCache, TimelineKind}, timeline::{TimelineCache, TimelineKind},
ui::{self, note::contents::NoteContentsDriller, profile::ProfileView}, ui::{self, note::contents::NoteContext, profile::ProfileView},
}; };
use enostr::Pubkey; use enostr::Pubkey;
@@ -17,10 +17,10 @@ pub fn render_timeline_route(
col: usize, col: usize,
depth: usize, depth: usize,
ui: &mut egui::Ui, ui: &mut egui::Ui,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
) -> Option<RenderNavAction> { ) -> Option<RenderNavAction> {
if kind == &TimelineKind::Universe { if kind == &TimelineKind::Universe {
driller.options.set_hide_media(true); note_context.options.set_hide_media(true);
} }
match kind { match kind {
@@ -31,7 +31,7 @@ pub fn render_timeline_route(
| TimelineKind::Hashtag(_) | TimelineKind::Hashtag(_)
| TimelineKind::Generic(_) => { | TimelineKind::Generic(_) => {
let note_action = let note_action =
ui::TimelineView::new(kind, timeline_cache, &accounts.mutefun(), driller).ui(ui); ui::TimelineView::new(kind, timeline_cache, &accounts.mutefun(), note_context).ui(ui);
note_action.map(RenderNavAction::NoteAction) note_action.map(RenderNavAction::NoteAction)
} }
@@ -46,12 +46,12 @@ pub fn render_timeline_route(
col, col,
ui, ui,
&accounts.mutefun(), &accounts.mutefun(),
driller, note_context,
) )
} else { } else {
// we render profiles like timelines if they are at the root // we render profiles like timelines if they are at the root
let note_action = let note_action =
ui::TimelineView::new(kind, timeline_cache, &accounts.mutefun(), driller) ui::TimelineView::new(kind, timeline_cache, &accounts.mutefun(), note_context)
.ui(ui); .ui(ui);
note_action.map(RenderNavAction::NoteAction) note_action.map(RenderNavAction::NoteAction)
@@ -63,7 +63,7 @@ pub fn render_timeline_route(
unknown_ids, unknown_ids,
id.selected_or_root(), id.selected_or_root(),
&accounts.mutefun(), &accounts.mutefun(),
driller, note_context,
) )
.id_source(egui::Id::new(("threadscroll", col))) .id_source(egui::Id::new(("threadscroll", col)))
.ui(ui) .ui(ui)
@@ -80,7 +80,7 @@ pub fn render_profile_route(
col: usize, col: usize,
ui: &mut egui::Ui, ui: &mut egui::Ui,
is_muted: &MuteFun, is_muted: &MuteFun,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
) -> Option<RenderNavAction> { ) -> Option<RenderNavAction> {
let action = ProfileView::new( let action = ProfileView::new(
pubkey, pubkey,
@@ -89,7 +89,7 @@ pub fn render_profile_route(
timeline_cache, timeline_cache,
unknown_ids, unknown_ids,
is_muted, is_muted,
driller, note_context,
) )
.ui(ui); .ui(ui);

View File

@@ -13,7 +13,7 @@ use notedeck::{supported_mime_hosted_at_url, Images, MediaCacheType, NoteCache};
/// Aggregates dependencies to reduce the number of parameters /// Aggregates dependencies to reduce the number of parameters
/// passed to inner UI elements, minimizing prop drilling. /// passed to inner UI elements, minimizing prop drilling.
pub struct NoteContentsDriller<'d> { pub struct NoteContext<'d> {
pub ndb: &'d Ndb, pub ndb: &'d Ndb,
pub img_cache: &'d mut Images, pub img_cache: &'d mut Images,
pub note_cache: &'d mut NoteCache, pub note_cache: &'d mut NoteCache,
@@ -21,7 +21,7 @@ pub struct NoteContentsDriller<'d> {
} }
pub struct NoteContents<'a, 'd> { pub struct NoteContents<'a, 'd> {
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note<'a>, note: &'a Note<'a>,
action: Option<NoteAction>, action: Option<NoteAction>,
@@ -30,12 +30,12 @@ pub struct NoteContents<'a, 'd> {
impl<'a, 'd> NoteContents<'a, 'd> { impl<'a, 'd> NoteContents<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note, note: &'a Note,
) -> Self { ) -> Self {
NoteContents { NoteContents {
driller, note_context,
txn, txn,
note, note,
action: None, action: None,
@@ -49,7 +49,7 @@ impl<'a, 'd> NoteContents<'a, 'd> {
impl egui::Widget for &mut NoteContents<'_, '_> { impl egui::Widget for &mut NoteContents<'_, '_> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response { fn ui(self, ui: &mut egui::Ui) -> egui::Response {
let result = render_note_contents(ui, self.driller, self.txn, self.note); let result = render_note_contents(ui, self.note_context, self.txn, self.note);
self.action = result.action; self.action = result.action;
result.response result.response
} }
@@ -60,7 +60,7 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn render_note_preview( pub fn render_note_preview(
ui: &mut egui::Ui, ui: &mut egui::Ui,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
txn: &Transaction, txn: &Transaction,
id: &[u8; 32], id: &[u8; 32],
parent: NoteKey, parent: NoteKey,
@@ -68,7 +68,7 @@ pub fn render_note_preview(
#[cfg(feature = "profiling")] #[cfg(feature = "profiling")]
puffin::profile_function!(); puffin::profile_function!();
let note = if let Ok(note) = driller.ndb.get_note_by_id(txn, id) { let note = if let Ok(note) = note_context.ndb.get_note_by_id(txn, id) {
// TODO: support other preview kinds // TODO: support other preview kinds
if note.kind() == 1 { if note.kind() == 1 {
note note
@@ -101,7 +101,7 @@ pub fn render_note_preview(
ui.visuals().noninteractive().bg_stroke.color, ui.visuals().noninteractive().bg_stroke.color,
)) ))
.show(ui, |ui| { .show(ui, |ui| {
ui::NoteView::new(driller, &note) ui::NoteView::new(note_context, &note)
.actionbar(false) .actionbar(false)
.small_pfp(true) .small_pfp(true)
.wide(true) .wide(true)
@@ -116,7 +116,7 @@ pub fn render_note_preview(
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn render_note_contents( fn render_note_contents(
ui: &mut egui::Ui, ui: &mut egui::Ui,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
txn: &Transaction, txn: &Transaction,
note: &Note, note: &Note,
) -> NoteResponse { ) -> NoteResponse {
@@ -124,15 +124,15 @@ fn render_note_contents(
puffin::profile_function!(); puffin::profile_function!();
let note_key = note.key().expect("todo: implement non-db notes"); let note_key = note.key().expect("todo: implement non-db notes");
let selectable = driller.options.has_selectable_text(); let selectable = note_context.options.has_selectable_text();
let mut images: Vec<(String, MediaCacheType)> = vec![]; let mut images: Vec<(String, MediaCacheType)> = vec![];
let mut note_action: Option<NoteAction> = None; let mut note_action: Option<NoteAction> = None;
let mut inline_note: Option<(&[u8; 32], &str)> = None; let mut inline_note: Option<(&[u8; 32], &str)> = None;
let hide_media = driller.options.has_hide_media(); let hide_media = note_context.options.has_hide_media();
let link_color = ui.visuals().hyperlink_color; let link_color = ui.visuals().hyperlink_color;
let response = ui.horizontal_wrapped(|ui| { let response = ui.horizontal_wrapped(|ui| {
let blocks = if let Ok(blocks) = driller.ndb.get_blocks_by_key(txn, note_key) { let blocks = if let Ok(blocks) = note_context.ndb.get_blocks_by_key(txn, note_key) {
blocks blocks
} else { } else {
warn!("missing note content blocks? '{}'", note.content()); warn!("missing note content blocks? '{}'", note.content());
@@ -147,7 +147,7 @@ fn render_note_contents(
BlockType::MentionBech32 => match block.as_mention().unwrap() { BlockType::MentionBech32 => match block.as_mention().unwrap() {
Mention::Profile(profile) => { Mention::Profile(profile) => {
let act = let act =
ui::Mention::new(driller.ndb, driller.img_cache, txn, profile.pubkey()) ui::Mention::new(note_context.ndb, note_context.img_cache, txn, profile.pubkey())
.show(ui) .show(ui)
.inner; .inner;
if act.is_some() { if act.is_some() {
@@ -157,7 +157,7 @@ fn render_note_contents(
Mention::Pubkey(npub) => { Mention::Pubkey(npub) => {
let act = let act =
ui::Mention::new(driller.ndb, driller.img_cache, txn, npub.pubkey()) ui::Mention::new(note_context.ndb, note_context.img_cache, txn, npub.pubkey())
.show(ui) .show(ui)
.inner; .inner;
if act.is_some() { if act.is_some() {
@@ -165,11 +165,11 @@ fn render_note_contents(
} }
} }
Mention::Note(note) if driller.options.has_note_previews() => { Mention::Note(note) if note_context.options.has_note_previews() => {
inline_note = Some((note.id(), block.as_str())); inline_note = Some((note.id(), block.as_str()));
} }
Mention::Event(note) if driller.options.has_note_previews() => { Mention::Event(note) if note_context.options.has_note_previews() => {
inline_note = Some((note.id(), block.as_str())); inline_note = Some((note.id(), block.as_str()));
} }
@@ -196,7 +196,7 @@ fn render_note_contents(
let mut found_supported = || -> bool { let mut found_supported = || -> bool {
let url = block.as_str(); let url = block.as_str();
if let Some(cache_type) = if let Some(cache_type) =
supported_mime_hosted_at_url(&mut driller.img_cache.urls, url) supported_mime_hosted_at_url(&mut note_context.img_cache.urls, url)
{ {
images.push((url.to_string(), cache_type)); images.push((url.to_string(), cache_type));
true true
@@ -217,7 +217,7 @@ fn render_note_contents(
BlockType::Text => { BlockType::Text => {
#[cfg(feature = "profiling")] #[cfg(feature = "profiling")]
puffin::profile_scope!("text contents"); puffin::profile_scope!("text contents");
if driller.options.has_scramble_text() { if note_context.options.has_scramble_text() {
ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable)); ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable));
} else { } else {
ui.add(egui::Label::new(block.as_str()).selectable(selectable)); ui.add(egui::Label::new(block.as_str()).selectable(selectable));
@@ -232,15 +232,15 @@ fn render_note_contents(
}); });
let preview_note_action = if let Some((id, _block_str)) = inline_note { let preview_note_action = if let Some((id, _block_str)) = inline_note {
render_note_preview(ui, driller, txn, id, note_key).action render_note_preview(ui, note_context, txn, id, note_key).action
} else { } else {
None None
}; };
if !images.is_empty() && !driller.options.has_textmode() { if !images.is_empty() && !note_context.options.has_textmode() {
ui.add_space(2.0); ui.add_space(2.0);
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note"))); let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note")));
image_carousel(ui, driller.img_cache, images, carousel_id); image_carousel(ui, note_context.img_cache, images, carousel_id);
ui.add_space(2.0); ui.add_space(2.0);
} }

View File

@@ -7,7 +7,7 @@ pub mod reply;
pub mod reply_description; pub mod reply_description;
pub use contents::NoteContents; pub use contents::NoteContents;
use contents::NoteContentsDriller; use contents::NoteContext;
pub use context::{NoteContextButton, NoteContextSelection}; pub use context::{NoteContextButton, NoteContextSelection};
pub use options::NoteOptions; pub use options::NoteOptions;
pub use post::{PostAction, PostResponse, PostType, PostView}; pub use post::{PostAction, PostResponse, PostType, PostView};
@@ -31,7 +31,7 @@ use notedeck::{CachedNote, NoteCache, NotedeckTextStyle};
use super::profile::preview::one_line_display_name_widget; use super::profile::preview::one_line_display_name_widget;
pub struct NoteView<'a, 'd> { pub struct NoteView<'a, 'd> {
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
parent: Option<NoteKey>, parent: Option<NoteKey>,
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
} }
@@ -69,13 +69,13 @@ impl View for NoteView<'_, '_> {
} }
impl<'a, 'd> NoteView<'a, 'd> { impl<'a, 'd> NoteView<'a, 'd> {
pub fn new(driller: &'a mut NoteContentsDriller<'d>, note: &'a nostrdb::Note<'a>) -> Self { pub fn new(note_context: &'a mut NoteContext<'d>, note: &'a nostrdb::Note<'a>) -> Self {
driller.options.set_actionbar(true); note_context.options.set_actionbar(true);
driller.options.set_note_previews(true); note_context.options.set_note_previews(true);
let parent: Option<NoteKey> = None; let parent: Option<NoteKey> = None;
Self { Self {
driller, note_context,
parent, parent,
note, note,
} }
@@ -122,11 +122,11 @@ impl<'a, 'd> NoteView<'a, 'd> {
} }
pub fn options(&self) -> NoteOptions { pub fn options(&self) -> NoteOptions {
self.driller.options self.note_context.options
} }
pub fn options_mut(&mut self) -> &mut NoteOptions { pub fn options_mut(&mut self) -> &mut NoteOptions {
&mut self.driller.options &mut self.note_context.options
} }
pub fn parent(mut self, parent: NoteKey) -> Self { pub fn parent(mut self, parent: NoteKey) -> Self {
@@ -140,7 +140,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| { ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
let profile = self let profile = self
.driller .note_context
.ndb .ndb
.get_profile_by_pubkey(txn, self.note.pubkey()); .get_profile_by_pubkey(txn, self.note.pubkey());
@@ -148,7 +148,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.spacing_mut().item_spacing.x = 2.0; ui.spacing_mut().item_spacing.x = 2.0;
let cached_note = self let cached_note = self
.driller .note_context
.note_cache .note_cache
.cached_note_or_insert_mut(note_key, self.note); .cached_note_or_insert_mut(note_key, self.note);
@@ -167,7 +167,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
) )
}); });
ui.add(&mut NoteContents::new(self.driller, txn, self.note)); ui.add(&mut NoteContents::new(self.note_context, txn, self.note));
//}); //});
}) })
.response .response
@@ -214,13 +214,13 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.put( ui.put(
rect, rect,
ui::ProfilePic::new(self.driller.img_cache, pic).size(size), ui::ProfilePic::new(self.note_context.img_cache, pic).size(size),
) )
.on_hover_ui_at_pointer(|ui| { .on_hover_ui_at_pointer(|ui| {
ui.set_max_width(300.0); ui.set_max_width(300.0);
ui.add(ui::ProfilePreview::new( ui.add(ui::ProfilePreview::new(
profile.as_ref().unwrap(), profile.as_ref().unwrap(),
self.driller.img_cache, self.note_context.img_cache,
)); ));
}); });
@@ -238,7 +238,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.put( ui.put(
rect, rect,
ui::ProfilePic::new(self.driller.img_cache, ui::ProfilePic::no_pfp_url()) ui::ProfilePic::new(self.note_context.img_cache, ui::ProfilePic::no_pfp_url())
.size(pfp_size), .size(pfp_size),
) )
.interact(sense) .interact(sense)
@@ -251,9 +251,9 @@ impl<'a, 'd> NoteView<'a, 'd> {
NoteResponse::new(self.textmode_ui(ui)) NoteResponse::new(self.textmode_ui(ui))
} else { } else {
let txn = self.note.txn().expect("txn"); let txn = self.note.txn().expect("txn");
if let Some(note_to_repost) = get_reposted_note(self.driller.ndb, txn, self.note) { if let Some(note_to_repost) = get_reposted_note(self.note_context.ndb, txn, self.note) {
let profile = self let profile = self
.driller .note_context
.ndb .ndb
.get_profile_by_pubkey(txn, self.note.pubkey()); .get_profile_by_pubkey(txn, self.note.pubkey());
@@ -272,7 +272,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
if let Ok(rec) = &profile { if let Ok(rec) = &profile {
resp.on_hover_ui_at_pointer(|ui| { resp.on_hover_ui_at_pointer(|ui| {
ui.set_max_width(300.0); ui.set_max_width(300.0);
ui.add(ui::ProfilePreview::new(rec, self.driller.img_cache)); ui.add(ui::ProfilePreview::new(rec, self.note_context.img_cache));
}); });
} }
let color = ui.style().visuals.noninteractive().fg_stroke.color; let color = ui.style().visuals.noninteractive().fg_stroke.color;
@@ -283,7 +283,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
.text_style(style.text_style()), .text_style(style.text_style()),
); );
}); });
NoteView::new(self.driller, &note_to_repost).show(ui) NoteView::new(self.note_context, &note_to_repost).show(ui)
} else { } else {
self.show_standard(ui) self.show_standard(ui)
} }
@@ -338,7 +338,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent); let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
let profile = self let profile = self
.driller .note_context
.ndb .ndb
.get_profile_by_pubkey(txn, self.note.pubkey()); .get_profile_by_pubkey(txn, self.note.pubkey());
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id); let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
@@ -365,7 +365,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.horizontal_centered(|ui| { ui.horizontal_centered(|ui| {
selected_option = NoteView::note_header( selected_option = NoteView::note_header(
ui, ui,
self.driller.note_cache, self.note_context.note_cache,
self.note, self.note,
&profile, &profile,
self.options(), self.options(),
@@ -377,7 +377,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
}); });
let note_reply = self let note_reply = self
.driller .note_context
.note_cache .note_cache
.cached_note_or_insert_mut(note_key, self.note) .cached_note_or_insert_mut(note_key, self.note)
.reply .reply
@@ -385,7 +385,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
if note_reply.reply().is_some() { if note_reply.reply().is_some() {
let action = ui let action = ui
.horizontal(|ui| reply_desc(ui, txn, &note_reply, self.driller)) .horizontal(|ui| reply_desc(ui, txn, &note_reply, self.note_context))
.inner; .inner;
if action.is_some() { if action.is_some() {
@@ -395,7 +395,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
}); });
}); });
let mut contents = NoteContents::new(self.driller, txn, self.note); let mut contents = NoteContents::new(self.note_context, txn, self.note);
ui.add(&mut contents); ui.add(&mut contents);
@@ -423,7 +423,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| { ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
selected_option = NoteView::note_header( selected_option = NoteView::note_header(
ui, ui,
self.driller.note_cache, self.note_context.note_cache,
self.note, self.note,
&profile, &profile,
self.options(), self.options(),
@@ -434,14 +434,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.spacing_mut().item_spacing.x = 2.0; ui.spacing_mut().item_spacing.x = 2.0;
let note_reply = self let note_reply = self
.driller .note_context
.note_cache .note_cache
.cached_note_or_insert_mut(note_key, self.note) .cached_note_or_insert_mut(note_key, self.note)
.reply .reply
.borrow(self.note.tags()); .borrow(self.note.tags());
if note_reply.reply().is_some() { if note_reply.reply().is_some() {
let action = reply_desc(ui, txn, &note_reply, self.driller); let action = reply_desc(ui, txn, &note_reply, self.note_context);
if action.is_some() { if action.is_some() {
note_action = action; note_action = action;
@@ -449,7 +449,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
} }
}); });
let mut contents = NoteContents::new(self.driller, txn, self.note); let mut contents = NoteContents::new(self.note_context, txn, self.note);
ui.add(&mut contents); ui.add(&mut contents);
if let Some(action) = contents.action() { if let Some(action) = contents.action() {
@@ -470,8 +470,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) { let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
if let Ok(selection) = ThreadSelection::from_note_id( if let Ok(selection) = ThreadSelection::from_note_id(
self.driller.ndb, self.note_context.ndb,
self.driller.note_cache, self.note_context.note_cache,
self.note.txn().unwrap(), self.note.txn().unwrap(),
NoteId::new(*self.note.id()), NoteId::new(*self.note.id()),
) { ) {

View File

@@ -17,10 +17,10 @@ use nostrdb::{Ndb, Transaction};
use notedeck::supported_mime_hosted_at_url; use notedeck::supported_mime_hosted_at_url;
use tracing::error; use tracing::error;
use super::contents::{render_note_preview, NoteContentsDriller}; use super::contents::{render_note_preview, NoteContext};
pub struct PostView<'a, 'd> { pub struct PostView<'a, 'd> {
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
draft: &'a mut Draft, draft: &'a mut Draft,
post_type: PostType, post_type: PostType,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
@@ -83,7 +83,7 @@ pub struct PostResponse {
impl<'a, 'd> PostView<'a, 'd> { impl<'a, 'd> PostView<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
draft: &'a mut Draft, draft: &'a mut Draft,
post_type: PostType, post_type: PostType,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
@@ -91,7 +91,7 @@ impl<'a, 'd> PostView<'a, 'd> {
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
PostView { PostView {
driller, note_context,
draft, draft,
poster, poster,
id_source, id_source,
@@ -112,20 +112,20 @@ impl<'a, 'd> PostView<'a, 'd> {
// TODO: refactor pfp control to do all of this for us // TODO: refactor pfp control to do all of this for us
let poster_pfp = self let poster_pfp = self
.driller .note_context
.ndb .ndb
.get_profile_by_pubkey(txn, self.poster.pubkey.bytes()) .get_profile_by_pubkey(txn, self.poster.pubkey.bytes())
.as_ref() .as_ref()
.ok() .ok()
.and_then(|p| { .and_then(|p| {
Some(ui::ProfilePic::from_profile(self.driller.img_cache, p)?.size(pfp_size)) Some(ui::ProfilePic::from_profile(self.note_context.img_cache, p)?.size(pfp_size))
}); });
if let Some(pfp) = poster_pfp { if let Some(pfp) = poster_pfp {
ui.add(pfp); ui.add(pfp);
} else { } else {
ui.add( ui.add(
ui::ProfilePic::new(self.driller.img_cache, ui::ProfilePic::no_pfp_url()) ui::ProfilePic::new(self.note_context.img_cache, ui::ProfilePic::no_pfp_url())
.size(pfp_size), .size(pfp_size),
); );
} }
@@ -223,10 +223,10 @@ impl<'a, 'd> PostView<'a, 'd> {
hint_rect hint_rect
}; };
if let Ok(res) = self.driller.ndb.search_profile(txn, mention_str, 10) { if let Ok(res) = self.note_context.ndb.search_profile(txn, mention_str, 10) {
let resp = SearchResultsView::new( let resp = SearchResultsView::new(
self.driller.img_cache, self.note_context.img_cache,
self.driller.ndb, self.note_context.ndb,
txn, txn,
&res, &res,
) )
@@ -239,7 +239,7 @@ impl<'a, 'd> PostView<'a, 'd> {
if let Some(hint_index) = selection { if let Some(hint_index) = selection {
if let Some(pk) = res.get(hint_index) { if let Some(pk) = res.get(hint_index) {
let record = let record =
self.driller.ndb.get_profile_by_pubkey(txn, pk); self.note_context.ndb.get_profile_by_pubkey(txn, pk);
self.draft.buffer.select_mention_and_replace_name( self.draft.buffer.select_mention_and_replace_name(
mention.index, mention.index,
@@ -319,7 +319,7 @@ impl<'a, 'd> PostView<'a, 'd> {
ui.set_max_width(avail_size.x * 0.8); ui.set_max_width(avail_size.x * 0.8);
render_note_preview( render_note_preview(
ui, ui,
self.driller, self.note_context,
txn, txn,
id.bytes(), id.bytes(),
nostrdb::NoteKey::new(0), nostrdb::NoteKey::new(0),
@@ -402,11 +402,11 @@ impl<'a, 'd> PostView<'a, 'd> {
}; };
if let Some(cache_type) = if let Some(cache_type) =
supported_mime_hosted_at_url(&mut self.driller.img_cache.urls, &media.url) supported_mime_hosted_at_url(&mut self.note_context.img_cache.urls, &media.url)
{ {
render_images( render_images(
ui, ui,
self.driller.img_cache, self.note_context.img_cache,
&media.url, &media.url,
crate::images::ImageType::Content(width, height), crate::images::ImageType::Content(width, height),
cache_type, cache_type,
@@ -709,7 +709,7 @@ mod preview {
impl App for PostPreview { impl App for PostPreview {
fn update(&mut self, app: &mut AppContext<'_>, ui: &mut egui::Ui) { fn update(&mut self, app: &mut AppContext<'_>, ui: &mut egui::Ui) {
let txn = Transaction::new(app.ndb).expect("txn"); let txn = Transaction::new(app.ndb).expect("txn");
let mut driller = NoteContentsDriller { let mut note_context = NoteContext {
ndb: app.ndb, ndb: app.ndb,
img_cache: app.img_cache, img_cache: app.img_cache,
note_cache: app.note_cache, note_cache: app.note_cache,
@@ -717,7 +717,7 @@ mod preview {
}; };
PostView::new( PostView::new(
&mut driller, &mut note_context,
&mut self.draft, &mut self.draft,
PostType::New, PostType::New,
self.poster.to_filled(), self.poster.to_filled(),

View File

@@ -5,10 +5,10 @@ use crate::{
ui::{self}, ui::{self},
}; };
use super::{contents::NoteContentsDriller, PostResponse, PostType}; use super::{contents::NoteContext, PostResponse, PostType};
pub struct QuoteRepostView<'a, 'd> { pub struct QuoteRepostView<'a, 'd> {
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
draft: &'a mut Draft, draft: &'a mut Draft,
quoting_note: &'a nostrdb::Note<'a>, quoting_note: &'a nostrdb::Note<'a>,
@@ -19,7 +19,7 @@ pub struct QuoteRepostView<'a, 'd> {
impl<'a, 'd> QuoteRepostView<'a, 'd> { impl<'a, 'd> QuoteRepostView<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
draft: &'a mut Draft, draft: &'a mut Draft,
quoting_note: &'a nostrdb::Note<'a>, quoting_note: &'a nostrdb::Note<'a>,
@@ -27,7 +27,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> {
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
QuoteRepostView { QuoteRepostView {
driller, note_context,
poster, poster,
draft, draft,
quoting_note, quoting_note,
@@ -41,7 +41,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> {
let quoting_note_id = self.quoting_note.id(); let quoting_note_id = self.quoting_note.id();
ui::PostView::new( ui::PostView::new(
self.driller, self.note_context,
self.draft, self.draft,
PostType::Quote(NoteId::new(quoting_note_id.to_owned())), PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
self.poster, self.poster,

View File

@@ -3,10 +3,10 @@ use crate::ui;
use crate::ui::note::{PostResponse, PostType}; use crate::ui::note::{PostResponse, PostType};
use enostr::{FilledKeypair, NoteId}; use enostr::{FilledKeypair, NoteId};
use super::contents::NoteContentsDriller; use super::contents::NoteContext;
pub struct PostReplyView<'a, 'd> { pub struct PostReplyView<'a, 'd> {
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
draft: &'a mut Draft, draft: &'a mut Draft,
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
@@ -17,7 +17,7 @@ pub struct PostReplyView<'a, 'd> {
impl<'a, 'd> PostReplyView<'a, 'd> { impl<'a, 'd> PostReplyView<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
draft: &'a mut Draft, draft: &'a mut Draft,
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
@@ -25,7 +25,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
PostReplyView { PostReplyView {
driller, note_context,
poster, poster,
draft, draft,
note, note,
@@ -61,7 +61,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
egui::Frame::none() egui::Frame::none()
.outer_margin(egui::Margin::same(note_offset)) .outer_margin(egui::Margin::same(note_offset))
.show(ui, |ui| { .show(ui, |ui| {
ui::NoteView::new(self.driller, self.note) ui::NoteView::new(self.note_context, self.note)
.actionbar(false) .actionbar(false)
.medium_pfp(true) .medium_pfp(true)
.options_button(true) .options_button(true)
@@ -74,7 +74,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
let post_response = { let post_response = {
ui::PostView::new( ui::PostView::new(
self.driller, self.note_context,
self.draft, self.draft,
PostType::Reply(NoteId::new(*replying_to)), PostType::Reply(NoteId::new(*replying_to)),
self.poster, self.poster,

View File

@@ -5,14 +5,14 @@ use crate::{
use egui::{Label, RichText, Sense}; use egui::{Label, RichText, Sense};
use nostrdb::{Note, NoteReply, Transaction}; use nostrdb::{Note, NoteReply, Transaction};
use super::contents::NoteContentsDriller; use super::contents::NoteContext;
#[must_use = "Please handle the resulting note action"] #[must_use = "Please handle the resulting note action"]
pub fn reply_desc( pub fn reply_desc(
ui: &mut egui::Ui, ui: &mut egui::Ui,
txn: &Transaction, txn: &Transaction,
note_reply: &NoteReply, note_reply: &NoteReply,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
#[cfg(feature = "profiling")] #[cfg(feature = "profiling")]
puffin::profile_function!(); puffin::profile_function!();
@@ -26,7 +26,7 @@ pub fn reply_desc(
// note link renderer helper // note link renderer helper
let note_link = let note_link =
|ui: &mut egui::Ui, driller: &mut NoteContentsDriller, text: &str, note: &Note<'_>| { |ui: &mut egui::Ui, note_context: &mut NoteContext, text: &str, note: &Note<'_>| {
let r = ui.add( let r = ui.add(
Label::new(RichText::new(text).size(size).color(link_color)) Label::new(RichText::new(text).size(size).color(link_color))
.sense(Sense::click()) .sense(Sense::click())
@@ -40,7 +40,7 @@ pub fn reply_desc(
if r.hovered() { if r.hovered() {
r.on_hover_ui_at_pointer(|ui| { r.on_hover_ui_at_pointer(|ui| {
ui.set_max_width(400.0); ui.set_max_width(400.0);
ui::NoteView::new(driller, note) ui::NoteView::new(note_context, note)
.actionbar(false) .actionbar(false)
.wide(true) .wide(true)
.show(ui); .show(ui);
@@ -52,7 +52,7 @@ pub fn reply_desc(
let reply = note_reply.reply()?; let reply = note_reply.reply()?;
let reply_note = if let Ok(reply_note) = driller.ndb.get_note_by_id(txn, reply.id) { let reply_note = if let Ok(reply_note) = note_context.ndb.get_note_by_id(txn, reply.id) {
reply_note reply_note
} else { } else {
ui.add(Label::new(RichText::new("a note").size(size).color(color)).selectable(selectable)); ui.add(Label::new(RichText::new("a note").size(size).color(color)).selectable(selectable));
@@ -61,7 +61,7 @@ pub fn reply_desc(
if note_reply.is_reply_to_root() { if note_reply.is_reply_to_root() {
// We're replying to the root, let's show this // We're replying to the root, let's show this
let action = ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey()) let action = ui::Mention::new(note_context.ndb, note_context.img_cache, txn, reply_note.pubkey())
.size(size) .size(size)
.selectable(selectable) .selectable(selectable)
.show(ui) .show(ui)
@@ -73,15 +73,15 @@ pub fn reply_desc(
ui.add(Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable)); ui.add(Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable));
note_link(ui, driller, "thread", &reply_note); note_link(ui, note_context, "thread", &reply_note);
} else if let Some(root) = note_reply.root() { } else if let Some(root) = note_reply.root() {
// replying to another post in a thread, not the root // replying to another post in a thread, not the root
if let Ok(root_note) = driller.ndb.get_note_by_id(txn, root.id) { if let Ok(root_note) = note_context.ndb.get_note_by_id(txn, root.id) {
if root_note.pubkey() == reply_note.pubkey() { if root_note.pubkey() == reply_note.pubkey() {
// simply "replying to bob's note" when replying to bob in his thread // simply "replying to bob's note" when replying to bob in his thread
let action = let action =
ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey()) ui::Mention::new(note_context.ndb, note_context.img_cache, txn, reply_note.pubkey())
.size(size) .size(size)
.selectable(selectable) .selectable(selectable)
.show(ui) .show(ui)
@@ -95,12 +95,12 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable), Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
); );
note_link(ui, driller, "note", &reply_note); note_link(ui, note_context, "note", &reply_note);
} else { } else {
// replying to bob in alice's thread // replying to bob in alice's thread
let action = let action =
ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey()) ui::Mention::new(note_context.ndb, note_context.img_cache, txn, reply_note.pubkey())
.size(size) .size(size)
.selectable(selectable) .selectable(selectable)
.show(ui) .show(ui)
@@ -114,14 +114,14 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable), Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
); );
note_link(ui, driller, "note", &reply_note); note_link(ui, note_context, "note", &reply_note);
ui.add( ui.add(
Label::new(RichText::new("in").size(size).color(color)).selectable(selectable), Label::new(RichText::new("in").size(size).color(color)).selectable(selectable),
); );
let action = let action =
ui::Mention::new(driller.ndb, driller.img_cache, txn, root_note.pubkey()) ui::Mention::new(note_context.ndb, note_context.img_cache, txn, root_note.pubkey())
.size(size) .size(size)
.selectable(selectable) .selectable(selectable)
.show(ui) .show(ui)
@@ -135,10 +135,10 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable), Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
); );
note_link(ui, driller, "thread", &root_note); note_link(ui, note_context, "thread", &root_note);
} }
} else { } else {
let action = ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey()) let action = ui::Mention::new(note_context.ndb, note_context.img_cache, txn, reply_note.pubkey())
.size(size) .size(size)
.selectable(selectable) .selectable(selectable)
.show(ui) .show(ui)

View File

@@ -22,7 +22,7 @@ use crate::{
use notedeck::{Accounts, MuteFun, NotedeckTextStyle, UnknownIds}; use notedeck::{Accounts, MuteFun, NotedeckTextStyle, UnknownIds};
use super::note::contents::NoteContentsDriller; use super::note::contents::NoteContext;
pub struct ProfileView<'a, 'd> { pub struct ProfileView<'a, 'd> {
pubkey: &'a Pubkey, pubkey: &'a Pubkey,
@@ -31,7 +31,7 @@ pub struct ProfileView<'a, 'd> {
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
unknown_ids: &'a mut UnknownIds, unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
} }
pub enum ProfileViewAction { pub enum ProfileViewAction {
@@ -48,7 +48,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
unknown_ids: &'a mut UnknownIds, unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
) -> Self { ) -> Self {
ProfileView { ProfileView {
pubkey, pubkey,
@@ -57,7 +57,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
timeline_cache, timeline_cache,
unknown_ids, unknown_ids,
is_muted, is_muted,
driller, note_context,
} }
} }
@@ -68,9 +68,9 @@ impl<'a, 'd> ProfileView<'a, 'd> {
.id_salt(scroll_id) .id_salt(scroll_id)
.show(ui, |ui| { .show(ui, |ui| {
let mut action = None; let mut action = None;
let txn = Transaction::new(self.driller.ndb).expect("txn"); let txn = Transaction::new(self.note_context.ndb).expect("txn");
if let Ok(profile) = self if let Ok(profile) = self
.driller .note_context
.ndb .ndb
.get_profile_by_pubkey(&txn, self.pubkey.bytes()) .get_profile_by_pubkey(&txn, self.pubkey.bytes())
{ {
@@ -81,8 +81,8 @@ impl<'a, 'd> ProfileView<'a, 'd> {
let profile_timeline = self let profile_timeline = self
.timeline_cache .timeline_cache
.notes( .notes(
self.driller.ndb, self.note_context.ndb,
self.driller.note_cache, self.note_context.note_cache,
&txn, &txn,
&TimelineKind::Profile(*self.pubkey), &TimelineKind::Profile(*self.pubkey),
) )
@@ -94,10 +94,10 @@ impl<'a, 'd> ProfileView<'a, 'd> {
let reversed = false; let reversed = false;
// poll for new notes and insert them into our existing notes // poll for new notes and insert them into our existing notes
if let Err(e) = profile_timeline.poll_notes_into_view( if let Err(e) = profile_timeline.poll_notes_into_view(
self.driller.ndb, self.note_context.ndb,
&txn, &txn,
self.unknown_ids, self.unknown_ids,
self.driller.note_cache, self.note_context.note_cache,
reversed, reversed,
) { ) {
error!("Profile::poll_notes_into_view: {e}"); error!("Profile::poll_notes_into_view: {e}");
@@ -108,7 +108,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
reversed, reversed,
&txn, &txn,
self.is_muted, self.is_muted,
self.driller, self.note_context,
) )
.show(ui) .show(ui)
{ {
@@ -140,7 +140,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.put( ui.put(
pfp_rect, pfp_rect,
ProfilePic::new(self.driller.img_cache, get_profile_url(Some(&profile))) ProfilePic::new(self.note_context.img_cache, get_profile_url(Some(&profile)))
.size(size) .size(size)
.border(ProfilePic::border_stroke(ui)), .border(ProfilePic::border_stroke(ui)),
); );

View File

@@ -7,7 +7,7 @@ use nostrdb::Transaction;
use notedeck::{MuteFun, RootNoteId, UnknownIds}; use notedeck::{MuteFun, RootNoteId, UnknownIds};
use tracing::error; use tracing::error;
use super::{note::contents::NoteContentsDriller, timeline::TimelineTabView}; use super::{note::contents::NoteContext, timeline::TimelineTabView};
pub struct ThreadView<'a, 'd> { pub struct ThreadView<'a, 'd> {
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
@@ -15,7 +15,7 @@ pub struct ThreadView<'a, 'd> {
selected_note_id: &'a [u8; 32], selected_note_id: &'a [u8; 32],
id_source: egui::Id, id_source: egui::Id,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
} }
impl<'a, 'd> ThreadView<'a, 'd> { impl<'a, 'd> ThreadView<'a, 'd> {
@@ -25,7 +25,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
unknown_ids: &'a mut UnknownIds, unknown_ids: &'a mut UnknownIds,
selected_note_id: &'a [u8; 32], selected_note_id: &'a [u8; 32],
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
) -> Self { ) -> Self {
let id_source = egui::Id::new("threadscroll_threadview"); let id_source = egui::Id::new("threadscroll_threadview");
ThreadView { ThreadView {
@@ -34,7 +34,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
selected_note_id, selected_note_id,
id_source, id_source,
is_muted, is_muted,
driller, note_context,
} }
} }
@@ -44,7 +44,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
} }
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> { pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
let txn = Transaction::new(self.driller.ndb).expect("txn"); let txn = Transaction::new(self.note_context.ndb).expect("txn");
ui.label( ui.label(
egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.") egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.")
@@ -58,8 +58,8 @@ impl<'a, 'd> ThreadView<'a, 'd> {
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible) .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible)
.show(ui, |ui| { .show(ui, |ui| {
let root_id = match RootNoteId::new( let root_id = match RootNoteId::new(
self.driller.ndb, self.note_context.ndb,
self.driller.note_cache, self.note_context.note_cache,
&txn, &txn,
self.selected_note_id, self.selected_note_id,
) { ) {
@@ -74,8 +74,8 @@ impl<'a, 'd> ThreadView<'a, 'd> {
let thread_timeline = self let thread_timeline = self
.timeline_cache .timeline_cache
.notes( .notes(
self.driller.ndb, self.note_context.ndb,
self.driller.note_cache, self.note_context.note_cache,
&txn, &txn,
&TimelineKind::Thread(ThreadSelection::from_root_id(root_id.to_owned())), &TimelineKind::Thread(ThreadSelection::from_root_id(root_id.to_owned())),
) )
@@ -86,10 +86,10 @@ impl<'a, 'd> ThreadView<'a, 'd> {
let reversed = true; let reversed = true;
// poll for new notes and insert them into our existing notes // poll for new notes and insert them into our existing notes
if let Err(err) = thread_timeline.poll_notes_into_view( if let Err(err) = thread_timeline.poll_notes_into_view(
self.driller.ndb, self.note_context.ndb,
&txn, &txn,
self.unknown_ids, self.unknown_ids,
self.driller.note_cache, self.note_context.note_cache,
reversed, reversed,
) { ) {
error!("error polling notes into thread timeline: {err}"); error!("error polling notes into thread timeline: {err}");
@@ -100,7 +100,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
true, true,
&txn, &txn,
self.is_muted, self.is_muted,
self.driller, self.note_context,
) )
.show(ui) .show(ui)
}) })

View File

@@ -15,14 +15,14 @@ use notedeck::MuteFun;
use tracing::{error, warn}; use tracing::{error, warn};
use super::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE}; use super::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
use super::note::contents::NoteContentsDriller; use super::note::contents::NoteContext;
pub struct TimelineView<'a, 'd> { pub struct TimelineView<'a, 'd> {
timeline_id: &'a TimelineKind, timeline_id: &'a TimelineKind,
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
reverse: bool, reverse: bool,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
} }
impl<'a, 'd> TimelineView<'a, 'd> { impl<'a, 'd> TimelineView<'a, 'd> {
@@ -31,7 +31,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
timeline_id: &'a TimelineKind, timeline_id: &'a TimelineKind,
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
) -> Self { ) -> Self {
let reverse = false; let reverse = false;
TimelineView { TimelineView {
@@ -39,7 +39,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
timeline_cache, timeline_cache,
reverse, reverse,
is_muted, is_muted,
driller, note_context,
} }
} }
@@ -50,7 +50,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
self.timeline_cache, self.timeline_cache,
self.reverse, self.reverse,
self.is_muted, self.is_muted,
self.driller, self.note_context,
) )
} }
@@ -67,7 +67,7 @@ fn timeline_ui(
timeline_cache: &mut TimelineCache, timeline_cache: &mut TimelineCache,
reversed: bool, reversed: bool,
is_muted: &MuteFun, is_muted: &MuteFun,
driller: &mut NoteContentsDriller, note_context: &mut NoteContext,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
//padding(4.0, ui, |ui| ui.heading("Notifications")); //padding(4.0, ui, |ui| ui.heading("Notifications"));
/* /*
@@ -136,9 +136,9 @@ fn timeline_ui(
return None; return None;
}; };
let txn = Transaction::new(driller.ndb).expect("failed to create txn"); let txn = Transaction::new(note_context.ndb).expect("failed to create txn");
TimelineTabView::new(timeline.current_view(), reversed, &txn, is_muted, driller).show(ui) TimelineTabView::new(timeline.current_view(), reversed, &txn, is_muted, note_context).show(ui)
}); });
let at_top_after_scroll = scroll_output.state.offset.y == 0.0; let at_top_after_scroll = scroll_output.state.offset.y == 0.0;
@@ -296,7 +296,7 @@ pub struct TimelineTabView<'a, 'd> {
reversed: bool, reversed: bool,
txn: &'a Transaction, txn: &'a Transaction,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
} }
impl<'a, 'd> TimelineTabView<'a, 'd> { impl<'a, 'd> TimelineTabView<'a, 'd> {
@@ -306,14 +306,14 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
reversed: bool, reversed: bool,
txn: &'a Transaction, txn: &'a Transaction,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>, note_context: &'a mut NoteContext<'d>,
) -> Self { ) -> Self {
Self { Self {
tab, tab,
reversed, reversed,
txn, txn,
is_muted, is_muted,
driller, note_context,
} }
} }
@@ -338,7 +338,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
let note_key = self.tab.notes[ind].key; let note_key = self.tab.notes[ind].key;
let note = if let Ok(note) = self.driller.ndb.get_note_by_key(self.txn, note_key) { let note = if let Ok(note) = self.note_context.ndb.get_note_by_key(self.txn, note_key) {
note note
} else { } else {
warn!("failed to query note {:?}", note_key); warn!("failed to query note {:?}", note_key);
@@ -347,8 +347,8 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
// should we mute the thread? we might not have it! // should we mute the thread? we might not have it!
let muted = if let Ok(root_id) = root_note_id_from_selected_id( let muted = if let Ok(root_id) = root_note_id_from_selected_id(
self.driller.ndb, self.note_context.ndb,
self.driller.note_cache, self.note_context.note_cache,
self.txn, self.txn,
note.id(), note.id(),
) { ) {
@@ -359,7 +359,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
if !muted { if !muted {
ui::padding(8.0, ui, |ui| { ui::padding(8.0, ui, |ui| {
let resp = ui::NoteView::new(self.driller, &note).show(ui); let resp = ui::NoteView::new(self.note_context, &note).show(ui);
if let Some(note_action) = resp.action { if let Some(note_action) = resp.action {
action = Some(note_action) action = Some(note_action)