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) {
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<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) {
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<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
void dispose() {
unawaited(_activeAccountSubject.close());

Loading…
Cancel
Save