This splits notedeck into: - notedeck - notedeck_chrome - notedeck_columns The `notedeck` crate is the library that `notedeck_chrome` and `notedeck_columns`, use. It contains common functionality related to notedeck apps such as the NoteCache, ImageCache, etc. The `notedeck_chrome` crate is the binary and ui chrome. It is responsible for managing themes, user accounts, signing, data paths, nostrdb, image caches etc. It will eventually have its own ui which has yet to be determined. For now it just manages the browser data, which is passed to apps via a new struct called `AppContext`. `notedeck_columns` is our columns app, with less responsibility now that more things are handled by `notedeck_chrome` There is still much work left to do before this is a proper browser: - process isolation - sandboxing - etc This is the beginning of a new era! We're just getting started. Signed-off-by: William Casarin <jb55@jb55.com>
94 lines
2.2 KiB
Rust
94 lines
2.2 KiB
Rust
use crate::{
|
|
multi_subscriber::MultiSubscriber,
|
|
notes_holder::NotesHolder,
|
|
timeline::{TimelineTab, ViewFilter},
|
|
};
|
|
|
|
use nostrdb::{Filter, FilterBuilder, Ndb, Transaction};
|
|
use notedeck::{MuteFun, NoteCache, NoteRef};
|
|
|
|
#[derive(Default)]
|
|
pub struct Thread {
|
|
view: TimelineTab,
|
|
pub multi_subscriber: Option<MultiSubscriber>,
|
|
}
|
|
|
|
impl Thread {
|
|
pub fn new(notes: Vec<NoteRef>) -> Self {
|
|
let mut cap = ((notes.len() as f32) * 1.5) as usize;
|
|
if cap == 0 {
|
|
cap = 25;
|
|
}
|
|
let mut view = TimelineTab::new_with_capacity(ViewFilter::NotesAndReplies, cap);
|
|
view.notes = notes;
|
|
|
|
Thread {
|
|
view,
|
|
multi_subscriber: None,
|
|
}
|
|
}
|
|
|
|
pub fn view(&self) -> &TimelineTab {
|
|
&self.view
|
|
}
|
|
|
|
pub fn view_mut(&mut self) -> &mut TimelineTab {
|
|
&mut self.view
|
|
}
|
|
|
|
fn filters_raw(root: &[u8; 32]) -> Vec<FilterBuilder> {
|
|
vec![
|
|
nostrdb::Filter::new().kinds([1]).event(root),
|
|
nostrdb::Filter::new().ids([root]).limit(1),
|
|
]
|
|
}
|
|
|
|
pub fn filters_since(root: &[u8; 32], since: u64) -> Vec<Filter> {
|
|
Self::filters_raw(root)
|
|
.into_iter()
|
|
.map(|fb| fb.since(since).build())
|
|
.collect()
|
|
}
|
|
|
|
pub fn filters(root: &[u8; 32]) -> Vec<Filter> {
|
|
Self::filters_raw(root)
|
|
.into_iter()
|
|
.map(|mut fb| fb.build())
|
|
.collect()
|
|
}
|
|
}
|
|
|
|
impl NotesHolder for Thread {
|
|
fn get_multi_subscriber(&mut self) -> Option<&mut MultiSubscriber> {
|
|
self.multi_subscriber.as_mut()
|
|
}
|
|
|
|
fn filters(for_id: &[u8; 32]) -> Vec<Filter> {
|
|
Thread::filters(for_id)
|
|
}
|
|
|
|
fn new_notes_holder(
|
|
_: &Transaction,
|
|
_: &Ndb,
|
|
_: &mut NoteCache,
|
|
_: &[u8; 32],
|
|
_: Vec<Filter>,
|
|
notes: Vec<NoteRef>,
|
|
_: &MuteFun,
|
|
) -> Self {
|
|
Thread::new(notes)
|
|
}
|
|
|
|
fn get_view(&mut self) -> &mut TimelineTab {
|
|
&mut self.view
|
|
}
|
|
|
|
fn filters_since(for_id: &[u8; 32], since: u64) -> Vec<Filter> {
|
|
Thread::filters_since(for_id, since)
|
|
}
|
|
|
|
fn set_multi_subscriber(&mut self, subscriber: MultiSubscriber) {
|
|
self.multi_subscriber = Some(subscriber);
|
|
}
|
|
}
|