diff --git a/src/session.rs b/src/session.rs index a43d7cc..6f3075e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -104,7 +104,8 @@ impl Session { let (ready, sync) = watch::channel(false); let s = Arc::new(Session { - username, drop, sync, + drop, sync, + username: username.clone(), users : RwLock::new(HashMap::new()), host: host.to_string(), }); @@ -122,14 +123,19 @@ impl Session { Err(e) => break tracing::warn!("disconnected from server: {}", e), // Ok(tcp::proto::Packet::TextMessage(msg)) => tracing::info!("{}", msg.message), // Ok(tcp::proto::Packet::ChannelState(channel)) => tracing::info!("discovered channel: {:?}", channel.name), - Ok(proto::Packet::ServerSync(_sync)) => ready_tx.send(true).unwrap(), + Ok(proto::Packet::ServerSync(_sync)) => { + tracing::info!("synched: {:?}", _sync); + ready.send(true).unwrap(); + }, Ok(proto::Packet::UserState(user)) => { - tracing::info!("user state: {:#?}", user); - if user.name.as_ref().is_some_and(|n| n != &username) { - session.users.write().await.insert(user.user_id(), User::from(user)); + tracing::info!("user state: {:?}", user); + let mut users = session.users.write().await; + match users.get_mut(&user.session()) { + Some(u) => u.update(user), + None => { users.insert(user.session(), User::from(user)); }, } }, - Ok(pkt) => tracing::debug!("ignoring packet {:#?}", pkt), + Ok(pkt) => tracing::info!("ignoring packet {:?}", pkt), } } });