diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-21 11:31:00 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-21 11:32:07 +0100 |
commit | 5a86b1e44467f1d5439fe6f447c55f33c35f564f (patch) | |
tree | 88369fae11c17a338758c8e2a3e6dc43a981cf54 | |
parent | e44417036291dd9755dc768d06355f985ad2e61d (diff) |
Change timeline to be ordered internally
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | gui/src/timeline.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gui/src/timeline.rs b/gui/src/timeline.rs index 85cd0d5..75f3c73 100644 --- a/gui/src/timeline.rs +++ b/gui/src/timeline.rs @@ -1,4 +1,5 @@ use std::collections::HashSet; +use std::collections::BTreeMap; use anyhow::Result; use futures::StreamExt; @@ -10,11 +11,12 @@ use crate::post::Post; use distrox_lib::client::Client; use distrox_lib::stream::NodeStreamBuilder; use distrox_lib::types::Payload; +use distrox_lib::types::DateTime; #[derive(Debug)] pub struct Timeline { post_ids: HashSet<cid::Cid>, - posts: Vec<Post>, + posts: BTreeMap<DateTime, Post>, scrollable: ScrollableState, } @@ -22,14 +24,14 @@ impl Timeline { pub fn new() -> Self { Self { post_ids: HashSet::with_capacity(1000), - posts: Vec::new(), + posts: BTreeMap::new(), scrollable: ScrollableState::new(), } } pub fn push(&mut self, payload: Payload, content: String) { if self.post_ids.insert(payload.content()) { - self.posts.push(Post::new(payload, content)); + self.posts.insert(payload.timestamp().clone(), Post::new(payload, content)); } } @@ -45,7 +47,8 @@ impl Timeline { self.posts .iter() - .fold(scrollable, |scrollable, post| { + .rev() + .fold(scrollable, |scrollable, (_, post)| { scrollable.push(post.view()) }) .into() |