AccountManager: add ability to make a selection

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-05-22 16:40:52 -04:00
committed by William Casarin
parent bdf6156fff
commit 2ca47edf4d
3 changed files with 18 additions and 2 deletions

View File

@@ -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<usize>,
accounts: Vec<UserAccount>,
key_store: KeyStorage,
relay_generator: RelayGenerator,
@@ -13,6 +14,7 @@ pub struct AccountManager {
impl AccountManager {
pub fn new(
currently_selected_account: Option<usize>,
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<usize> {
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)
}
}
}

View File

@@ -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,
|| {},

View File

@@ -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()