| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- use crate::{id_list::IdList, info_list::InfoList, node_info::NodeInfo};
- //use smol::Timer;
- //use std::{collections::HashMap, time::Duration};
- // make a structure to be able to modify and read them
- // protect using a mutex
- // arc reference
- #[derive(Clone)]
- pub struct App {
- pub id_list: IdList,
- pub info_list: InfoList,
- }
- impl App {
- pub fn new() -> App {
- let infos = vec![
- NodeInfo {
- id: "0385048034sodisofjhosd1111q3434".to_string(),
- connections: 10,
- is_active: true,
- last_message: "hey how are you?".to_string(),
- },
- NodeInfo {
- id: "09w30we9wsnfksdfkdjflsjkdfjdfsd".to_string(),
- connections: 5,
- is_active: false,
- last_message: "lmao".to_string(),
- },
- NodeInfo {
- id: "038043325alsdlasjfrsdfsdfsdjsdf".to_string(),
- connections: 7,
- is_active: true,
- last_message: "gm".to_string(),
- },
- NodeInfo {
- id: "04985034953ldflsdjflsdjflsdjfii".to_string(),
- connections: 2,
- is_active: true,
- last_message: "hihi".to_string(),
- },
- NodeInfo {
- id: "09850249352asdjapsdikalskasdkas".to_string(),
- connections: 10,
- is_active: true,
- last_message: "wtf".to_string(),
- },
- ];
- let info_list = InfoList::new(infos.clone());
- let ids = vec![
- infos[0].id.clone(),
- infos[1].id.clone(),
- infos[2].id.clone(),
- infos[3].id.clone(),
- infos[4].id.clone(),
- ];
- let id_list = IdList::new(ids);
- //let infos = Vec::new();
- //let ids = Vec::new();
- //let info_list = InfoList::new(infos);
- //let id_list = IdList::new(ids);
- App { id_list, info_list }
- }
- // TODO: implement this
- //async fn sleep(self, dur: Duration) {
- // Timer::after(dur).await;
- //}
- pub async fn update(mut self, node_vec: Vec<NodeInfo>) -> App {
- let ids = vec![node_vec[0].id.clone()];
- for id in ids {
- self.id_list.node_id.push(id);
- }
- let id_list = self.id_list;
- for info in node_vec {
- self.info_list.infos.push(info);
- }
- let info_list = self.info_list;
- App { id_list, info_list }
- }
- }
- impl Default for App {
- fn default() -> Self {
- Self::new()
- }
- }
|