diff --git a/cove/src/euph/room.rs b/cove/src/euph/room.rs index 2831bc6..64ddfe6 100644 --- a/cove/src/euph/room.rs +++ b/cove/src/euph/room.rs @@ -9,7 +9,7 @@ use euphoxide::api::{ UserId, }; use euphoxide::bot::instance::{ConnSnapshot, Event, Instance, InstanceConfig}; -use euphoxide::conn::{self, ConnTx}; +use euphoxide::conn::{self, ConnTx, Joined}; use log::{debug, error, info, warn}; use tokio::select; use tokio::sync::oneshot; @@ -36,6 +36,13 @@ impl State { None } } + + pub fn joined(&self) -> Option<&Joined> { + match self { + Self::Connected(_, conn::State::Joined(joined)) => Some(joined), + _ => None, + } + } } #[derive(Debug, thiserror::Error)] diff --git a/cove/src/ui/euph/room.rs b/cove/src/ui/euph/room.rs index defb955..8240ba5 100644 --- a/cove/src/ui/euph/room.rs +++ b/cove/src/ui/euph/room.rs @@ -134,10 +134,7 @@ impl EuphRoom { } pub fn room_state_joined(&self) -> Option<&Joined> { - match self.room_state() { - Some(euph::State::Connected(_, conn::State::Joined(ref joined))) => Some(joined), - _ => None, - } + self.room_state().and_then(|s| s.joined()) } pub fn stopped(&self) -> bool { @@ -216,17 +213,15 @@ impl EuphRoom { let room_state = self.room.as_ref().map(|room| room.state()); let status_widget = self.status_widget(room_state).await; - let chat = if let Some(euph::State::Connected(_, conn::State::Joined(joined))) = room_state - { - Self::widget_with_nick_list( + let chat = match room_state.and_then(|s| s.joined()) { + Some(joined) => Self::widget_with_nick_list( &mut self.chat, status_widget, &mut self.nick_list, joined, self.focus, - ) - } else { - Self::widget_without_nick_list(&mut self.chat, status_widget) + ), + None => Self::widget_without_nick_list(&mut self.chat, status_widget), }; let mut layers = vec![chat];