Browse Source

refactor(neon): refactor account storage

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/674/head
Nikolas Rimikis 1 year ago
parent
commit
d5f7d8d962
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 19
      packages/neon/neon/lib/src/blocs/accounts.dart
  2. 3
      packages/neon/neon/lib/src/utils/push_utils.dart

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

@ -61,10 +61,10 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
const lastUsedStorage = SingleValueStorage('last-used-account');
accounts
..add(loadAccounts(_storage))
..add(loadAccounts())
..listen((final as) async {
_globalOptions.updateAccounts(as);
await _storage.setStringList(_keyAccounts, as.map((final a) => json.encode(a.toJson())).toList());
await saveAccounts(as);
});
activeAccount.listen((final aa) async {
if (aa != null) {
@ -96,7 +96,6 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
}
}
late final AppStorage _storage = const AppStorage('accounts');
final GlobalOptions _globalOptions;
final Iterable<AppImplementation> _allAppImplementations;
@ -278,10 +277,12 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
);
}
/// Get a list of logged in accounts from [storage].
/// Gets a list of logged in accounts from storage.
///
/// It is not checked whether the stored information is still valid.
List<Account> loadAccounts(final AppStorage storage) {
List<Account> loadAccounts() {
const storage = AppStorage('accounts');
if (storage.containsKey(_keyAccounts)) {
return storage
.getStringList(_keyAccounts)!
@ -290,3 +291,11 @@ List<Account> loadAccounts(final AppStorage storage) {
}
return [];
}
/// Saves the given [accounts] to the storage.
Future<void> saveAccounts(final List<Account> accounts) async {
const storage = AppStorage('accounts');
final values = accounts.map((final a) => json.encode(a.toJson())).toList();
await storage.setStringList(_keyAccounts, values);
}

3
packages/neon/neon/lib/src/utils/push_utils.dart

@ -93,12 +93,11 @@ class PushUtils {
} else {
final localizations = await appLocalizationsFromSystem();
var accounts = <Account>[];
final accounts = loadAccounts();
Account? account;
NotificationsNotification? notification;
AndroidBitmap<Object>? largeIconBitmap;
try {
accounts = loadAccounts(const AppStorage('accounts'));
account = accounts.tryFind(instance);
if (account != null) {
notification =

Loading…
Cancel
Save