introduce NoteContext

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-03-07 17:02:02 -05:00
parent d85c6043b7
commit a9f473e3c9
12 changed files with 368 additions and 430 deletions

View File

@@ -1,50 +1,46 @@
use crate::{
actionbar::NoteAction,
timeline::{ThreadSelection, TimelineCache, TimelineKind},
ui::note::NoteOptions,
};
use nostrdb::{Ndb, Transaction};
use notedeck::{Images, MuteFun, NoteCache, RootNoteId, UnknownIds};
use nostrdb::Transaction;
use notedeck::{MuteFun, RootNoteId, UnknownIds};
use tracing::error;
use super::timeline::TimelineTabView;
use super::{
note::{contents::NoteContext, NoteOptions},
timeline::TimelineTabView,
};
pub struct ThreadView<'a> {
pub struct ThreadView<'a, 'd> {
timeline_cache: &'a mut TimelineCache,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
unknown_ids: &'a mut UnknownIds,
img_cache: &'a mut Images,
selected_note_id: &'a [u8; 32],
note_options: NoteOptions,
id_source: egui::Id,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
}
impl<'a> ThreadView<'a> {
impl<'a, 'd> ThreadView<'a, 'd> {
#[allow(clippy::too_many_arguments)]
pub fn new(
timeline_cache: &'a mut TimelineCache,
ndb: &'a Ndb,
note_cache: &'a mut NoteCache,
unknown_ids: &'a mut UnknownIds,
img_cache: &'a mut Images,
selected_note_id: &'a [u8; 32],
note_options: NoteOptions,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
) -> Self {
let id_source = egui::Id::new("threadscroll_threadview");
ThreadView {
timeline_cache,
ndb,
note_cache,
unknown_ids,
img_cache,
selected_note_id,
note_options,
id_source,
is_muted,
note_context,
}
}
@@ -54,7 +50,7 @@ impl<'a> ThreadView<'a> {
}
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
let txn = Transaction::new(self.ndb).expect("txn");
let txn = Transaction::new(self.note_context.ndb).expect("txn");
ui.label(
egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.")
@@ -67,21 +63,25 @@ impl<'a> ThreadView<'a> {
.auto_shrink([false, false])
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible)
.show(ui, |ui| {
let root_id =
match RootNoteId::new(self.ndb, self.note_cache, &txn, self.selected_note_id) {
Ok(root_id) => root_id,
let root_id = match RootNoteId::new(
self.note_context.ndb,
self.note_context.note_cache,
&txn,
self.selected_note_id,
) {
Ok(root_id) => root_id,
Err(err) => {
ui.label(format!("Error loading thread: {:?}", err));
return None;
}
};
Err(err) => {
ui.label(format!("Error loading thread: {:?}", err));
return None;
}
};
let thread_timeline = self
.timeline_cache
.notes(
self.ndb,
self.note_cache,
self.note_context.ndb,
self.note_context.note_cache,
&txn,
&TimelineKind::Thread(ThreadSelection::from_root_id(root_id.to_owned())),
)
@@ -92,10 +92,10 @@ impl<'a> ThreadView<'a> {
let reversed = true;
// poll for new notes and insert them into our existing notes
if let Err(err) = thread_timeline.poll_notes_into_view(
self.ndb,
self.note_context.ndb,
&txn,
self.unknown_ids,
self.note_cache,
self.note_context.note_cache,
reversed,
) {
error!("error polling notes into thread timeline: {err}");
@@ -106,10 +106,8 @@ impl<'a> ThreadView<'a> {
true,
self.note_options,
&txn,
self.ndb,
self.note_cache,
self.img_cache,
self.is_muted,
self.note_context,
)
.show(ui)
})