split notedeck into crates
This splits notedeck into crates, separating the browser chrome and individual apps: * notedeck: binary file, browser chrome * notedeck_columns: our columns app * enostr: same as before We still need to do more work to cleanly separate the chrome apis from the app apis. Soon I will create notedeck-notebook to see what makes sense to be shared between the apps. Some obvious ones that come to mind: 1. ImageCache We will likely want to move this to the notedeck crate, as most apps will want some kind of image cache. In web browsers, web pages do not need to worry about this, so we will likely have to do something similar 2. Ndb Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely copied to each app. This will simplify things. In the future we might want to create an abstraction over this? Maybe each app shouldn't have access to the same database... we assume the data in DBs are all public anyways, but if we have unwrapped giftwraps that could be a problem. 3. RelayPool / Subscription Manager The browser should probably maintain these. Then apps can use ken's high level subscription manager api and not have to worry about connection pool details 4. Accounts Accounts and key management should be handled by the chrome. Apps should only have a simple signer interface. That's all for now, just something to think about! Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
132
crates/notedeck_columns/src/ui/thread.rs
Normal file
132
crates/notedeck_columns/src/ui/thread.rs
Normal file
@@ -0,0 +1,132 @@
|
||||
use crate::{
|
||||
actionbar::NoteAction,
|
||||
imgcache::ImageCache,
|
||||
muted::MuteFun,
|
||||
notecache::NoteCache,
|
||||
notes_holder::{NotesHolder, NotesHolderStorage},
|
||||
thread::Thread,
|
||||
ui::note::NoteOptions,
|
||||
unknowns::UnknownIds,
|
||||
};
|
||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||
use tracing::error;
|
||||
|
||||
use super::timeline::TimelineTabView;
|
||||
|
||||
pub struct ThreadView<'a> {
|
||||
threads: &'a mut NotesHolderStorage<Thread>,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
img_cache: &'a mut ImageCache,
|
||||
selected_note_id: &'a [u8; 32],
|
||||
textmode: bool,
|
||||
id_source: egui::Id,
|
||||
}
|
||||
|
||||
impl<'a> ThreadView<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
threads: &'a mut NotesHolderStorage<Thread>,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
img_cache: &'a mut ImageCache,
|
||||
selected_note_id: &'a [u8; 32],
|
||||
textmode: bool,
|
||||
) -> Self {
|
||||
let id_source = egui::Id::new("threadscroll_threadview");
|
||||
ThreadView {
|
||||
threads,
|
||||
ndb,
|
||||
note_cache,
|
||||
unknown_ids,
|
||||
img_cache,
|
||||
selected_note_id,
|
||||
textmode,
|
||||
id_source,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id_source(mut self, id: egui::Id) -> Self {
|
||||
self.id_source = id;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, is_muted: &MuteFun) -> Option<NoteAction> {
|
||||
let txn = Transaction::new(self.ndb).expect("txn");
|
||||
|
||||
let selected_note_key = if let Ok(key) = self
|
||||
.ndb
|
||||
.get_notekey_by_id(&txn, self.selected_note_id)
|
||||
.map(NoteKey::new)
|
||||
{
|
||||
key
|
||||
} else {
|
||||
// TODO: render 404 ?
|
||||
return None;
|
||||
};
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.")
|
||||
.color(egui::Color32::RED),
|
||||
);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt(self.id_source)
|
||||
.animated(false)
|
||||
.auto_shrink([false, false])
|
||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible)
|
||||
.show(ui, |ui| {
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, selected_note_key) {
|
||||
note
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let root_id = {
|
||||
let cached_note = self
|
||||
.note_cache
|
||||
.cached_note_or_insert(selected_note_key, ¬e);
|
||||
|
||||
cached_note
|
||||
.reply
|
||||
.borrow(note.tags())
|
||||
.root()
|
||||
.map_or_else(|| self.selected_note_id, |nr| nr.id)
|
||||
};
|
||||
|
||||
let thread = self
|
||||
.threads
|
||||
.notes_holder_mutated(self.ndb, self.note_cache, &txn, root_id, is_muted)
|
||||
.get_ptr();
|
||||
|
||||
// TODO(jb55): skip poll if ThreadResult is fresh?
|
||||
|
||||
// poll for new notes and insert them into our existing notes
|
||||
match thread.poll_notes_into_view(&txn, self.ndb, is_muted) {
|
||||
Ok(action) => {
|
||||
action.process_action(&txn, self.ndb, self.unknown_ids, self.note_cache)
|
||||
}
|
||||
Err(err) => error!("{err}"),
|
||||
};
|
||||
|
||||
// This is threadview. We are not the universe view...
|
||||
let is_universe = false;
|
||||
let mut note_options = NoteOptions::new(is_universe);
|
||||
note_options.set_textmode(self.textmode);
|
||||
|
||||
TimelineTabView::new(
|
||||
thread.view(),
|
||||
true,
|
||||
note_options,
|
||||
&txn,
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
)
|
||||
.show(ui)
|
||||
})
|
||||
.inner
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user