refactor: rename AccountsManager to Accounts

plz stop with the managers
This commit is contained in:
William Casarin
2024-11-18 18:03:27 -08:00
parent 6545e1ddee
commit 22e67c95cc
11 changed files with 59 additions and 53 deletions

View File

@@ -2,7 +2,6 @@ use std::cmp::Ordering;
use enostr::{FilledKeypair, FullKeypair, Keypair}; use enostr::{FilledKeypair, FullKeypair, Keypair};
use nostrdb::Ndb; use nostrdb::Ndb;
use serde::{Deserialize, Serialize};
use crate::{ use crate::{
column::Columns, column::Columns,
@@ -12,34 +11,25 @@ use crate::{
storage::{KeyStorageResponse, KeyStorageType}, storage::{KeyStorageResponse, KeyStorageType},
ui::{ ui::{
account_login_view::{AccountLoginResponse, AccountLoginView}, account_login_view::{AccountLoginResponse, AccountLoginView},
account_management::{AccountsView, AccountsViewResponse}, accounts::{AccountsView, AccountsViewResponse},
}, },
unknowns::SingleUnkIdAction, unknowns::SingleUnkIdAction,
user_account::UserAccount,
}; };
use tracing::{error, info}; use tracing::{error, info};
pub use crate::user_account::UserAccount; mod route;
pub use route::{AccountsRoute, AccountsRouteResponse};
/// 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 Accounts {
currently_selected_account: Option<usize>, currently_selected_account: Option<usize>,
accounts: Vec<UserAccount>, accounts: Vec<UserAccount>,
key_store: KeyStorageType, key_store: KeyStorageType,
} }
// TODO(jb55): move to accounts/route.rs
pub enum AccountsRouteResponse {
Accounts(AccountsViewResponse),
AddAccount(AccountLoginResponse),
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum AccountsRoute {
Accounts,
AddAccount,
}
/// Render account management views from a route /// Render account management views from a route
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn render_accounts_route( pub fn render_accounts_route(
@@ -48,7 +38,7 @@ pub fn render_accounts_route(
col: usize, col: usize,
columns: &mut Columns, columns: &mut Columns,
img_cache: &mut ImageCache, img_cache: &mut ImageCache,
accounts: &mut AccountManager, accounts: &mut Accounts,
login_state: &mut AcquireKeyState, login_state: &mut AcquireKeyState,
route: AccountsRoute, route: AccountsRoute,
) -> SingleUnkIdAction { ) -> SingleUnkIdAction {
@@ -84,7 +74,7 @@ pub fn render_accounts_route(
} }
pub fn process_accounts_view_response( pub fn process_accounts_view_response(
manager: &mut AccountManager, manager: &mut Accounts,
response: AccountsViewResponse, response: AccountsViewResponse,
router: &mut Router<Route>, router: &mut Router<Route>,
) { ) {
@@ -101,7 +91,7 @@ pub fn process_accounts_view_response(
} }
} }
impl AccountManager { impl Accounts {
pub fn new(key_store: KeyStorageType) -> Self { pub fn new(key_store: KeyStorageType) -> Self {
let accounts = if let KeyStorageResponse::ReceivedResult(res) = key_store.get_keys() { let accounts = if let KeyStorageResponse::ReceivedResult(res) = key_store.get_keys() {
res.unwrap_or_default() res.unwrap_or_default()
@@ -110,7 +100,7 @@ impl AccountManager {
}; };
let currently_selected_account = get_selected_index(&accounts, &key_store); let currently_selected_account = get_selected_index(&accounts, &key_store);
AccountManager { Accounts {
currently_selected_account, currently_selected_account,
accounts, accounts,
key_store, key_store,
@@ -224,7 +214,7 @@ fn get_selected_index(accounts: &[UserAccount], keystore: &KeyStorageType) -> Op
} }
pub fn process_login_view_response( pub fn process_login_view_response(
manager: &mut AccountManager, manager: &mut Accounts,
response: AccountLoginResponse, response: AccountLoginResponse,
) -> SingleUnkIdAction { ) -> SingleUnkIdAction {
let r = match response { let r = match response {

13
src/accounts/route.rs Normal file
View File

@@ -0,0 +1,13 @@
use super::{AccountLoginResponse, AccountsViewResponse};
use serde::{Deserialize, Serialize};
pub enum AccountsRouteResponse {
Accounts(AccountsViewResponse),
AddAccount(AccountLoginResponse),
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum AccountsRoute {
Accounts,
AddAccount,
}

View File

@@ -1,10 +1,10 @@
use crate::{ use crate::{
account_manager::AccountManager, accounts::{Accounts, AccountsRoute},
app_creation::setup_cc, app_creation::setup_cc,
app_size_handler::AppSizeHandler, app_size_handler::AppSizeHandler,
app_style::user_requested_visuals_change, app_style::user_requested_visuals_change,
args::Args, args::Args,
column::Columns, column::{Column, Columns},
draft::Drafts, draft::Drafts,
filter::FilterState, filter::FilterState,
frame_history::FrameHistory, frame_history::FrameHistory,
@@ -13,6 +13,7 @@ use crate::{
notecache::NoteCache, notecache::NoteCache,
notes_holder::NotesHolderStorage, notes_holder::NotesHolderStorage,
profile::Profile, profile::Profile,
route::Route,
storage::{self, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType}, storage::{self, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType},
subscriptions::{SubKind, Subscriptions}, subscriptions::{SubKind, Subscriptions},
support::Support, support::Support,
@@ -57,7 +58,7 @@ pub struct Damus {
pub threads: NotesHolderStorage<Thread>, pub threads: NotesHolderStorage<Thread>,
pub profiles: NotesHolderStorage<Profile>, pub profiles: NotesHolderStorage<Profile>,
pub img_cache: ImageCache, pub img_cache: ImageCache,
pub accounts: AccountManager, pub accounts: Accounts,
pub subscriptions: Subscriptions, pub subscriptions: Subscriptions,
pub app_rect_handler: AppSizeHandler, pub app_rect_handler: AppSizeHandler,
pub support: Support, pub support: Support,
@@ -415,7 +416,7 @@ impl Damus {
KeyStorageType::None KeyStorageType::None
}; };
let mut accounts = AccountManager::new(keystore); let mut accounts = Accounts::new(keystore);
let num_keys = parsed_args.keys.len(); let num_keys = parsed_args.keys.len();
@@ -489,7 +490,9 @@ impl Damus {
let debug = parsed_args.debug; let debug = parsed_args.debug;
if columns.columns().is_empty() { if columns.columns().is_empty() {
columns.new_column_picker(); columns.add_column(Column::new(vec![Route::Accounts(
AccountsRoute::AddAccount,
)]));
} }
let app_rect_handler = AppSizeHandler::new(&path); let app_rect_handler = AppSizeHandler::new(&path);
@@ -535,11 +538,11 @@ impl Damus {
&mut self.img_cache &mut self.img_cache
} }
pub fn accounts(&self) -> &AccountManager { pub fn accounts(&self) -> &Accounts {
&self.accounts &self.accounts
} }
pub fn accounts_mut(&mut self) -> &mut AccountManager { pub fn accounts_mut(&mut self) -> &mut Accounts {
&mut self.accounts &mut self.accounts
} }
@@ -603,7 +606,7 @@ impl Damus {
&config, &config,
) )
.expect("ndb"), .expect("ndb"),
accounts: AccountManager::new(KeyStorageType::None), accounts: Accounts::new(KeyStorageType::None),
frame_history: FrameHistory::default(), frame_history: FrameHistory::default(),
view_state: ViewState::default(), view_state: ViewState::default(),

View File

@@ -4,7 +4,7 @@ mod error;
//mod note; //mod note;
//mod block; //mod block;
mod abbrev; mod abbrev;
pub mod account_manager; pub mod accounts;
mod actionbar; mod actionbar;
pub mod app_creation; pub mod app_creation;
mod app_size_handler; mod app_size_handler;

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
account_manager::render_accounts_route, accounts::render_accounts_route,
app_style::{get_font_size, NotedeckTextStyle}, app_style::{get_font_size, NotedeckTextStyle},
column::Columns, column::Columns,
fonts::NamedFontFamily, fonts::NamedFontFamily,

View File

@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use std::fmt::{self}; use std::fmt::{self};
use crate::{ use crate::{
account_manager::AccountsRoute, accounts::AccountsRoute,
column::Columns, column::Columns,
timeline::{TimelineId, TimelineRoute}, timeline::{TimelineId, TimelineRoute},
ui::{ ui::{

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
account_manager::AccountManager, accounts::Accounts,
column::Columns, column::Columns,
draft::Drafts, draft::Drafts,
imgcache::ImageCache, imgcache::ImageCache,
@@ -51,7 +51,7 @@ pub fn render_timeline_route(
unknown_ids: &mut UnknownIds, unknown_ids: &mut UnknownIds,
note_cache: &mut NoteCache, note_cache: &mut NoteCache,
threads: &mut NotesHolderStorage<Thread>, threads: &mut NotesHolderStorage<Thread>,
accounts: &mut AccountManager, accounts: &mut Accounts,
route: TimelineRoute, route: TimelineRoute,
col: usize, col: usize,
textmode: bool, textmode: bool,

View File

@@ -1,7 +1,7 @@
use crate::colors::PINK; use crate::colors::PINK;
use crate::imgcache::ImageCache; use crate::imgcache::ImageCache;
use crate::{ use crate::{
account_manager::AccountManager, accounts::Accounts,
route::{Route, Router}, route::{Route, Router},
ui::{Preview, PreviewConfig, View}, ui::{Preview, PreviewConfig, View},
Damus, Damus,
@@ -13,7 +13,7 @@ use super::profile::preview::SimpleProfilePreview;
pub struct AccountsView<'a> { pub struct AccountsView<'a> {
ndb: &'a Ndb, ndb: &'a Ndb,
accounts: &'a AccountManager, accounts: &'a Accounts,
img_cache: &'a mut ImageCache, img_cache: &'a mut ImageCache,
} }
@@ -31,7 +31,7 @@ enum ProfilePreviewOp {
} }
impl<'a> AccountsView<'a> { impl<'a> AccountsView<'a> {
pub fn new(ndb: &'a Ndb, accounts: &'a AccountManager, img_cache: &'a mut ImageCache) -> Self { pub fn new(ndb: &'a Ndb, accounts: &'a Accounts, img_cache: &'a mut ImageCache) -> Self {
AccountsView { AccountsView {
ndb, ndb,
accounts, accounts,
@@ -56,7 +56,7 @@ impl<'a> AccountsView<'a> {
fn show_accounts( fn show_accounts(
ui: &mut Ui, ui: &mut Ui,
account_manager: &AccountManager, accounts: &Accounts,
ndb: &Ndb, ndb: &Ndb,
img_cache: &mut ImageCache, img_cache: &mut ImageCache,
) -> Option<AccountsViewResponse> { ) -> Option<AccountsViewResponse> {
@@ -71,8 +71,8 @@ impl<'a> AccountsView<'a> {
return; return;
}; };
for i in 0..account_manager.num_accounts() { for i in 0..accounts.num_accounts() {
let account_pubkey = account_manager let account_pubkey = accounts
.get_account(i) .get_account(i)
.map(|account| account.pubkey.bytes()); .map(|account| account.pubkey.bytes());
@@ -83,12 +83,12 @@ impl<'a> AccountsView<'a> {
}; };
let profile = ndb.get_profile_by_pubkey(&txn, account_pubkey).ok(); let profile = ndb.get_profile_by_pubkey(&txn, account_pubkey).ok();
let is_selected = let is_selected = if let Some(selected) = accounts.get_selected_account_index()
if let Some(selected) = account_manager.get_selected_account_index() { {
i == selected i == selected
} else { } else {
false false
}; };
let profile_peview_view = { let profile_peview_view = {
let width = ui.available_width(); let width = ui.available_width();
@@ -217,7 +217,7 @@ fn selected_widget() -> impl egui::Widget {
mod preview { mod preview {
use super::*; use super::*;
use crate::{account_manager::process_accounts_view_response, test_data}; use crate::{accounts::process_accounts_view_response, test_data};
pub struct AccountsPreview { pub struct AccountsPreview {
app: Damus, app: Damus,

View File

@@ -1,5 +1,5 @@
pub mod account_login_view; pub mod account_login_view;
pub mod account_management; pub mod accounts;
pub mod add_column; pub mod add_column;
pub mod anim; pub mod anim;
pub mod mention; pub mod mention;
@@ -13,7 +13,7 @@ pub mod thread;
pub mod timeline; pub mod timeline;
pub mod username; pub mod username;
pub use account_management::AccountsView; pub use accounts::AccountsView;
pub use mention::Mention; pub use mention::Mention;
pub use note::{NoteResponse, NoteView, PostReplyView, PostView}; pub use note::{NoteResponse, NoteView, PostReplyView, PostView};
pub use preview::{Preview, PreviewApp, PreviewConfig}; pub use preview::{Preview, PreviewApp, PreviewConfig};

View File

@@ -2,7 +2,7 @@ use egui::{vec2, Color32, InnerResponse, Layout, Margin, Separator, Stroke, Widg
use tracing::info; use tracing::info;
use crate::{ use crate::{
account_manager::AccountsRoute, accounts::AccountsRoute,
colors, colors,
column::{Column, Columns}, column::{Column, Columns},
imgcache::ImageCache, imgcache::ImageCache,

View File

@@ -1,7 +1,7 @@
use notedeck::ui::{ use notedeck::ui::{
account_login_view::AccountLoginView, account_management::AccountsView, account_login_view::AccountLoginView, accounts::AccountsView, add_column::AddColumnView,
add_column::AddColumnView, DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic, ProfilePreview,
ProfilePic, ProfilePreview, RelayView, RelayView,
}; };
use notedeck::{ use notedeck::{
app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc}, app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc},