AccountManager: add ability to make a selection
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
bdf6156fff
commit
2ca47edf4d
@@ -6,6 +6,7 @@ use crate::{key_storage::KeyStorage, relay_generation::RelayGenerator};
|
|||||||
/// The interface for managing the user's accounts.
|
/// The interface for managing the user's accounts.
|
||||||
/// Represents all user-facing operations related to account management.
|
/// Represents all user-facing operations related to account management.
|
||||||
pub struct AccountManager {
|
pub struct AccountManager {
|
||||||
|
currently_selected_account: Option<usize>,
|
||||||
accounts: Vec<UserAccount>,
|
accounts: Vec<UserAccount>,
|
||||||
key_store: KeyStorage,
|
key_store: KeyStorage,
|
||||||
relay_generator: RelayGenerator,
|
relay_generator: RelayGenerator,
|
||||||
@@ -13,6 +14,7 @@ pub struct AccountManager {
|
|||||||
|
|
||||||
impl AccountManager {
|
impl AccountManager {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
currently_selected_account: Option<usize>,
|
||||||
key_store: KeyStorage,
|
key_store: KeyStorage,
|
||||||
// TODO: right now, there is only one way of generating relays for all accounts. In the future
|
// 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
|
// each account should have the option of generating relays differently
|
||||||
@@ -31,6 +33,7 @@ impl AccountManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AccountManager {
|
AccountManager {
|
||||||
|
currently_selected_account,
|
||||||
accounts,
|
accounts,
|
||||||
key_store,
|
key_store,
|
||||||
relay_generator,
|
relay_generator,
|
||||||
@@ -71,4 +74,14 @@ impl AccountManager {
|
|||||||
pub fn num_accounts(&self) -> usize {
|
pub fn num_accounts(&self) -> usize {
|
||||||
self.accounts.len()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -648,6 +648,8 @@ impl Damus {
|
|||||||
textmode: false,
|
textmode: false,
|
||||||
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
|
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
|
||||||
account_manager: AccountManager::new(
|
account_manager: AccountManager::new(
|
||||||
|
// TODO: should pull this from settings
|
||||||
|
None,
|
||||||
// TODO: use correct KeyStorage mechanism for current OS arch
|
// TODO: use correct KeyStorage mechanism for current OS arch
|
||||||
crate::key_storage::KeyStorage::None,
|
crate::key_storage::KeyStorage::None,
|
||||||
// TODO: setting for relay generator
|
// TODO: setting for relay generator
|
||||||
@@ -680,6 +682,7 @@ impl Damus {
|
|||||||
textmode: false,
|
textmode: false,
|
||||||
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
|
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
|
||||||
account_manager: AccountManager::new(
|
account_manager: AccountManager::new(
|
||||||
|
None,
|
||||||
crate::key_storage::KeyStorage::None,
|
crate::key_storage::KeyStorage::None,
|
||||||
crate::relay_generation::RelayGenerator::Constant,
|
crate::relay_generation::RelayGenerator::Constant,
|
||||||
|| {},
|
|| {},
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ mod preview {
|
|||||||
impl AccountManagementPreview {
|
impl AccountManagementPreview {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let mut account_manager =
|
let mut account_manager =
|
||||||
AccountManager::new(KeyStorage::None, RelayGenerator::Constant, || {});
|
AccountManager::new(None, KeyStorage::None, RelayGenerator::Constant, || {});
|
||||||
let accounts = test_data::get_test_accounts();
|
let accounts = test_data::get_test_accounts();
|
||||||
accounts
|
accounts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -360,7 +360,7 @@ mod preview {
|
|||||||
impl AccountSelectionPreview {
|
impl AccountSelectionPreview {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let mut account_manager =
|
let mut account_manager =
|
||||||
AccountManager::new(KeyStorage::None, RelayGenerator::Constant, || {});
|
AccountManager::new(None, KeyStorage::None, RelayGenerator::Constant, || {});
|
||||||
let accounts = test_data::get_test_accounts();
|
let accounts = test_data::get_test_accounts();
|
||||||
accounts
|
accounts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user