From a819b785dbd3c7ef83b7bb79d57dd87712d16d76 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 22 Oct 2022 21:12:13 +0200 Subject: [PATCH] neon: Fix and cleanup accounts bloc --- packages/neon/lib/src/blocs/accounts.dart | 55 ++++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/neon/lib/src/blocs/accounts.dart b/packages/neon/lib/src/blocs/accounts.dart index 73aef222..8a13c0e5 100644 --- a/packages/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/lib/src/blocs/accounts.dart @@ -129,7 +129,8 @@ class AccountsBloc extends $AccountsBloc { if (_accountsAppsBlocs[account.id] != null) { return _accountsAppsBlocs[account.id]!; } - return AppsBloc( + + return _accountsAppsBlocs[account.id] = AppsBloc( _requestManager, this, account, @@ -137,33 +138,15 @@ class AccountsBloc extends $AccountsBloc { ); } - final RequestManager _requestManager; - final Storage _storage; - final SharedPreferences _sharedPreferences; - final GlobalOptions _globalOptions; - final List _allAppImplementations; - final PackageInfo _packageInfo; - final _keyAccounts = 'accounts'; - final _keyLastUsedAccount = 'last-used-account'; - - final _accountsOptions = {}; - final _accountsAppsBlocs = {}; - late final _activeAccountSubject = BehaviorSubject.seeded(null); - late final _accountsSubject = BehaviorSubject>.seeded([]); - String? pushNotificationApp; - - final Map _userDetailsBlocs = {}; - final Map _userStatusBlocs = {}; - UserDetailsBloc getUserDetailsBloc(final Account account) { if (_userDetailsBlocs[account] != null) { return _userDetailsBlocs[account]!; } - final bloc = UserDetailsBloc(_requestManager, account.client); - _userDetailsBlocs[account] = bloc; - - return bloc; + return _userDetailsBlocs[account.id] = UserDetailsBloc( + _requestManager, + account.client, + ); } UserStatusBloc getUserStatusBloc(final Account account) { @@ -171,12 +154,30 @@ class AccountsBloc extends $AccountsBloc { return _userStatusBlocs[account]!; } - final bloc = UserStatusBloc(_requestManager, account, _activeAccountSubject); - _userStatusBlocs[account] = bloc; - - return bloc; + return _userStatusBlocs[account.id] = UserStatusBloc( + _requestManager, + account, + _activeAccountSubject, + ); } + final RequestManager _requestManager; + final Storage _storage; + final SharedPreferences _sharedPreferences; + final GlobalOptions _globalOptions; + final List _allAppImplementations; + final PackageInfo _packageInfo; + final _keyAccounts = 'accounts'; + final _keyLastUsedAccount = 'last-used-account'; + + final _accountsOptions = {}; + late final _activeAccountSubject = BehaviorSubject.seeded(null); + late final _accountsSubject = BehaviorSubject>.seeded([]); + + final _accountsAppsBlocs = {}; + final _userDetailsBlocs = {}; + final _userStatusBlocs = {}; + @override void dispose() { unawaited(_activeAccountSubject.close());