aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-23 01:50:20 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-10-23 01:50:20 +0200
commit8e35c18e2aac958837b2c8fcb782950f86e5f214 (patch)
tree1215c65f89961f3e6ce2e914abda73ef68ad6dd1
parentcd3c1ad6c508a698314ecc59ae6de320263f740d (diff)
downloadmum-8e35c18e2aac958837b2c8fcb782950f86e5f214.tar.gz
add first notification
-rw-r--r--Cargo.lock105
-rw-r--r--mumd/Cargo.toml1
-rw-r--r--mumd/src/main.rs1
-rw-r--r--mumd/src/state.rs15
-rw-r--r--mumd/src/state/user.rs6
5 files changed, 126 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d1ba33d..239a3b0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -420,6 +420,33 @@ dependencies = [
]
[[package]]
+name = "gdk-pixbuf"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "16160d212ae91abe9f3324c3fb233929ba322dde63585d15cda3336f8c529ed1"
+dependencies = [
+ "gdk-pixbuf-sys",
+ "glib",
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+]
+
+[[package]]
+name = "gdk-pixbuf-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "798f97101eea8180da363d0e80e07ec7ec6d1809306601c0100c1de5bc8b4f52"
+dependencies = [
+ "bitflags",
+ "gio-sys",
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
name = "getrandom"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -431,12 +458,61 @@ dependencies = [
]
[[package]]
+name = "gio-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a303bbf7a5e75ab3b627117ff10e495d1b9e97e1d68966285ac2b1f6270091bc"
+dependencies = [
+ "bitflags",
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
+name = "glib"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9b0452824cc63066940f01adc721804919f0b76cdba3cfab977b00b87f16d4a"
+dependencies = [
+ "bitflags",
+ "glib-sys",
+ "gobject-sys",
+ "lazy_static",
+ "libc",
+]
+
+[[package]]
+name = "glib-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9693049613ff52b93013cc3d2590366d8e530366d288438724b73f6c7dc4be8"
+dependencies = [
+ "bitflags",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
+name = "gobject-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60d507c87a71b1143c66ed21a969be9b99a76df234b342d733e787e6c9c7d7c2"
+dependencies = [
+ "bitflags",
+ "glib-sys",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
name = "hermit-abi"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -520,6 +596,34 @@ dependencies = [
]
[[package]]
+name = "libnotify"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10506a4f8bc6f8f7ccc6fde3a8290378d7aed3d1a26dca606a73e2ffe140cc2d"
+dependencies = [
+ "gdk-pixbuf",
+ "gdk-pixbuf-sys",
+ "glib",
+ "glib-sys",
+ "gobject-sys",
+ "libnotify-sys",
+]
+
+[[package]]
+name = "libnotify-sys"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0a716b9b7d24ed10f1eb431e1527fa13c9a4bf2d4fa68bb3e54da1d0747383c"
+dependencies = [
+ "bitflags",
+ "gdk-pixbuf-sys",
+ "glib-sys",
+ "gobject-sys",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
name = "lock_api"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -657,6 +761,7 @@ dependencies = [
"futures",
"futures-util",
"ipc-channel",
+ "libnotify",
"log",
"mumble-protocol",
"mumlib",
diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml
index ffb463a..c59c32b 100644
--- a/mumd/Cargo.toml
+++ b/mumd/Cargo.toml
@@ -17,6 +17,7 @@ cpal = { git = "https://github.com/RustAudio/cpal" }
futures = "0.3"
futures-util = "0.3"
ipc-channel = "0.14"
+libnotify = "1.0"
log = "0.4"
mumble-protocol = "0.3"
native-tls = "0.2"
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index e88eede..79e44a2 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -22,6 +22,7 @@ use tokio::task::spawn_blocking;
#[tokio::main]
async fn main() {
setup_logger(std::io::stderr(), true);
+ libnotify::init("mumd").unwrap();
// Oneshot channel for setting UDP CryptState from control task
// For simplicity we don't deal with re-syncing, real applications would have to.
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index 44d8b21..6180654 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -228,6 +228,21 @@ impl State {
let user = self.server_mut().unwrap().users_mut().get_mut(&sess).unwrap();
let diff = mumlib::state::UserDiff::from(msg);
user.apply_user_diff(&diff);
+ let user = self.server().unwrap().users().get(&sess).unwrap();
+
+ // send notification
+ if let Some(channel_id) = diff.channel_id {
+ if let Some(channel) = self.server().unwrap().channels().get(&channel_id) {
+ libnotify::Notification::new("mumd",
+ Some(format!("{} moved to channel {}",
+ &user.name(),
+ channel.name()).as_str()),
+ None).show().unwrap();
+ } else {
+ warn!("{} moved to invalid channel {}", &user.name(), channel_id);
+ }
+ }
+
Some(diff)
}
}
diff --git a/mumd/src/state/user.rs b/mumd/src/state/user.rs
index 679d0ff..ab867e6 100644
--- a/mumd/src/state/user.rs
+++ b/mumd/src/state/user.rs
@@ -1,6 +1,10 @@
+use crate::state::channel::Channel;
+
use log::*;
use mumble_protocol::control::msgs;
use serde::{Deserialize, Serialize};
+use std::collections::HashMap;
+use std::collections::hash_map::Entry;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User {
@@ -80,7 +84,6 @@ impl User {
}
pub fn apply_user_diff(&mut self, diff: &mumlib::state::UserDiff) {
- debug!("applying user diff\n{:#?}", diff);
if let Some(comment) = diff.comment.clone() {
self.comment = Some(comment);
}
@@ -111,7 +114,6 @@ impl User {
if let Some(deaf) = diff.deaf {
self.deaf = deaf;
}
-
if let Some(channel_id) = diff.channel_id {
self.channel = channel_id;
}