aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/state.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-06-08 10:00:33 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-06-08 10:00:33 +0200
commit52a4740f252391c944bf910c1a81a07bd7aea610 (patch)
treea7380d01cfa8b0c673370a63a3280537262c5e54 /mumd/src/state.rs
parentd3eb004bcca01c87cb12ba297e568eaf9d25cd77 (diff)
downloadmum-52a4740f252391c944bf910c1a81a07bd7aea610.tar.gz
always send user joined/left channels and events
Diffstat (limited to 'mumd/src/state.rs')
-rw-r--r--mumd/src/state.rs53
1 files changed, 33 insertions, 20 deletions
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("<unnamed channel>")
+ .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("<unnamed channel>")
+ .to_string();
+ let user_name = self
+ .server()
+ .unwrap()
+ .users()
+ .get(&msg.get_session())
+ .map(|u| u.name())
+ .unwrap_or("<unknown user>")
+ .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()