ui: move timeline view to its own file

Also add some thread methods for fetching new notes

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-07-28 16:13:08 -05:00
parent a28db5d330
commit 5be6b1ca68
6 changed files with 325 additions and 241 deletions

View File

@@ -1,3 +1,30 @@
use crate::note::NoteRef;
pub fn should_since_optimize(limit: Option<u16>, num_notes: usize) -> bool {
let limit = limit.unwrap_or(enostr::Filter::default_limit()) as usize;
// rough heuristic for bailing since optimization if we don't have enough notes
limit <= num_notes
}
pub fn since_optimize_filter_with(filter: &mut enostr::Filter, notes: &[NoteRef], since_gap: u64) {
// Get the latest entry in the events
if notes.is_empty() {
return;
}
// get the latest note
let latest = notes[0];
let since = latest.created_at - since_gap;
// update the filters
filter.since = Some(since);
}
pub fn since_optimize_filter(filter: &mut enostr::Filter, notes: &[NoteRef]) {
since_optimize_filter_with(filter, notes, 60);
}
pub fn convert_enostr_filter(filter: &enostr::Filter) -> nostrdb::Filter {
let mut nfilter = nostrdb::Filter::new();