switch to TimelineCache

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-01-19 12:42:41 -08:00
parent e52ba5937f
commit 4b542c0a74
19 changed files with 720 additions and 673 deletions

View File

@@ -2,7 +2,7 @@ use crate::error::Error;
use crate::timeline::{Timeline, TimelineTab};
use enostr::{Filter, Pubkey};
use nostrdb::{Ndb, Transaction};
use notedeck::{filter::default_limit, FilterError, FilterState};
use notedeck::{filter::default_limit, FilterError, FilterState, RootNoteIdBuf};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, fmt::Display};
use tracing::{error, warn};
@@ -58,6 +58,9 @@ pub enum TimelineKind {
Profile(PubkeySource),
/// This could be any note id, doesn't need to be the root id
Thread(RootNoteIdBuf),
Universe,
/// Generic filter
@@ -75,6 +78,7 @@ impl Display for TimelineKind {
TimelineKind::Profile(_) => f.write_str("Profile"),
TimelineKind::Universe => f.write_str("Universe"),
TimelineKind::Hashtag(_) => f.write_str("Hashtag"),
TimelineKind::Thread(_) => f.write_str("Thread"),
}
}
}
@@ -88,6 +92,7 @@ impl TimelineKind {
TimelineKind::Universe => None,
TimelineKind::Generic => None,
TimelineKind::Hashtag(_ht) => None,
TimelineKind::Thread(_ht) => None,
}
}
@@ -103,6 +108,10 @@ impl TimelineKind {
TimelineKind::Profile(pk)
}
pub fn thread(root_id: RootNoteIdBuf) -> Self {
TimelineKind::Thread(root_id)
}
pub fn is_notifications(&self) -> bool {
matches!(self, TimelineKind::Notifications(_))
}
@@ -122,6 +131,8 @@ impl TimelineKind {
TimelineTab::no_replies(),
)),
TimelineKind::Thread(root_id) => Some(Timeline::thread(root_id)),
TimelineKind::Generic => {
warn!("you can't convert a TimelineKind::Generic to a Timeline");
None
@@ -213,6 +224,7 @@ impl TimelineKind {
},
TimelineKind::Notifications(_pubkey_source) => ColumnTitle::simple("Notifications"),
TimelineKind::Profile(_pubkey_source) => ColumnTitle::needs_db(self),
TimelineKind::Thread(_root_id) => ColumnTitle::simple("Thread"),
TimelineKind::Universe => ColumnTitle::simple("Universe"),
TimelineKind::Generic => ColumnTitle::simple("Custom"),
TimelineKind::Hashtag(hashtag) => ColumnTitle::formatted(hashtag.to_string()),