use super::{proto::hunter::*, *};
use std::collections::HashMap;
pub struct DeliNote {
users: HashMap<u32, User>,
int: i32,
}
impl DeliNote {
fn new() -> Self {
Self {
users: HashMap::new(),
int: 0,
}
}
fn add_user(&mut self, id: u32) {
self.users.insert(
id,
User {
name: "new user".to_string(),
},
);
}
fn remove_user(&mut self, id: &u32) {
self.users.remove(&id);
}
fn set_input(&mut self, _id: u32, _input: CellInput) {
debug!("TODO: handle input");
}
}
pub fn run(tx: UnboundedSender<BroadcastEvents>, mut rx: UnboundedReceiver<CollabEvents>) {
let mut note = DeliNote::new();
while let Ok(event) = rx.try_recv() {
match event {
CollabEvents::Join(conn) => {
note.add_user(conn.id);
tx.send(BroadcastEvents::Join(conn)).ok();
}
CollabEvents::Quit(id) => {
note.remove_user(&id);
tx.send(BroadcastEvents::Quit(id)).ok();
}
CollabEvents::Input(id, input) => {
note.set_input(id, input);
}
}
}
}