diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-21 11:28:00 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-21 11:28:00 +0100 |
commit | 2417f087194a871d25fd829996cb5a6613ec8745 (patch) | |
tree | 6613ee234bf28a2deffc7f9141ee8d847241a1da | |
parent | bf097c9b5b57289e2ab792df9494f4579ce08d6c (diff) |
Make timeline deduplicating
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | gui/src/timeline.rs | 8 |
1 files changed, 7 insertions, 1 deletions
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<cid::Cid>, posts: Vec<Post>, 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<Message> { |