From c600dc36a905164dea5cf48c2d65af7ac7bf211b Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 29 Sep 2022 22:44:13 +0200 Subject: [PATCH] neon: Fix apps for different accounts not loading in account settings --- .../integration_test/screenshot_test.dart | 1 + packages/neon/lib/main.dart | 1 + packages/neon/lib/src/blocs/accounts.dart | 28 ++++++++++------- packages/neon/lib/src/blocs/apps.dart | 2 +- packages/neon/lib/src/models/account.dart | 30 +++++++++++-------- packages/neon/lib/src/pages/home/home.dart | 7 +---- .../settings/account_specific_settings.dart | 2 +- .../neon/lib/src/pages/settings/settings.dart | 4 +-- 8 files changed, 41 insertions(+), 34 deletions(-) diff --git a/packages/neon/integration_test/screenshot_test.dart b/packages/neon/integration_test/screenshot_test.dart index d5050324..97dd1c30 100644 --- a/packages/neon/integration_test/screenshot_test.dart +++ b/packages/neon/integration_test/screenshot_test.dart @@ -119,6 +119,7 @@ Future pumpAppPage( sharedPreferences, globalOptions, packageInfo, + allAppImplementations, ); if (account != null) { accountsBloc.addAccount(account..setupClient(packageInfo)); diff --git a/packages/neon/lib/main.dart b/packages/neon/lib/main.dart index 7220b928..4207a6ef 100644 --- a/packages/neon/lib/main.dart +++ b/packages/neon/lib/main.dart @@ -47,6 +47,7 @@ Future main() async { sharedPreferences, globalOptions, packageInfo, + allAppImplementations, ); final pushNotificationsBloc = PushNotificationsBloc( accountsBloc, diff --git a/packages/neon/lib/src/blocs/accounts.dart b/packages/neon/lib/src/blocs/accounts.dart index 31e78167..73aef222 100644 --- a/packages/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/lib/src/blocs/accounts.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/blocs/user_details.dart'; import 'package:neon/src/blocs/user_status.dart'; import 'package:neon/src/models/account.dart'; @@ -32,6 +33,7 @@ class AccountsBloc extends $AccountsBloc { this._sharedPreferences, this._globalOptions, this._packageInfo, + this._allAppImplementations, ) { _accountsSubject.listen((final accounts) async { _globalOptions.updateAccounts(accounts); @@ -118,30 +120,34 @@ class AccountsBloc extends $AccountsBloc { } } - AccountSpecificOptions? getOptions([Account? account]) { - account ??= _activeAccountSubject.valueOrNull; - if (account != null) { - final accountID = account.id; - if (_accountsOptions[accountID] != null) { - return _accountsOptions[accountID]; - } + AccountSpecificOptions getOptions(final Account account) => _accountsOptions[account.id] ??= AccountSpecificOptions( + Storage('accounts-${account.id}', _sharedPreferences), + getAppsBloc(account), + ); - return _accountsOptions[accountID] = - AccountSpecificOptions(Storage('accounts-${account.id}', _sharedPreferences)); + AppsBloc getAppsBloc(final Account account) { + if (_accountsAppsBlocs[account.id] != null) { + return _accountsAppsBlocs[account.id]!; } - - return null; + return AppsBloc( + _requestManager, + this, + account, + _allAppImplementations, + ); } 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; diff --git a/packages/neon/lib/src/blocs/apps.dart b/packages/neon/lib/src/blocs/apps.dart index a8b9e1e5..55a8a50f 100644 --- a/packages/neon/lib/src/blocs/apps.dart +++ b/packages/neon/lib/src/blocs/apps.dart @@ -66,7 +66,7 @@ class AppsBloc extends $AppsBloc { setActiveApp(_accountsBloc.pushNotificationApp); _accountsBloc.pushNotificationApp = null; } else { - final options = _accountsBloc.getOptions(_account)!..updateApps(appImplementations); + final options = _accountsBloc.getOptions(_account); unawaited( options.initialApp.stream.first.then((var initialApp) { if (initialApp == null) { diff --git a/packages/neon/lib/src/models/account.dart b/packages/neon/lib/src/models/account.dart index 0dae71cf..2b2a1953 100644 --- a/packages/neon/lib/src/models/account.dart +++ b/packages/neon/lib/src/models/account.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:crypto/crypto.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:neon/l10n/localizations.dart'; +import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/neon.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -88,27 +89,30 @@ extension NextcloudClientHelpers on NextcloudClient { } class AccountSpecificOptions { - AccountSpecificOptions(this._storage); + AccountSpecificOptions( + this._storage, + this._appsBloc, + ) { + _appsBloc.appImplementations.listen((final result) { + if (result.data != null) { + _appIDsSubject.add({ + null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic, + for (final app in result.data!) ...{ + app.id: app.name, + }, + }); + } + }); + } final Storage _storage; + final AppsBloc _appsBloc; final _appIDsSubject = BehaviorSubject>(); late final List