From 52a4740f252391c944bf910c1a81a07bd7aea610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 10:00:33 +0200 Subject: always send user joined/left channels and events --- mumd/src/state.rs | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index cdd663d..8d92877 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -134,21 +134,23 @@ impl State { if matches!(*self.phase_receiver().borrow(), StatePhase::Connected(_)) { let this_channel = msg.get_channel_id(); let other_channel = self.get_users_channel(self.server().unwrap().session_id().unwrap()); - //TODO can this fail? - let this_channel_name = self.server().unwrap().channels().get(&this_channel).map(|c| c.name()); + let this_channel_name = self + .server() + .unwrap() + .channels() + .get(&this_channel) + .map(|c| c.name()) + .unwrap_or("") + .to_string(); if this_channel == other_channel { - if let Some(this_channel_name) = this_channel_name { - notifications::send(format!( - "{} connected and joined {}", - msg.get_name(), - this_channel_name, - )); - } - let this_channel_name = this_channel_name.map(|s| s.to_string()); + notifications::send(format!( + "{} connected and joined {}", + msg.get_name(), + this_channel_name, + )); self.push_event(MumbleEventKind::UserConnected(msg.get_name().to_string(), this_channel_name)); - self.audio_output - .play_effect(NotificationEvents::UserConnected); + self.audio_output.play_effect(NotificationEvents::UserConnected); } } } @@ -248,14 +250,25 @@ impl State { let this_channel = self.get_users_channel(self.server().unwrap().session_id().unwrap()); let other_channel = self.get_users_channel(msg.get_session()); if this_channel == other_channel { - let channel_name = self.server().unwrap().channels().get(&this_channel).map(|c| c.name().to_string()); - self.audio_output - .play_effect(NotificationEvents::UserDisconnected); - if let Some(user) = self.server().unwrap().users().get(&msg.get_session()) { - notifications::send(format!("{} disconnected", &user.name())); - let user_name = user.name().to_string(); - self.push_event(MumbleEventKind::UserDisconnected(user_name, channel_name)); - } + let channel_name = self + .server() + .unwrap() + .channels() + .get(&this_channel) + .map(|c| c.name()) + .unwrap_or("") + .to_string(); + let user_name = self + .server() + .unwrap() + .users() + .get(&msg.get_session()) + .map(|u| u.name()) + .unwrap_or("") + .to_string(); + notifications::send(format!("{} disconnected", &user_name)); + self.push_event(MumbleEventKind::UserDisconnected(user_name, channel_name)); + self.audio_output.play_effect(NotificationEvents::UserDisconnected); } self.server_mut() -- cgit v1.2.1