From f61c03cf0a7f50bbfa6e73ce51683a31adcf0599 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 14 Jan 2023 17:31:02 +0100 Subject: [PATCH] Remove redundant vault --- src/ui/euph/room.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs index 2f1f0f9..c8e1b52 100644 --- a/src/ui/euph/room.rs +++ b/src/ui/euph/room.rs @@ -70,7 +70,6 @@ pub struct EuphRoom { ui_event_tx: mpsc::UnboundedSender, - vault: EuphRoomVault, room: Option, focus: Focus, @@ -92,7 +91,6 @@ impl EuphRoom { Self { config, ui_event_tx, - vault: vault.clone(), room: None, focus: Focus::Chat, state: State::Normal, @@ -103,6 +101,14 @@ impl EuphRoom { } } + fn vault(&self) -> &EuphRoomVault { + self.chat.store() + } + + fn name(&self) -> &str { + self.vault().room() + } + async fn shovel_room_events( name: String, mut euph_room_event_rx: mpsc::UnboundedReceiver, @@ -120,10 +126,8 @@ impl EuphRoom { pub fn connect(&mut self) { if self.room.is_none() { - let store = self.chat.store().clone(); - let name = store.room().to_string(); let (room, euph_room_event_rx) = euph::Room::new( - store, + self.vault().clone(), self.config.username.clone(), self.config.force_username, self.config.password.clone(), @@ -132,7 +136,7 @@ impl EuphRoom { self.room = Some(room); tokio::task::spawn(Self::shovel_room_events( - name, + self.name().to_string(), euph_room_event_rx, self.ui_event_tx.clone(), )); @@ -167,7 +171,7 @@ impl EuphRoom { } pub async fn unseen_msgs_count(&self) -> usize { - self.vault.unseen_msgs_count().await + self.vault().unseen_msgs_count().await } async fn stabilize_pseudo_msg(&mut self) { @@ -290,9 +294,8 @@ impl EuphRoom { } async fn status_widget(&self, status: &RoomStatus) -> BoxedWidget { - let room = self.chat.store().room(); let room_style = ContentStyle::default().bold().blue(); - let mut info = Styled::new(format!("&{room}"), room_style); + let mut info = Styled::new(format!("&{}", self.name()), room_style); info = match status { RoomStatus::NoRoom | RoomStatus::Stopped => info.then_plain(", archive"), @@ -430,7 +433,7 @@ impl EuphRoom { match event { key!('i') => { if let Some(id) = self.chat.cursor().await { - if let Some(msg) = self.vault.full_msg(id).await { + if let Some(msg) = self.vault().full_msg(id).await { self.state = State::InspectMessage(msg); } } @@ -438,14 +441,14 @@ impl EuphRoom { } key!('I') => { if let Some(id) = self.chat.cursor().await { - if let Some(msg) = self.vault.msg(id).await { + if let Some(msg) = self.vault().msg(id).await { self.state = State::Links(LinksState::new(&msg.content)); } } return true; } key!(Ctrl + 'p') => { - let link = format!("https://plugh.de/present/{}/", self.vault.room()); + let link = format!("https://plugh.de/present/{}/", self.name()); if let Err(error) = open::that(&link) { self.popups.push_front(RoomPopup::Error { description: format!("Failed to open link: {link}"),