Switch to Columns
Also refactor damus app usage to only pass in things that we need in views. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
108
src/ui/thread.rs
108
src/ui/thread.rs
@@ -1,28 +1,57 @@
|
||||
use crate::{actionbar::BarResult, timeline::TimelineSource, ui, Damus};
|
||||
use nostrdb::{NoteKey, Transaction};
|
||||
use crate::{
|
||||
actionbar::BarResult, column::Columns, imgcache::ImageCache, notecache::NoteCache,
|
||||
thread::Threads, timeline::TimelineSource, ui, unknowns::UnknownIds,
|
||||
};
|
||||
use enostr::RelayPool;
|
||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||
use tracing::{error, warn};
|
||||
|
||||
pub struct ThreadView<'a> {
|
||||
app: &'a mut Damus,
|
||||
timeline: usize,
|
||||
column: usize,
|
||||
columns: &'a mut Columns,
|
||||
threads: &'a mut Threads,
|
||||
ndb: &'a Ndb,
|
||||
pool: &'a mut RelayPool,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
selected_note_id: &'a [u8; 32],
|
||||
textmode: bool,
|
||||
}
|
||||
|
||||
impl<'a> ThreadView<'a> {
|
||||
pub fn new(app: &'a mut Damus, timeline: usize, selected_note_id: &'a [u8; 32]) -> Self {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
column: usize,
|
||||
columns: &'a mut Columns,
|
||||
threads: &'a mut Threads,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
pool: &'a mut RelayPool,
|
||||
textmode: bool,
|
||||
selected_note_id: &'a [u8; 32],
|
||||
) -> Self {
|
||||
ThreadView {
|
||||
app,
|
||||
timeline,
|
||||
column,
|
||||
columns,
|
||||
threads,
|
||||
ndb,
|
||||
note_cache,
|
||||
img_cache,
|
||||
textmode,
|
||||
selected_note_id,
|
||||
unknown_ids,
|
||||
pool,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<BarResult> {
|
||||
let txn = Transaction::new(&self.app.ndb).expect("txn");
|
||||
let txn = Transaction::new(self.ndb).expect("txn");
|
||||
let mut result: Option<BarResult> = None;
|
||||
|
||||
let selected_note_key = if let Ok(key) = self
|
||||
.app
|
||||
.ndb
|
||||
.get_notekey_by_id(&txn, self.selected_note_id)
|
||||
.map(NoteKey::new)
|
||||
@@ -33,12 +62,13 @@ impl<'a> ThreadView<'a> {
|
||||
return None;
|
||||
};
|
||||
|
||||
let scroll_id = egui::Id::new((
|
||||
"threadscroll",
|
||||
self.app.timelines[self.timeline].selected_view,
|
||||
self.timeline,
|
||||
selected_note_key,
|
||||
));
|
||||
let scroll_id = {
|
||||
egui::Id::new((
|
||||
"threadscroll",
|
||||
self.columns.column(self.column).view_id(),
|
||||
selected_note_key,
|
||||
))
|
||||
};
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.")
|
||||
@@ -51,7 +81,7 @@ impl<'a> ThreadView<'a> {
|
||||
.auto_shrink([false, false])
|
||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible)
|
||||
.show(ui, |ui| {
|
||||
let note = if let Ok(note) = self.app.ndb.get_note_by_key(&txn, selected_note_key) {
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, selected_note_key) {
|
||||
note
|
||||
} else {
|
||||
return;
|
||||
@@ -59,8 +89,7 @@ impl<'a> ThreadView<'a> {
|
||||
|
||||
let root_id = {
|
||||
let cached_note = self
|
||||
.app
|
||||
.note_cache_mut()
|
||||
.note_cache
|
||||
.cached_note_or_insert(selected_note_key, ¬e);
|
||||
|
||||
cached_note
|
||||
@@ -71,17 +100,19 @@ impl<'a> ThreadView<'a> {
|
||||
};
|
||||
|
||||
// poll for new notes and insert them into our existing notes
|
||||
if let Err(e) = TimelineSource::Thread(root_id).poll_notes_into_view(&txn, self.app)
|
||||
{
|
||||
if let Err(e) = TimelineSource::Thread(root_id).poll_notes_into_view(
|
||||
&txn,
|
||||
self.ndb,
|
||||
self.columns,
|
||||
self.threads,
|
||||
self.unknown_ids,
|
||||
self.note_cache,
|
||||
) {
|
||||
error!("Thread::poll_notes_into_view: {e}");
|
||||
}
|
||||
|
||||
let (len, list) = {
|
||||
let thread = self
|
||||
.app
|
||||
.threads
|
||||
.thread_mut(&self.app.ndb, &txn, root_id)
|
||||
.get_ptr();
|
||||
let thread = self.threads.thread_mut(self.ndb, &txn, root_id).get_ptr();
|
||||
|
||||
let len = thread.view.notes.len();
|
||||
(len, &mut thread.view.list)
|
||||
@@ -95,15 +126,11 @@ impl<'a> ThreadView<'a> {
|
||||
|
||||
let ind = len - 1 - start_index;
|
||||
let note_key = {
|
||||
let thread = self
|
||||
.app
|
||||
.threads
|
||||
.thread_mut(&self.app.ndb, &txn, root_id)
|
||||
.get_ptr();
|
||||
let thread = self.threads.thread_mut(self.ndb, &txn, root_id).get_ptr();
|
||||
thread.view.notes[ind].key
|
||||
};
|
||||
|
||||
let note = if let Ok(note) = self.app.ndb.get_note_by_key(&txn, note_key) {
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, note_key) {
|
||||
note
|
||||
} else {
|
||||
warn!("failed to query note {:?}", note_key);
|
||||
@@ -111,13 +138,22 @@ impl<'a> ThreadView<'a> {
|
||||
};
|
||||
|
||||
ui::padding(8.0, ui, |ui| {
|
||||
let textmode = self.app.textmode;
|
||||
let resp = ui::NoteView::new(self.app, ¬e)
|
||||
.note_previews(!textmode)
|
||||
.show(ui);
|
||||
let resp =
|
||||
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e)
|
||||
.note_previews(!self.textmode)
|
||||
.textmode(self.textmode)
|
||||
.show(ui);
|
||||
|
||||
if let Some(action) = resp.action {
|
||||
let br = action.execute(self.app, self.timeline, note.id(), &txn);
|
||||
let br = action.execute(
|
||||
self.ndb,
|
||||
self.columns.column_mut(self.column),
|
||||
self.threads,
|
||||
self.note_cache,
|
||||
self.pool,
|
||||
note.id(),
|
||||
&txn,
|
||||
);
|
||||
if br.is_some() {
|
||||
result = br;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user