From f72440096cefecbe62a37813ea3ee6f3cd3c7299 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 21 May 2021 21:48:14 +0200 Subject: add connectivity check --- mumd/src/state.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index ce915ac..8072b8e 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -621,6 +621,10 @@ pub fn handle_command( now!(Ok(None)) } Command::PastMessages { block } => { + //does it make sense to wait for messages while not connected? + if !matches!(*state.phase_receiver().borrow(), StatePhase::Connected(_)) { + return now!(Err(Error::Disconnected)); + } if block { let ref_state = Arc::clone(&og_state); ExecutionContext::TcpEventSubscriber( @@ -629,7 +633,7 @@ pub fn handle_command( if let TcpEventData::TextMessage(a) = data { let message = ( a.get_message().to_owned(), - ref_state.read().unwrap().get_user_name(a.get_actor()) + ref_state.read().unwrap().get_user_name(a.get_actor()).unwrap() ); sender.send(Ok(Some(CommandResponse::PastMessage { message }))).is_ok() } else { @@ -640,7 +644,7 @@ pub fn handle_command( } else { let messages = std::mem::take(&mut state.message_buffer); let messages = messages.into_iter() - .map(|(msg, user)| (msg, state.get_user_name(user))) + .map(|(msg, user)| (msg, state.get_user_name(user).unwrap())) .collect(); now!(Ok(Some(CommandResponse::PastMessages { messages }))) -- cgit v1.2.1