From 4337be108b7ea5bbb1500a2f0c5b458c65215833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Gro=C3=9Fe?= Date: Sat, 28 Jan 2023 14:09:40 -0800 Subject: [PATCH] Add "default_room" to profile settings (#25) --- src/config.rs | 4 ++++ src/main.rs | 9 ++++++++- src/tests.rs | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index c69d4ab..cfb1ba2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -183,6 +183,7 @@ pub struct TunableValues { pub typing_notice_send: bool, pub typing_notice_display: bool, pub users: UserOverrides, + pub default_room: Option, } #[derive(Clone, Default, Deserialize)] @@ -192,6 +193,7 @@ pub struct Tunables { pub typing_notice_send: Option, pub typing_notice_display: Option, pub users: Option, + pub default_room: Option, } impl Tunables { @@ -202,6 +204,7 @@ impl Tunables { typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), users: merge_users(self.users, other.users), + default_room: self.default_room.or(other.default_room), } } @@ -212,6 +215,7 @@ impl Tunables { typing_notice_send: self.typing_notice_send.unwrap_or(true), typing_notice_display: self.typing_notice_display.unwrap_or(true), users: self.users.unwrap_or_default(), + default_room: self.default_room, } } } diff --git a/src/main.rs b/src/main.rs index f823194..887c52c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,7 +138,14 @@ impl Application { let cmds = crate::commands::setup_commands(); let mut locked = store.lock().await; - let win = IambWindow::open(IambId::Welcome, locked.deref_mut()).unwrap(); + + let win = settings + .tunables + .default_room + .and_then(|room| IambWindow::find(room, locked.deref_mut()).ok()) + .or_else(|| IambWindow::open(IambId::Welcome, locked.deref_mut()).ok()) + .unwrap(); + let cmd = CommandBarState::new(IambBufferId::Command, locked.deref_mut()); let screen = ScreenState::new(win, cmd); diff --git a/src/tests.rs b/src/tests.rs index 0776ff2..73243dd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -168,6 +168,7 @@ pub fn mock_dirs() -> DirectoryValues { pub fn mock_tunables() -> TunableValues { TunableValues { + default_room: None, read_receipt_send: true, read_receipt_display: true, typing_notice_send: true,