Add 'euph.rooms.<name>.password' config option

This commit is contained in:
Joscha 2022-08-25 22:49:34 +02:00
parent e40948567a
commit 6e6fddc0b1
7 changed files with 65 additions and 12 deletions

View file

@ -11,6 +11,7 @@ use tokio::sync::{mpsc, oneshot};
use toss::styled::Styled;
use toss::terminal::Terminal;
use crate::config;
use crate::euph::{self, EuphRoomEvent};
use crate::macros::{ok_or_return, some_or_return};
use crate::store::MsgStore;
@ -47,6 +48,8 @@ pub enum RoomStatus {
}
pub struct EuphRoom {
config: config::EuphRoom,
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
vault: EuphVault,
@ -62,8 +65,13 @@ pub struct EuphRoom {
}
impl EuphRoom {
pub fn new(vault: EuphVault, ui_event_tx: mpsc::UnboundedSender<UiEvent>) -> Self {
pub fn new(
config: config::EuphRoom,
vault: EuphVault,
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
) -> Self {
Self {
config,
ui_event_tx,
vault: vault.clone(),
room: None,
@ -94,7 +102,7 @@ impl EuphRoom {
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);
let (room, euph_room_event_rx) = euph::Room::new(store, self.config.password.clone());
self.room = Some(room);

View file

@ -11,6 +11,7 @@ use tokio::sync::mpsc;
use toss::styled::Styled;
use toss::terminal::Terminal;
use crate::config::Config;
use crate::euph::EuphRoomEvent;
use crate::vault::Vault;
@ -33,6 +34,8 @@ enum State {
}
pub struct Rooms {
config: &'static Config,
vault: Vault,
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
@ -43,8 +46,13 @@ pub struct Rooms {
}
impl Rooms {
pub fn new(vault: Vault, ui_event_tx: mpsc::UnboundedSender<UiEvent>) -> Self {
pub fn new(
config: &'static Config,
vault: Vault,
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
) -> Self {
Self {
config,
vault,
ui_event_tx,
state: State::ShowList,
@ -54,9 +62,13 @@ impl Rooms {
}
fn get_or_insert_room(&mut self, name: String) -> &mut EuphRoom {
self.euph_rooms
.entry(name.clone())
.or_insert_with(|| EuphRoom::new(self.vault.euph(name), self.ui_event_tx.clone()))
self.euph_rooms.entry(name.clone()).or_insert_with(|| {
EuphRoom::new(
self.config.euph_room(&name),
self.vault.euph(name),
self.ui_event_tx.clone(),
)
})
}
/// Remove rooms that are not running any more and can't be found in the db.