From 6a9e74def5010e29abe62be81c3f53e8943b2d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 23 Oct 2020 03:32:50 +0200 Subject: notif if user muted/unmuted --- mumd/src/state.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ mumd/src/state/user.rs | 8 ++++++++ 2 files changed, 51 insertions(+) (limited to 'mumd/src') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 3aff353..2093c7c 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -252,6 +252,18 @@ impl State { fn parse_updated_user_state(&mut self, session: u32, msg: msgs::UserState) -> mumlib::state::UserDiff { let user = self.server_mut().unwrap().users_mut().get_mut(&session).unwrap(); + + let mute = if msg.has_self_mute() && user.self_mute() != msg.get_self_mute() { + Some(msg.get_self_mute()) + } else { + None + }; + let deaf = if msg.has_self_deaf() && user.self_deaf() != msg.get_self_deaf() { + Some(msg.get_self_deaf()) + } else { + None + }; + let diff = mumlib::state::UserDiff::from(msg); user.apply_user_diff(&diff); let user = self.server().unwrap().users().get(&session).unwrap(); @@ -271,6 +283,37 @@ impl State { } } + // send notification if a user muted/unmuted + //TODO our channel only + let notif_desc = + if let Some(deaf) = deaf { + if deaf { + Some(format!("{} muted and deafend themselves", &user.name())) + } else if !deaf { + Some(format!("{} unmuted and undeafend themselves", &user.name())) + } else { + warn!("Invalid user state received"); + None + } + } else if let Some(mute) = mute { + if mute { + Some(format!("{} muted themselves", &user.name())) + } else if !mute { + Some(format!("{} unmuted themselves", &user.name())) + } else { + warn!("Invalid user state received"); + None + } + } else { + None + }; + if let Some(notif_desc) = notif_desc { + libnotify::Notification::new("mumd", + notif_desc.as_str(), + None) + .show().unwrap(); + } + diff } diff --git a/mumd/src/state/user.rs b/mumd/src/state/user.rs index 98f34bc..848208c 100644 --- a/mumd/src/state/user.rs +++ b/mumd/src/state/user.rs @@ -121,6 +121,14 @@ impl User { pub fn channel(&self) -> u32 { self.channel } + + pub fn self_mute(&self) -> bool { + self.self_mute + } + + pub fn self_deaf(&self) -> bool { + self.self_deaf + } } impl From<&User> for mumlib::state::User { -- cgit v1.2.1