update - many samll fixes with the duplication and otehr things
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{collections::VecDeque, hash::{Hash, Hasher}, sync::{Arc, Mutex}, thread};
|
||||
use std::{collections::{HashSet, VecDeque}, hash::{Hash, Hasher}, sync::{Arc, Mutex}, thread};
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
@@ -37,19 +37,35 @@ fn main() {
|
||||
let message = pubsub.get_message().unwrap();
|
||||
|
||||
let payload_string: String = message.get_payload().unwrap();
|
||||
println!("{payload_string}");
|
||||
//println!("{payload_string}");
|
||||
let notif: Vec<Notification> = serde_json::from_str(payload_string.as_str()).unwrap();
|
||||
println!("Just recieved: {:#?}", notif);
|
||||
//println!("Just recieved: {:#?}", notif);
|
||||
for notification in notif{
|
||||
reference_arc.lock().unwrap().push_front(notification.clone());
|
||||
reference_arc.lock().unwrap().push_back(notification.clone());
|
||||
}
|
||||
while reference_arc.lock().unwrap().len() > 10{
|
||||
reference_arc.lock().unwrap().pop_back();
|
||||
reference_arc.lock().unwrap().pop_front();
|
||||
|
||||
}
|
||||
let unique_vec: VecDeque<_> = reference_arc.lock().unwrap().clone().into_iter().collect::<std::collections::HashSet<_>>().into_iter().collect();
|
||||
*reference_arc.lock().unwrap()=unique_vec;
|
||||
}
|
||||
println!("Current vec length: {}", reference_arc.lock() .unwrap().len());
|
||||
let temp_mutable_ref = reference_arc.lock().unwrap().clone();
|
||||
let mut temp_hash_set: HashSet<Notification> = HashSet::new();
|
||||
for notif_in_order in temp_mutable_ref{
|
||||
let add: bool = temp_hash_set.insert(notif_in_order.clone());
|
||||
|
||||
if !add{
|
||||
let notif_clone = notif_in_order.clone();
|
||||
if let Some(position) = reference_arc.lock().unwrap().iter().position(|x| *x==notif_clone){
|
||||
reference_arc.lock().unwrap().remove(position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
println!("Current vec length: {}", reference_arc.lock() .unwrap().len());
|
||||
|
||||
|
||||
}
|
||||
}) ;
|
||||
dioxus::launch(App);
|
||||
}
|
||||
@@ -81,3 +97,4 @@ impl Hash for Notification{
|
||||
self.url.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user