From 5a86b1e44467f1d5439fe6f447c55f33c35f564f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 21 Dec 2021 11:31:00 +0100 Subject: Change timeline to be ordered internally Signed-off-by: Matthias Beyer --- gui/src/timeline.rs | 11 +++++++---- 1 file 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, - posts: Vec, + posts: BTreeMap, 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() -- cgit v1.2.3