diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 17:26:56 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 17:30:51 +0200 |
| commit | 4cf73b2d08bd50b38ca610ca67cad01958ca8577 (patch) | |
| tree | 0adbbc531fd74c8551b6d5f8ae1b1d5dce30f590 /mumd | |
| parent | be76c2aa51733a0cf495e92659fbcbe527f41149 (diff) | |
| download | mum-4cf73b2d08bd50b38ca610ca67cad01958ca8577.tar.gz | |
store timestamp with messages
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/Cargo.toml | 1 | ||||
| -rw-r--r-- | mumd/src/state.rs | 10 |
2 files changed, 7 insertions, 4 deletions
diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index d8e2635..1e8e63f 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -42,6 +42,7 @@ tokio-stream = "0.1.0" tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } bincode = "1.3.2" +chrono = "0.4" libnotify = { version = "1.0", optional = true } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 84583e0..4530e46 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -8,8 +8,9 @@ use crate::network::tcp::{TcpEvent, TcpEventData}; use crate::network::{ConnectionInfo, VoiceStreamType}; use crate::notifications; use crate::state::server::Server; - use crate::state::user::UserDiff; + +use chrono::NaiveDateTime; use log::*; use mumble_protocol::control::msgs; use mumble_protocol::control::ControlPacket; @@ -72,7 +73,7 @@ pub struct State { server: Option<Server>, audio_input: AudioInput, audio_output: AudioOutput, - message_buffer: Vec<(String, u32)>, + message_buffer: Vec<(NaiveDateTime, String, u32)>, phase_watcher: (watch::Sender<StatePhase>, watch::Receiver<StatePhase>), } @@ -266,7 +267,7 @@ impl State { } pub fn register_message(&mut self, msg: (String, u32)) { - self.message_buffer.push(msg); + self.message_buffer.push((chrono::Local::now().naive_local(), msg.0, msg.1)); } pub fn broadcast_phase(&self, phase: StatePhase) { @@ -650,6 +651,7 @@ pub fn handle_command( Box::new(move |data, sender| { if let TcpEventData::TextMessage(a) = data { let message = ( + chrono::Local::now().naive_local(), a.get_message().to_owned(), ref_state .read() @@ -669,7 +671,7 @@ pub fn handle_command( let messages = std::mem::take(&mut state.message_buffer); let messages: Vec<_> = messages .into_iter() - .map(|(msg, user)| (msg, state.get_user_name(user).unwrap())) + .map(|(timestamp, msg, user)| (timestamp, msg, state.get_user_name(user).unwrap())) .map(|e| Ok(Some(CommandResponse::PastMessage { message: e }))) .collect(); |
