Browse Source

refactor(neon): Adjust

pull/526/head
jld3103 1 year ago
parent
commit
86374c5efb
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/neon/neon/lib/src/blocs/accounts.dart
  2. 2
      packages/neon/neon/lib/src/blocs/apps.dart
  3. 8
      packages/neon/neon/lib/src/blocs/capabilities.dart
  4. 4
      packages/neon/neon/lib/src/blocs/push_notifications.dart
  5. 8
      packages/neon/neon/lib/src/blocs/user_details.dart
  6. 22
      packages/neon/neon/lib/src/models/account.dart
  7. 2
      packages/neon/neon/lib/src/models/account.g.dart
  8. 2
      packages/neon/neon/lib/src/widgets/user_avatar.dart

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

@ -257,7 +257,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
return _capabilitiesBlocs[account.id] = CapabilitiesBloc( return _capabilitiesBlocs[account.id] = CapabilitiesBloc(
_requestManager, _requestManager,
account.client, account,
); );
} }
@ -276,7 +276,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
return _userDetailsBlocs[account.id] = UserDetailsBloc( return _userDetailsBlocs[account.id] = UserDetailsBloc(
_requestManager, _requestManager,
account.client, account,
); );
} }

2
packages/neon/neon/lib/src/blocs/apps.dart

@ -196,7 +196,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>( await _requestManager.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>(
_account.client.id, _account.id,
'apps-apps', 'apps-apps',
apps, apps,
() async => _account.client.core.getNavigationApps(), () async => _account.client.core.getNavigationApps(),

8
packages/neon/neon/lib/src/blocs/capabilities.dart

@ -21,13 +21,13 @@ abstract class CapabilitiesBlocStates {
class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents, CapabilitiesBlocStates { class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents, CapabilitiesBlocStates {
CapabilitiesBloc( CapabilitiesBloc(
this._requestManager, this._requestManager,
this._client, this._account,
) { ) {
unawaited(refresh()); unawaited(refresh());
} }
final RequestManager _requestManager; final RequestManager _requestManager;
final NextcloudClient _client; final Account _account;
@override @override
void dispose() { void dispose() {
@ -41,10 +41,10 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapNextcloud<CoreServerCapabilities_Ocs_Data, CoreServerCapabilities>( await _requestManager.wrapNextcloud<CoreServerCapabilities_Ocs_Data, CoreServerCapabilities>(
_client.id, _account.id,
'capabilities', 'capabilities',
capabilities, capabilities,
() async => _client.core.getCapabilities(), () async => _account.client.core.getCapabilities(),
(final response) => response.ocs.data, (final response) => response.ocs.data,
); );
} }

4
packages/neon/neon/lib/src/blocs/push_notifications.dart

@ -126,7 +126,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
for (final account in accounts) { for (final account in accounts) {
try { try {
await account.client.notifications.removeDevice(); await account.client.notifications.removeDevice();
await UnifiedPush.unregister(account.client.id); await UnifiedPush.unregister(account.id);
await _storage.remove(_keyLastEndpoint(account)); await _storage.remove(_keyLastEndpoint(account));
} catch (e) { } catch (e) {
debugPrint('Failed to unregister device: $e'); debugPrint('Failed to unregister device: $e');
@ -137,7 +137,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
Future _registerUnifiedPushInstances(final List<Account> accounts) async { Future _registerUnifiedPushInstances(final List<Account> accounts) async {
// Notifications will only work on accounts with app password // Notifications will only work on accounts with app password
for (final account in accounts.where((final a) => a.password != null)) { for (final account in accounts.where((final a) => a.password != null)) {
await UnifiedPush.registerApp(account.client.id); await UnifiedPush.registerApp(account.id);
} }
} }
} }

8
packages/neon/neon/lib/src/blocs/user_details.dart

@ -18,13 +18,13 @@ abstract class UserDetailsBlocStates {
class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents, UserDetailsBlocStates { class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents, UserDetailsBlocStates {
UserDetailsBloc( UserDetailsBloc(
this._requestManager, this._requestManager,
this._client, this._account,
) { ) {
unawaited(refresh()); unawaited(refresh());
} }
final RequestManager _requestManager; final RequestManager _requestManager;
final NextcloudClient _client; final Account _account;
@override @override
void dispose() { void dispose() {
@ -39,10 +39,10 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>( await _requestManager.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>(
_client.id, _account.id,
'user-details', 'user-details',
userDetails, userDetails,
() async => _client.provisioningApi.getCurrentUser(), () async => _account.client.provisioningApi.getCurrentUser(),
(final response) => response.ocs.data, (final response) => response.ocs.data,
); );
} }

22
packages/neon/neon/lib/src/models/account.dart

@ -30,7 +30,7 @@ class Account implements Credentials {
required this.username, required this.username,
this.password, this.password,
this.userAgent, this.userAgent,
}) : _client = NextcloudClient( }) : client = NextcloudClient(
serverURL, serverURL,
loginName: username, loginName: username,
password: password, password: password,
@ -60,20 +60,10 @@ class Account implements Credentials {
@override @override
int get hashCode => serverURL.hashCode + username.hashCode; int get hashCode => serverURL.hashCode + username.hashCode;
String get id => client.id; final NextcloudClient client;
String get humanReadableID => client.humanReadableID;
final NextcloudClient _client;
NextcloudClient get client => _client;
}
Map<String, String> _idCache = {};
extension NextcloudClientHelpers on NextcloudClient {
String get id { String get id {
final key = '$username@$baseURL'; final key = '$username@$serverURL';
if (_idCache[key] != null) { if (_idCache[key] != null) {
return _idCache[key]!; return _idCache[key]!;
} }
@ -81,12 +71,14 @@ extension NextcloudClientHelpers on NextcloudClient {
} }
String get humanReadableID { String get humanReadableID {
final uri = Uri.parse(baseURL); final uri = Uri.parse(serverURL);
// Maybe also show path if it is not '/' ? // Maybe also show path if it is not '/' ?
return '${username!}@${uri.port != 443 ? '${uri.host}:${uri.port}' : uri.host}'; return '$username@${uri.port != 443 ? '${uri.host}:${uri.port}' : uri.host}';
} }
} }
Map<String, String> _idCache = {};
extension AccountFind on Iterable<Account> { extension AccountFind on Iterable<Account> {
Account? tryFind(final String? accountID) => firstWhereOrNull((final account) => account.id == accountID); Account? tryFind(final String? accountID) => firstWhereOrNull((final account) => account.id == accountID);
Account find(final String accountID) => firstWhere((final account) => account.id == accountID); Account find(final String accountID) => firstWhere((final account) => account.id == accountID);

2
packages/neon/neon/lib/src/models/account.g.dart

@ -8,7 +8,6 @@ part of 'account.dart';
Account _$AccountFromJson(Map<String, dynamic> json) => Account( Account _$AccountFromJson(Map<String, dynamic> json) => Account(
serverURL: json['serverURL'] as String, serverURL: json['serverURL'] as String,
loginName: json['loginName'] as String,
username: json['username'] as String, username: json['username'] as String,
password: json['password'] as String?, password: json['password'] as String?,
userAgent: json['userAgent'] as String?, userAgent: json['userAgent'] as String?,
@ -16,7 +15,6 @@ Account _$AccountFromJson(Map<String, dynamic> json) => Account(
Map<String, dynamic> _$AccountToJson(Account instance) => <String, dynamic>{ Map<String, dynamic> _$AccountToJson(Account instance) => <String, dynamic>{
'serverURL': instance.serverURL, 'serverURL': instance.serverURL,
'loginName': instance.loginName,
'username': instance.username, 'username': instance.username,
'password': instance.password, 'password': instance.password,
'userAgent': instance.userAgent, 'userAgent': instance.userAgent,

2
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -25,7 +25,7 @@ class NeonUserAvatar extends StatefulWidget {
this.backgroundColor, this.backgroundColor,
this.foregroundColor, this.foregroundColor,
super.key, super.key,
}) : username = username ?? account.client.username!; }) : username = username ?? account.username;
final Account account; final Account account;
final String username; final String username;

Loading…
Cancel
Save