Simplify getting Joined room state

This commit is contained in:
Joscha 2024-01-01 19:45:32 +01:00
parent 5995d06cad
commit fdbd6e0c55

View file

@ -132,7 +132,12 @@ impl EuphRoom {
} }
} }
// TODO fn room_state_joined(&self) -> Option<&Joined> {} pub fn room_state_joined(&self) -> Option<&Joined> {
match self.room_state() {
Some(euph::State::Connected(_, conn::State::Joined(ref joined))) => Some(joined),
_ => None,
}
}
pub fn stopped(&self) -> bool { pub fn stopped(&self) -> bool {
self.room.as_ref().map(|r| r.stopped()).unwrap_or(true) self.room.as_ref().map(|r| r.stopped()).unwrap_or(true)
@ -167,9 +172,8 @@ impl EuphRoom {
} }
fn stabilize_focus(&mut self) { fn stabilize_focus(&mut self) {
match self.room_state() { if self.room_state_joined().is_none() {
Some(euph::State::Connected(_, conn::State::Joined(_))) => {} self.focus = Focus::Chat; // There is no nick list to focus on
_ => self.focus = Focus::Chat, // There is no nick list to focus on
} }
} }
@ -325,10 +329,7 @@ impl EuphRoom {
} }
async fn handle_chat_input_event(&mut self, event: &mut InputEvent<'_>, keys: &Keys) -> bool { async fn handle_chat_input_event(&mut self, event: &mut InputEvent<'_>, keys: &Keys) -> bool {
let can_compose = matches!( let can_compose = self.room_state_joined().is_some();
self.room_state(),
Some(euph::State::Connected(_, conn::State::Joined(_)))
);
let reaction = self.chat.handle_input_event(event, keys, can_compose).await; let reaction = self.chat.handle_input_event(event, keys, can_compose).await;
let reaction = logging_unwrap!(reaction); let reaction = logging_unwrap!(reaction);
@ -448,8 +449,7 @@ impl EuphRoom {
} }
if event.matches(&keys.tree.action.inspect) { if event.matches(&keys.tree.action.inspect) {
if let Some(euph::State::Connected(_, conn::State::Joined(joined))) = self.room_state() if let Some(joined) = self.room_state_joined() {
{
if let Some(id) = self.nick_list.selected() { if let Some(id) = self.nick_list.selected() {
if *id == joined.session.session_id { if *id == joined.session.session_id {
self.state = self.state =
@ -472,11 +472,9 @@ impl EuphRoom {
return true; return true;
} }
if let Some(euph::State::Connected(_, conn::State::Joined(_))) = self.room_state() { if self.room_state_joined().is_some() && event.matches(&keys.general.focus) {
if event.matches(&keys.general.focus) { self.focus = Focus::NickList;
self.focus = Focus::NickList; return true;
return true;
}
} }
} }
Focus::NickList => { Focus::NickList => {