Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/app/integration_test/screenshot_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Future main() async {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final account = Account(
serverURL: 'http://10.0.2.2',
loginName: 'user1',
username: 'user1',
password: 'user1',
);
Expand Down Expand Up @@ -346,7 +345,6 @@ Future main() async {
testWidgets('notifications', (final tester) async {
await Account(
serverURL: 'http://10.0.2.2',
loginName: 'admin',
username: 'admin',
password: 'admin',
).client.notifications.sendAdminNotification(
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/blocs/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState

return _capabilitiesBlocs[account.id] = CapabilitiesBloc(
_requestManager,
account.client,
account,
);
}

Expand All @@ -276,7 +276,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState

return _userDetailsBlocs[account.id] = UserDetailsBloc(
_requestManager,
account.client,
account,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>(
_account.client.id,
_account.id,
'apps-apps',
apps,
() async => _account.client.core.getNavigationApps(),
Expand Down
8 changes: 4 additions & 4 deletions packages/neon/neon/lib/src/blocs/capabilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ abstract class CapabilitiesBlocStates {
class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents, CapabilitiesBlocStates {
CapabilitiesBloc(
this._requestManager,
this._client,
this._account,
) {
unawaited(refresh());
}

final RequestManager _requestManager;
final NextcloudClient _client;
final Account _account;

@override
void dispose() {
Expand All @@ -41,10 +41,10 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
@override
Future refresh() async {
await _requestManager.wrapNextcloud<CoreServerCapabilities_Ocs_Data, CoreServerCapabilities>(
_client.id,
_account.id,
'capabilities',
capabilities,
() async => _client.core.getCapabilities(),
() async => _account.client.core.getCapabilities(),
(final response) => response.ocs.data,
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/neon/neon/lib/src/blocs/login_check_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class LoginCheckAccountBloc extends InteractiveBloc

final account = Account(
serverURL: serverURL,
loginName: loginName,
username: response.ocs.data.id,
password: password,
userAgent: neonUserAgent,
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/blocs/push_notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
for (final account in accounts) {
try {
await account.client.notifications.removeDevice();
await UnifiedPush.unregister(account.client.id);
await UnifiedPush.unregister(account.id);
await _storage.remove(_keyLastEndpoint(account));
} catch (e) {
debugPrint('Failed to unregister device: $e');
Expand All @@ -137,7 +137,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
Future _registerUnifiedPushInstances(final List<Account> accounts) async {
// Notifications will only work on accounts with app password
for (final account in accounts.where((final a) => a.password != null)) {
await UnifiedPush.registerApp(account.client.id);
await UnifiedPush.registerApp(account.id);
}
}
}
8 changes: 4 additions & 4 deletions packages/neon/neon/lib/src/blocs/user_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ abstract class UserDetailsBlocStates {
class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents, UserDetailsBlocStates {
UserDetailsBloc(
this._requestManager,
this._client,
this._account,
) {
unawaited(refresh());
}

final RequestManager _requestManager;
final NextcloudClient _client;
final Account _account;

@override
void dispose() {
Expand All @@ -39,10 +39,10 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,
@override
Future refresh() async {
await _requestManager.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>(
_client.id,
_account.id,
'user-details',
userDetails,
() async => _client.provisioningApi.getCurrentUser(),
() async => _account.client.provisioningApi.getCurrentUser(),
(final response) => response.ocs.data,
);
}
Expand Down
26 changes: 8 additions & 18 deletions packages/neon/neon/lib/src/models/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ abstract interface class Credentials {
class Account implements Credentials {
Account({
required this.serverURL,
required this.loginName,
required this.username,
this.password,
this.userAgent,
}) : _client = NextcloudClient(
}) : client = NextcloudClient(
serverURL,
loginName: loginName,
username: username,
loginName: username,
password: password,
userAgentOverride: userAgent,
cookieJar: CookieJar(),
Expand All @@ -45,7 +43,6 @@ class Account implements Credentials {

@override
final String serverURL;
final String loginName;
@override
final String username;
@override
Expand All @@ -56,39 +53,32 @@ class Account implements Credentials {
bool operator ==(final Object other) =>
other is Account &&
other.serverURL == serverURL &&
other.loginName == loginName &&
other.username == username &&
other.password == password &&
other.userAgent == userAgent;

@override
int get hashCode => serverURL.hashCode + username.hashCode;

String get id => client.id;
final NextcloudClient client;

final NextcloudClient _client;

NextcloudClient get client => _client;
}

Map<String, String> _idCache = {};

extension NextcloudClientHelpers on NextcloudClient {
String get id {
final key = '$username@$baseURL';
final key = '$username@$serverURL';
if (_idCache[key] != null) {
return _idCache[key]!;
}
return _idCache[key] = sha1.convert(utf8.encode(key)).toString();
}

String get humanReadableID {
final uri = Uri.parse(baseURL);
final uri = Uri.parse(serverURL);
// 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> {
Account? tryFind(final String? accountID) => firstWhereOrNull((final account) => account.id == accountID);
Account find(final String accountID) => firstWhere((final account) => account.id == accountID);
Expand Down
2 changes: 0 additions & 2 deletions packages/neon/neon/lib/src/models/account.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/neon/neon/lib/src/models/app_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:neon/src/settings/models/nextcloud_app_options.dart';
import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/request_manager.dart';
import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -40,9 +39,9 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>

final Map<String, T> blocs = {};

T getBloc(final Account account) => blocs[account.id] ??= buildBloc(account.client);
T getBloc(final Account account) => blocs[account.id] ??= buildBloc(account);

T buildBloc(final NextcloudClient client);
T buildBloc(final Account account);

Provider<T> get blocProvider => Provider<T>(
create: (final context) {
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/pages/account_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AccountSettingsPage extends StatelessWidget {
Widget build(final BuildContext context) {
final options = bloc.getOptionsFor(account);
final userDetailsBloc = bloc.getUserDetailsBlocFor(account);
final name = account.client.humanReadableID;
final name = account.humanReadableID;

final appBar = AppBar(
title: Text(name),
Expand All @@ -39,7 +39,7 @@ class AccountSettingsPage extends StatelessWidget {
onPressed: () async {
if (await showConfirmationDialog(
context,
AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID),
AppLocalizations.of(context).accountOptionsRemoveConfirm(account.humanReadableID),
)) {
final isActive = bloc.activeAccount.valueOrNull == account;

Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/utils/global_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GlobalOptions {
}
initialAccount.values = {
for (final account in accounts) ...{
account.id: (final context) => account.client.humanReadableID,
account.id: (final context) => account.humanReadableID,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/utils/push_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class PushUtils {
android: AndroidNotificationDetails(
appID,
appName ?? appID,
subText: accounts.length > 1 && account != null ? account.client.humanReadableID : null,
subText: accounts.length > 1 && account != null ? account.humanReadableID : null,
groupKey: 'app_$appID',
icon: '@mipmap/ic_launcher',
largeIcon: largeIconBitmap,
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/widgets/account_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NeonAccountTile extends StatelessWidget {
),
),
subtitle: Text(
account.client.humanReadableID,
account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: textColor,
),
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/widgets/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NeonAppBar extends StatelessWidget implements PreferredSizeWidget {
),
if (accounts.length > 1) ...[
Text(
account.client.humanReadableID,
account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall,
),
],
Expand Down Expand Up @@ -140,7 +140,7 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
Text(app.name(context)),
if (_accounts.length > 1) ...[
Text(
_account.client.humanReadableID,
_account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall,
),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/widgets/user_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NeonUserAvatar extends StatefulWidget {
this.backgroundColor,
this.foregroundColor,
super.key,
}) : username = username ?? account.client.username!;
}) : username = username ?? account.username;

final Account account;
final String username;
Expand Down
10 changes: 5 additions & 5 deletions packages/neon/neon_files/lib/blocs/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
FilesBrowserBloc(
this._requestManager,
this.options,
this.client,
this.account,
) {
unawaited(refresh());
}

final RequestManager _requestManager;
final FilesAppSpecificOptions options;
final NextcloudClient client;
final Account account;

@override
void dispose() {
Expand All @@ -41,10 +41,10 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
@override
Future refresh() async {
await _requestManager.wrapWebDav<List<WebDavFile>>(
client.id,
account.id,
'files-${path.value.join('/')}',
files,
() async => client.webdav.propfind(
() async => account.client.webdav.propfind(
path.value.join('/'),
prop: WebDavPropWithoutValues.fromBools(
davgetcontenttype: true,
Expand All @@ -69,6 +69,6 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents

@override
void createFolder(final List<String> path) {
wrapAction(() async => client.webdav.mkcol(path.join('/')));
wrapAction(() async => account.client.webdav.mkcol(path.join('/')));
}
}
Loading