From 2417f087194a871d25fd829996cb5a6613ec8745 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 21 Dec 2021 11:28:00 +0100 Subject: Make timeline deduplicating Signed-off-by: Matthias Beyer --- gui/src/timeline.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gui/src/timeline.rs b/gui/src/timeline.rs index 0dace40..85cd0d5 100644 --- a/gui/src/timeline.rs +++ b/gui/src/timeline.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use anyhow::Result; use futures::StreamExt; @@ -11,6 +13,7 @@ use distrox_lib::types::Payload; #[derive(Debug)] pub struct Timeline { + post_ids: HashSet, posts: Vec, scrollable: ScrollableState, } @@ -18,13 +21,16 @@ pub struct Timeline { impl Timeline { pub fn new() -> Self { Self { + post_ids: HashSet::with_capacity(1000), posts: Vec::new(), scrollable: ScrollableState::new(), } } pub fn push(&mut self, payload: Payload, content: String) { - self.posts.push(Post::new(payload, content)); + if self.post_ids.insert(payload.content()) { + self.posts.push(Post::new(payload, content)); + } } pub fn view(&mut self) -> iced::Element { -- cgit v1.2.3