From 2ca47edf4d90188525a8b496d5efd6228b74952e Mon Sep 17 00:00:00 2001 From: kernelkind Date: Wed, 22 May 2024 16:40:52 -0400 Subject: [PATCH] AccountManager: add ability to make a selection Signed-off-by: kernelkind --- src/account_manager.rs | 13 +++++++++++++ src/app.rs | 3 +++ src/ui/account_management.rs | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/account_manager.rs b/src/account_manager.rs index 0c03d99..21fafee 100644 --- a/src/account_manager.rs +++ b/src/account_manager.rs @@ -6,6 +6,7 @@ use crate::{key_storage::KeyStorage, relay_generation::RelayGenerator}; /// The interface for managing the user's accounts. /// Represents all user-facing operations related to account management. pub struct AccountManager { + currently_selected_account: Option, accounts: Vec, key_store: KeyStorage, relay_generator: RelayGenerator, @@ -13,6 +14,7 @@ pub struct AccountManager { impl AccountManager { pub fn new( + currently_selected_account: Option, key_store: KeyStorage, // TODO: right now, there is only one way of generating relays for all accounts. In the future // each account should have the option of generating relays differently @@ -31,6 +33,7 @@ impl AccountManager { }; AccountManager { + currently_selected_account, accounts, key_store, relay_generator, @@ -71,4 +74,14 @@ impl AccountManager { pub fn num_accounts(&self) -> usize { self.accounts.len() } + + pub fn get_currently_selected_account(&self) -> Option { + self.currently_selected_account + } + + pub fn select_account(&mut self, index: usize) { + if self.accounts.get(index).is_some() { + self.currently_selected_account = Some(index) + } + } } diff --git a/src/app.rs b/src/app.rs index db73eb9..52993ee 100644 --- a/src/app.rs +++ b/src/app.rs @@ -648,6 +648,8 @@ impl Damus { textmode: false, ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"), account_manager: AccountManager::new( + // TODO: should pull this from settings + None, // TODO: use correct KeyStorage mechanism for current OS arch crate::key_storage::KeyStorage::None, // TODO: setting for relay generator @@ -680,6 +682,7 @@ impl Damus { textmode: false, ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"), account_manager: AccountManager::new( + None, crate::key_storage::KeyStorage::None, crate::relay_generation::RelayGenerator::Constant, || {}, diff --git a/src/ui/account_management.rs b/src/ui/account_management.rs index 5ae98ee..4d86cac 100644 --- a/src/ui/account_management.rs +++ b/src/ui/account_management.rs @@ -317,7 +317,7 @@ mod preview { impl AccountManagementPreview { fn new() -> Self { let mut account_manager = - AccountManager::new(KeyStorage::None, RelayGenerator::Constant, || {}); + AccountManager::new(None, KeyStorage::None, RelayGenerator::Constant, || {}); let accounts = test_data::get_test_accounts(); accounts .into_iter() @@ -360,7 +360,7 @@ mod preview { impl AccountSelectionPreview { fn new() -> Self { let mut account_manager = - AccountManager::new(KeyStorage::None, RelayGenerator::Constant, || {}); + AccountManager::new(None, KeyStorage::None, RelayGenerator::Constant, || {}); let accounts = test_data::get_test_accounts(); accounts .into_iter()