commit 95e9e4326a8d1a3a843e444e71b3d7dc48147342
parent 4db6f37017dc8e0ec58a7b0b489ee0e494a100d0
Author: kernelkind <kernelkind@gmail.com>
Date: Tue, 15 Jul 2025 16:04:50 -0400
add `TimelineCache` helper methods
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/crates/notedeck_columns/src/timeline/cache.rs b/crates/notedeck_columns/src/timeline/cache.rs
@@ -38,6 +38,15 @@ impl<'a, M> Vitality<'a, M> {
}
}
+impl<'a> IntoIterator for &'a mut TimelineCache {
+ type Item = (&'a TimelineKind, &'a mut Timeline);
+ type IntoIter = std::collections::hash_map::IterMut<'a, TimelineKind, Timeline>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.timelines.iter_mut()
+ }
+}
+
impl TimelineCache {
/// Pop a timeline from the timeline cache. This only removes the timeline
/// if it has reached 0 subscribers, meaning it was the last one to be
@@ -95,6 +104,14 @@ impl TimelineCache {
self.timelines.insert(id, timeline);
}
+ pub fn insert(&mut self, id: TimelineKind, timeline: Timeline) {
+ if let Some(_cur_timeline) = self.timelines.get_mut(&id) {
+ return;
+ };
+
+ self.timelines.insert(id, timeline);
+ }
+
/// Get and/or update the notes associated with this timeline
pub fn notes<'a>(
&'a mut self,
@@ -190,6 +207,18 @@ impl TimelineCache {
open_result
}
+
+ pub fn get(&self, id: &TimelineKind) -> Option<&Timeline> {
+ self.timelines.get(id)
+ }
+
+ pub fn get_mut(&mut self, id: &TimelineKind) -> Option<&mut Timeline> {
+ self.timelines.get_mut(id)
+ }
+
+ pub fn num_timelines(&self) -> usize {
+ self.timelines.len()
+ }
}
/// Look for new thread notes since our last fetch