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,
|
UserId,
|
||||||
};
|
};
|
||||||
use euphoxide::bot::instance::{ConnSnapshot, Event, Instance, InstanceConfig};
|
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 log::{debug, error, info, warn};
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
@ -36,6 +36,13 @@ impl State {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn joined(&self) -> Option<&Joined> {
|
||||||
|
match self {
|
||||||
|
Self::Connected(_, conn::State::Joined(joined)) => Some(joined),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
|
|
||||||
|
|
@ -134,10 +134,7 @@ impl EuphRoom {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn room_state_joined(&self) -> Option<&Joined> {
|
pub fn room_state_joined(&self) -> Option<&Joined> {
|
||||||
match self.room_state() {
|
self.room_state().and_then(|s| s.joined())
|
||||||
Some(euph::State::Connected(_, conn::State::Joined(ref joined))) => Some(joined),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stopped(&self) -> bool {
|
pub fn stopped(&self) -> bool {
|
||||||
|
|
@ -216,17 +213,15 @@ impl EuphRoom {
|
||||||
|
|
||||||
let room_state = self.room.as_ref().map(|room| room.state());
|
let room_state = self.room.as_ref().map(|room| room.state());
|
||||||
let status_widget = self.status_widget(room_state).await;
|
let status_widget = self.status_widget(room_state).await;
|
||||||
let chat = if let Some(euph::State::Connected(_, conn::State::Joined(joined))) = room_state
|
let chat = match room_state.and_then(|s| s.joined()) {
|
||||||
{
|
Some(joined) => Self::widget_with_nick_list(
|
||||||
Self::widget_with_nick_list(
|
|
||||||
&mut self.chat,
|
&mut self.chat,
|
||||||
status_widget,
|
status_widget,
|
||||||
&mut self.nick_list,
|
&mut self.nick_list,
|
||||||
joined,
|
joined,
|
||||||
self.focus,
|
self.focus,
|
||||||
)
|
),
|
||||||
} else {
|
None => Self::widget_without_nick_list(&mut self.chat, status_widget),
|
||||||
Self::widget_without_nick_list(&mut self.chat, status_widget)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut layers = vec![chat];
|
let mut layers = vec![chat];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue