Browse Source

neon: Fix and cleanup accounts bloc

pull/100/head
jld3103 2 years ago
parent
commit
a819b785db
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 55
      packages/neon/lib/src/blocs/accounts.dart

55
packages/neon/lib/src/blocs/accounts.dart

@ -129,7 +129,8 @@ class AccountsBloc extends $AccountsBloc {
if (_accountsAppsBlocs[account.id] != null) { if (_accountsAppsBlocs[account.id] != null) {
return _accountsAppsBlocs[account.id]!; return _accountsAppsBlocs[account.id]!;
} }
return AppsBloc(
return _accountsAppsBlocs[account.id] = AppsBloc(
_requestManager, _requestManager,
this, this,
account, account,
@ -137,33 +138,15 @@ class AccountsBloc extends $AccountsBloc {
); );
} }
final RequestManager _requestManager;
final Storage _storage;
final SharedPreferences _sharedPreferences;
final GlobalOptions _globalOptions;
final List<AppImplementation> _allAppImplementations;
final PackageInfo _packageInfo;
final _keyAccounts = 'accounts';
final _keyLastUsedAccount = 'last-used-account';
final _accountsOptions = <String, AccountSpecificOptions>{};
final _accountsAppsBlocs = <String, AppsBloc>{};
late final _activeAccountSubject = BehaviorSubject<Account?>.seeded(null);
late final _accountsSubject = BehaviorSubject<List<Account>>.seeded([]);
String? pushNotificationApp;
final Map<Account, UserDetailsBloc> _userDetailsBlocs = {};
final Map<Account, UserStatusBloc> _userStatusBlocs = {};
UserDetailsBloc getUserDetailsBloc(final Account account) { UserDetailsBloc getUserDetailsBloc(final Account account) {
if (_userDetailsBlocs[account] != null) { if (_userDetailsBlocs[account] != null) {
return _userDetailsBlocs[account]!; return _userDetailsBlocs[account]!;
} }
final bloc = UserDetailsBloc(_requestManager, account.client); return _userDetailsBlocs[account.id] = UserDetailsBloc(
_userDetailsBlocs[account] = bloc; _requestManager,
account.client,
return bloc; );
} }
UserStatusBloc getUserStatusBloc(final Account account) { UserStatusBloc getUserStatusBloc(final Account account) {
@ -171,12 +154,30 @@ class AccountsBloc extends $AccountsBloc {
return _userStatusBlocs[account]!; return _userStatusBlocs[account]!;
} }
final bloc = UserStatusBloc(_requestManager, account, _activeAccountSubject); return _userStatusBlocs[account.id] = UserStatusBloc(
_userStatusBlocs[account] = bloc; _requestManager,
account,
return bloc; _activeAccountSubject,
);
} }
final RequestManager _requestManager;
final Storage _storage;
final SharedPreferences _sharedPreferences;
final GlobalOptions _globalOptions;
final List<AppImplementation> _allAppImplementations;
final PackageInfo _packageInfo;
final _keyAccounts = 'accounts';
final _keyLastUsedAccount = 'last-used-account';
final _accountsOptions = <String, AccountSpecificOptions>{};
late final _activeAccountSubject = BehaviorSubject<Account?>.seeded(null);
late final _accountsSubject = BehaviorSubject<List<Account>>.seeded([]);
final _accountsAppsBlocs = <String, AppsBloc>{};
final _userDetailsBlocs = <String, UserDetailsBloc>{};
final _userStatusBlocs = <String, UserStatusBloc>{};
@override @override
void dispose() { void dispose() {
unawaited(_activeAccountSubject.close()); unawaited(_activeAccountSubject.close());

Loading…
Cancel
Save