wip algo timelines

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-12-25 19:06:04 -08:00
parent 7afe3b7d7c
commit 662755550f
5 changed files with 556 additions and 159 deletions

View File

@@ -4,6 +4,7 @@ use crate::{
error::Error,
subscriptions::{self, SubKind, Subscriptions},
thread::Thread,
timeline::kind::ListKind,
Result,
};
@@ -29,7 +30,7 @@ pub mod kind;
pub mod route;
pub use cache::{TimelineCache, TimelineCacheKey};
pub use kind::{ColumnTitle, PubkeySource, TimelineKind};
pub use kind::{AlgoTimeline, ColumnTitle, PubkeySource, TimelineKind};
pub use route::TimelineRoute;
#[derive(Debug, Hash, Copy, Clone, Eq, PartialEq)]
@@ -227,6 +228,18 @@ impl Timeline {
)
}
pub fn last_per_pubkey(list: &Note, list_kind: &ListKind) -> Result<Self> {
let kind = 1;
let notes_per_pk = 1;
let filter = filter::last_n_per_pubkey_from_tags(list, kind, notes_per_pk)?;
Ok(Timeline::new(
TimelineKind::last_per_pubkey(list_kind.clone()),
FilterState::ready(filter),
TimelineTab::only_notes_and_replies(),
))
}
pub fn hashtag(hashtag: String) -> Self {
let filter = Filter::new()
.kinds([1])
@@ -397,6 +410,11 @@ impl Timeline {
note_cache: &mut NoteCache,
reversed: bool,
) -> Result<()> {
if !self.kind.should_subscribe_locally() {
// don't need to poll for timelines that don't have local subscriptions
return Ok(());
}
let sub = self
.subscription
.ok_or(Error::App(notedeck::Error::no_active_sub()))?;
@@ -601,13 +619,20 @@ fn setup_initial_timeline(
note_cache: &mut NoteCache,
filters: &[Filter],
) -> Result<()> {
timeline.subscription = Some(ndb.subscribe(filters)?);
// some timelines are one-shot and a refreshed, like last_per_pubkey algo feed
if timeline.kind.should_subscribe_locally() {
timeline.subscription = Some(ndb.subscribe(filters)?);
}
let txn = Transaction::new(ndb)?;
debug!(
"querying nostrdb sub {:?} {:?}",
timeline.subscription, timeline.filter
);
let lim = filters[0].limit().unwrap_or(filter::default_limit()) as i32;
let mut lim = 0i32;
for filter in filters {
lim += filter.limit().unwrap_or(1) as i32;
}
let notes: Vec<NoteRef> = ndb
.query(&txn, filters, lim)?