mirror of
https://git.alemi.dev/mumble-stats-api.git
synced 2024-11-22 16:04:49 +01:00
fix: update users instead of replacing
also track but filter out local user
This commit is contained in:
parent
02c631c9e2
commit
7f0516dd1e
2 changed files with 28 additions and 6 deletions
17
src/model.rs
17
src/model.rs
|
@ -63,6 +63,23 @@ pub struct UserProperties {
|
||||||
pub recording: bool,
|
pub recording: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl User {
|
||||||
|
pub fn update(&mut self, state: crate::tcp::proto::UserState) {
|
||||||
|
if state.session() != self.session { tracing::warn!("updating with different session??") }
|
||||||
|
if let Some(actor) = state.actor { self.actor = actor }
|
||||||
|
if let Some(name) = state.name { self.name = name }
|
||||||
|
if let Some(user_id) = state.user_id { self.user_id = Some(user_id) }
|
||||||
|
if let Some(comment) = state.comment { self.comment = Some(comment) }
|
||||||
|
if let Some(mute) = state.mute { self.properties.mute = mute }
|
||||||
|
if let Some(deaf) = state.deaf { self.properties.deaf = deaf }
|
||||||
|
if let Some(suppress) = state.suppress { self.properties.suppress = suppress }
|
||||||
|
if let Some(self_mute) = state.self_mute { self.properties.self_mute = self_mute }
|
||||||
|
if let Some(self_deaf) = state.self_deaf { self.properties.self_deaf = self_deaf }
|
||||||
|
if let Some(priority_speaker) = state.priority_speaker { self.properties.priority_speaker = priority_speaker }
|
||||||
|
if let Some(recording) = state.recording { self.properties.recording = recording }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl From<crate::tcp::proto::UserState> for User {
|
impl From<crate::tcp::proto::UserState> for User {
|
||||||
fn from(value: crate::tcp::proto::UserState) -> Self {
|
fn from(value: crate::tcp::proto::UserState) -> Self {
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{model::User, tcp::{control::ControlChannel, proto}, udp::proto::{Pin
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
users: RwLock<HashMap<u32, User>>,
|
users: RwLock<HashMap<u32, User>>,
|
||||||
|
username: String,
|
||||||
host: String,
|
host: String,
|
||||||
sync: watch::Receiver<bool>,
|
sync: watch::Receiver<bool>,
|
||||||
drop: mpsc::Sender<()>,
|
drop: mpsc::Sender<()>,
|
||||||
|
@ -61,7 +62,12 @@ impl Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn users(&self) -> Vec<User> {
|
pub async fn users(&self) -> Vec<User> {
|
||||||
self.users.read().await.borrow().values().cloned().collect()
|
self.users.read().await
|
||||||
|
.borrow()
|
||||||
|
.values()
|
||||||
|
.filter(|u| u.name != self.username)
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn host(&self) -> String {
|
pub fn host(&self) -> String {
|
||||||
|
@ -94,13 +100,12 @@ impl Session {
|
||||||
channel.send(pkt).await?;
|
channel.send(pkt).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (tx, mut rx) = mpsc::channel(1);
|
let (drop, mut stop) = mpsc::channel(1);
|
||||||
let (ready_tx, ready) = watch::channel(false);
|
let (ready, sync) = watch::channel(false);
|
||||||
|
|
||||||
let s = Arc::new(Session {
|
let s = Arc::new(Session {
|
||||||
|
username, drop, sync,
|
||||||
users : RwLock::new(HashMap::new()),
|
users : RwLock::new(HashMap::new()),
|
||||||
sync: ready,
|
|
||||||
drop: tx,
|
|
||||||
host: host.to_string(),
|
host: host.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -108,7 +113,7 @@ impl Session {
|
||||||
let chan = channel.clone();
|
let chan = channel.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
match rx.try_recv() {
|
match stop.try_recv() {
|
||||||
Ok(()) => break,
|
Ok(()) => break,
|
||||||
Err(mpsc::error::TryRecvError::Empty) => {},
|
Err(mpsc::error::TryRecvError::Empty) => {},
|
||||||
Err(mpsc::error::TryRecvError::Disconnected) => break tracing::warn!("all session dropped without stopping this task, stopping..."),
|
Err(mpsc::error::TryRecvError::Disconnected) => break tracing::warn!("all session dropped without stopping this task, stopping..."),
|
||||||
|
|
Loading…
Reference in a new issue