notecache: add initial in-memory notecache

This is useful for things like relative time strings and other
transient note cache state

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-02-15 13:03:46 -08:00
parent c246b9d92f
commit 2ce2d4cc70
3 changed files with 27 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ use crate::error::Error;
use crate::fonts::setup_gossip_fonts;
use crate::frame_history::FrameHistory;
use crate::images::fetch_img;
use crate::notecache::NoteCache;
use crate::timeline;
use crate::ui::padding;
use crate::Result;
@@ -97,6 +98,7 @@ pub struct Damus {
compose: String,
initial_filter: Vec<enostr::Filter>,
note_cache: HashMap<NoteKey, NoteCache>,
pool: RelayPool,
timelines: Vec<Timeline>,
@@ -449,6 +451,7 @@ impl Damus {
state: DamusState::Initializing,
pool: RelayPool::new(),
img_cache: HashMap::new(),
note_cache: HashMap::new(),
initial_filter,
n_panels: 1,
timelines: vec![Timeline::new()],
@@ -457,6 +460,12 @@ impl Damus {
frame_history: FrameHistory::default(),
}
}
pub fn get_note_cache_mut(&mut self, note_ref: &NoteRef) -> &mut NoteCache {
self.note_cache
.entry(note_ref.key)
.or_insert_with(|| NoteCache::new(note_ref.created_at))
}
}
fn render_pfp(ui: &mut egui::Ui, img_cache: &mut ImageCache, url: &str) {