Simplify retrieving Joined from room::State
This commit is contained in:
parent
5bbf389dbe
commit
cc1a2866eb
2 changed files with 13 additions and 11 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue