introduce the driller

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-03-07 00:40:24 -05:00
parent 035aa20790
commit 95d618e7fe
11 changed files with 298 additions and 489 deletions

View File

@@ -5,64 +5,52 @@ use crate::timeline::TimelineTab;
use crate::{
timeline::{TimelineCache, TimelineKind, ViewFilter},
ui,
ui::note::NoteOptions,
};
use egui::containers::scroll_area::ScrollBarVisibility;
use egui::{vec2, Direction, Layout, Pos2, Stroke};
use egui_tabs::TabColor;
use nostrdb::{Ndb, Transaction};
use nostrdb::Transaction;
use notedeck::note::root_note_id_from_selected_id;
use notedeck::{Images, MuteFun, NoteCache};
use notedeck::MuteFun;
use tracing::{error, warn};
use super::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
use super::note::contents::NoteContentsDriller;
pub struct TimelineView<'a> {
pub struct TimelineView<'a, 'd> {
timeline_id: &'a TimelineKind,
timeline_cache: &'a mut TimelineCache,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
img_cache: &'a mut Images,
note_options: NoteOptions,
reverse: bool,
is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>,
}
impl<'a> TimelineView<'a> {
impl<'a, 'd> TimelineView<'a, 'd> {
#[allow(clippy::too_many_arguments)]
pub fn new(
timeline_id: &'a TimelineKind,
timeline_cache: &'a mut TimelineCache,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
img_cache: &'a mut Images,
note_options: NoteOptions,
is_muted: &'a MuteFun,
) -> TimelineView<'a> {
driller: &'a mut NoteContentsDriller<'d>,
) -> Self {
let reverse = false;
TimelineView {
ndb,
timeline_id,
timeline_cache,
note_cache,
img_cache,
reverse,
note_options,
is_muted,
driller,
}
}
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
timeline_ui(
ui,
self.ndb,
self.timeline_id,
self.timeline_cache,
self.note_cache,
self.img_cache,
self.reverse,
self.note_options,
self.is_muted,
self.driller,
)
}
@@ -75,14 +63,11 @@ impl<'a> TimelineView<'a> {
#[allow(clippy::too_many_arguments)]
fn timeline_ui(
ui: &mut egui::Ui,
ndb: &Ndb,
timeline_id: &TimelineKind,
timeline_cache: &mut TimelineCache,
note_cache: &mut NoteCache,
img_cache: &mut Images,
reversed: bool,
note_options: NoteOptions,
is_muted: &MuteFun,
driller: &mut NoteContentsDriller,
) -> Option<NoteAction> {
//padding(4.0, ui, |ui| ui.heading("Notifications"));
/*
@@ -151,18 +136,9 @@ fn timeline_ui(
return None;
};
let txn = Transaction::new(ndb).expect("failed to create txn");
TimelineTabView::new(
timeline.current_view(),
reversed,
note_options,
&txn,
ndb,
note_cache,
img_cache,
is_muted,
)
.show(ui)
let txn = Transaction::new(driller.ndb).expect("failed to create txn");
TimelineTabView::new(timeline.current_view(), reversed, &txn, is_muted, driller).show(ui)
});
let at_top_after_scroll = scroll_output.state.offset.y == 0.0;
@@ -315,38 +291,29 @@ fn shrink_range_to_width(range: egui::Rangef, width: f32) -> egui::Rangef {
egui::Rangef::new(min, max)
}
pub struct TimelineTabView<'a> {
pub struct TimelineTabView<'a, 'd> {
tab: &'a TimelineTab,
reversed: bool,
note_options: NoteOptions,
txn: &'a Transaction,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
img_cache: &'a mut Images,
is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>,
}
impl<'a> TimelineTabView<'a> {
impl<'a, 'd> TimelineTabView<'a, 'd> {
#[allow(clippy::too_many_arguments)]
pub fn new(
tab: &'a TimelineTab,
reversed: bool,
note_options: NoteOptions,
txn: &'a Transaction,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
img_cache: &'a mut Images,
is_muted: &'a MuteFun,
driller: &'a mut NoteContentsDriller<'d>,
) -> Self {
Self {
tab,
reversed,
txn,
note_options,
ndb,
note_cache,
img_cache,
is_muted,
driller,
}
}
@@ -371,7 +338,7 @@ impl<'a> TimelineTabView<'a> {
let note_key = self.tab.notes[ind].key;
let note = if let Ok(note) = self.ndb.get_note_by_key(self.txn, note_key) {
let note = if let Ok(note) = self.driller.ndb.get_note_by_key(self.txn, note_key) {
note
} else {
warn!("failed to query note {:?}", note_key);
@@ -379,9 +346,12 @@ impl<'a> TimelineTabView<'a> {
};
// should we mute the thread? we might not have it!
let muted = if let Ok(root_id) =
root_note_id_from_selected_id(self.ndb, self.note_cache, self.txn, note.id())
{
let muted = if let Ok(root_id) = root_note_id_from_selected_id(
self.driller.ndb,
self.driller.note_cache,
self.txn,
note.id(),
) {
is_muted(&note, root_id.bytes())
} else {
false
@@ -389,14 +359,7 @@ impl<'a> TimelineTabView<'a> {
if !muted {
ui::padding(8.0, ui, |ui| {
let resp = ui::NoteView::new(
self.ndb,
self.note_cache,
self.img_cache,
&note,
self.note_options,
)
.show(ui);
let resp = ui::NoteView::new(self.driller, &note).show(ui);
if let Some(note_action) = resp.action {
action = Some(note_action)