Browse Source

Merge pull request #526 from provokateurin/fix/client-username

Fix/client username
pull/529/head
Kate 1 year ago committed by GitHub
parent
commit
7771495b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/app/integration_test/screenshot_test.dart
  2. 4
      packages/neon/neon/lib/src/blocs/accounts.dart
  3. 2
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 8
      packages/neon/neon/lib/src/blocs/capabilities.dart
  5. 1
      packages/neon/neon/lib/src/blocs/login_check_account.dart
  6. 4
      packages/neon/neon/lib/src/blocs/push_notifications.dart
  7. 8
      packages/neon/neon/lib/src/blocs/user_details.dart
  8. 26
      packages/neon/neon/lib/src/models/account.dart
  9. 2
      packages/neon/neon/lib/src/models/account.g.dart
  10. 5
      packages/neon/neon/lib/src/models/app_implementation.dart
  11. 4
      packages/neon/neon/lib/src/pages/account_settings.dart
  12. 2
      packages/neon/neon/lib/src/utils/global_options.dart
  13. 2
      packages/neon/neon/lib/src/utils/push_utils.dart
  14. 2
      packages/neon/neon/lib/src/widgets/account_tile.dart
  15. 4
      packages/neon/neon/lib/src/widgets/app_bar.dart
  16. 2
      packages/neon/neon/lib/src/widgets/user_avatar.dart
  17. 10
      packages/neon/neon_files/lib/blocs/browser.dart
  18. 24
      packages/neon/neon_files/lib/blocs/files.dart
  19. 4
      packages/neon/neon_files/lib/neon_files.dart
  20. 8
      packages/neon/neon_news/lib/blocs/article.dart
  21. 18
      packages/neon/neon_news/lib/blocs/articles.dart
  22. 32
      packages/neon/neon_news/lib/blocs/news.dart
  23. 4
      packages/neon/neon_news/lib/neon_news.dart
  24. 2
      packages/neon/neon_news/lib/pages/feed.dart
  25. 2
      packages/neon/neon_news/lib/widgets/folder_view.dart
  26. 6
      packages/neon/neon_notes/lib/blocs/note.dart
  27. 14
      packages/neon/neon_notes/lib/blocs/notes.dart
  28. 4
      packages/neon/neon_notes/lib/neon_notes.dart
  29. 12
      packages/neon/neon_notifications/lib/blocs/notifications.dart
  30. 4
      packages/neon/neon_notifications/lib/neon_notifications.dart
  31. 7
      packages/nextcloud/lib/src/client.dart
  32. 2
      packages/nextcloud/test/helper.dart

2
packages/app/integration_test/screenshot_test.dart

@ -129,7 +129,6 @@ Future main() async {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final account = Account( final account = Account(
serverURL: 'http://10.0.2.2', serverURL: 'http://10.0.2.2',
loginName: 'user1',
username: 'user1', username: 'user1',
password: 'user1', password: 'user1',
); );
@ -346,7 +345,6 @@ Future main() async {
testWidgets('notifications', (final tester) async { testWidgets('notifications', (final tester) async {
await Account( await Account(
serverURL: 'http://10.0.2.2', serverURL: 'http://10.0.2.2',
loginName: 'admin',
username: 'admin', username: 'admin',
password: 'admin', password: 'admin',
).client.notifications.sendAdminNotification( ).client.notifications.sendAdminNotification(

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,
); );
} }

1
packages/neon/neon/lib/src/blocs/login_check_account.dart

@ -53,7 +53,6 @@ class LoginCheckAccountBloc extends InteractiveBloc
final account = Account( final account = Account(
serverURL: serverURL, serverURL: serverURL,
loginName: loginName,
username: response.ocs.data.id, username: response.ocs.data.id,
password: password, password: password,
userAgent: neonUserAgent, userAgent: neonUserAgent,

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,
); );
} }

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

@ -27,14 +27,12 @@ abstract interface class Credentials {
class Account implements Credentials { class Account implements Credentials {
Account({ Account({
required this.serverURL, required this.serverURL,
required this.loginName,
required this.username, required this.username,
this.password, this.password,
this.userAgent, this.userAgent,
}) : _client = NextcloudClient( }) : client = NextcloudClient(
serverURL, serverURL,
loginName: loginName, loginName: username,
username: username,
password: password, password: password,
userAgentOverride: userAgent, userAgentOverride: userAgent,
cookieJar: CookieJar(), cookieJar: CookieJar(),
@ -45,7 +43,6 @@ class Account implements Credentials {
@override @override
final String serverURL; final String serverURL;
final String loginName;
@override @override
final String username; final String username;
@override @override
@ -56,7 +53,6 @@ class Account implements Credentials {
bool operator ==(final Object other) => bool operator ==(final Object other) =>
other is Account && other is Account &&
other.serverURL == serverURL && other.serverURL == serverURL &&
other.loginName == loginName &&
other.username == username && other.username == username &&
other.password == password && other.password == password &&
other.userAgent == userAgent; other.userAgent == userAgent;
@ -64,18 +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;
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]!;
} }
@ -83,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,

5
packages/neon/neon/lib/src/models/app_implementation.dart

@ -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/settings/models/storage.dart';
import 'package:neon/src/utils/request_manager.dart'; import 'package:neon/src/utils/request_manager.dart';
import 'package:neon/src/widgets/drawer_destination.dart'; import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -40,9 +39,9 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
final Map<String, T> blocs = {}; 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>( Provider<T> get blocProvider => Provider<T>(
create: (final context) { create: (final context) {

4
packages/neon/neon/lib/src/pages/account_settings.dart

@ -30,7 +30,7 @@ class AccountSettingsPage extends StatelessWidget {
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final options = bloc.getOptionsFor(account); final options = bloc.getOptionsFor(account);
final userDetailsBloc = bloc.getUserDetailsBlocFor(account); final userDetailsBloc = bloc.getUserDetailsBlocFor(account);
final name = account.client.humanReadableID; final name = account.humanReadableID;
final appBar = AppBar( final appBar = AppBar(
title: Text(name), title: Text(name),
@ -39,7 +39,7 @@ class AccountSettingsPage extends StatelessWidget {
onPressed: () async { onPressed: () async {
if (await showConfirmationDialog( if (await showConfirmationDialog(
context, context,
AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), AppLocalizations.of(context).accountOptionsRemoveConfirm(account.humanReadableID),
)) { )) {
final isActive = bloc.activeAccount.valueOrNull == account; final isActive = bloc.activeAccount.valueOrNull == account;

2
packages/neon/neon/lib/src/utils/global_options.dart

@ -107,7 +107,7 @@ class GlobalOptions {
} }
initialAccount.values = { initialAccount.values = {
for (final account in accounts) ...{ for (final account in accounts) ...{
account.id: (final context) => account.client.humanReadableID, account.id: (final context) => account.humanReadableID,
}, },
}; };
} }

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

@ -160,7 +160,7 @@ class PushUtils {
android: AndroidNotificationDetails( android: AndroidNotificationDetails(
appID, appID,
appName ?? 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', groupKey: 'app_$appID',
icon: '@mipmap/ic_launcher', icon: '@mipmap/ic_launcher',
largeIcon: largeIconBitmap, largeIcon: largeIconBitmap,

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

@ -90,7 +90,7 @@ class NeonAccountTile extends StatelessWidget {
), ),
), ),
subtitle: Text( subtitle: Text(
account.client.humanReadableID, account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall!.copyWith( style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: textColor, color: textColor,
), ),

4
packages/neon/neon/lib/src/widgets/app_bar.dart

@ -71,7 +71,7 @@ class NeonAppBar extends StatelessWidget implements PreferredSizeWidget {
), ),
if (accounts.length > 1) ...[ if (accounts.length > 1) ...[
Text( Text(
account.client.humanReadableID, account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall, style: Theme.of(context).textTheme.bodySmall,
), ),
], ],
@ -140,7 +140,7 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
Text(app.name(context)), Text(app.name(context)),
if (_accounts.length > 1) ...[ if (_accounts.length > 1) ...[
Text( Text(
_account.client.humanReadableID, _account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall, style: Theme.of(context).textTheme.bodySmall,
), ),
], ],

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;

10
packages/neon/neon_files/lib/blocs/browser.dart

@ -16,14 +16,14 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
FilesBrowserBloc( FilesBrowserBloc(
this._requestManager, this._requestManager,
this.options, this.options,
this.client, this.account,
) { ) {
unawaited(refresh()); unawaited(refresh());
} }
final RequestManager _requestManager; final RequestManager _requestManager;
final FilesAppSpecificOptions options; final FilesAppSpecificOptions options;
final NextcloudClient client; final Account account;
@override @override
void dispose() { void dispose() {
@ -41,10 +41,10 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapWebDav<List<WebDavFile>>( await _requestManager.wrapWebDav<List<WebDavFile>>(
client.id, account.id,
'files-${path.value.join('/')}', 'files-${path.value.join('/')}',
files, files,
() async => client.webdav.propfind( () async => account.client.webdav.propfind(
path.value.join('/'), path.value.join('/'),
prop: WebDavPropWithoutValues.fromBools( prop: WebDavPropWithoutValues.fromBools(
davgetcontenttype: true, davgetcontenttype: true,
@ -69,6 +69,6 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
@override @override
void createFolder(final List<String> path) { void createFolder(final List<String> path) {
wrapAction(() async => client.webdav.mkcol(path.join('/'))); wrapAction(() async => account.client.webdav.mkcol(path.join('/')));
} }
} }

24
packages/neon/neon_files/lib/blocs/files.dart

@ -29,7 +29,7 @@ abstract class FilesBlocStates {
class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocStates { class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocStates {
FilesBloc( FilesBloc(
this.options, this.options,
this.client, this.account,
this._requestManager, this._requestManager,
this._platform, this._platform,
) { ) {
@ -38,7 +38,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
} }
final FilesAppSpecificOptions options; final FilesAppSpecificOptions options;
final NextcloudClient client; final Account account;
final RequestManager _requestManager; final RequestManager _requestManager;
final NeonPlatform _platform; final NeonPlatform _platform;
late final browser = getNewFilesBrowserBloc(); late final browser = getNewFilesBrowserBloc();
@ -66,7 +66,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override @override
void addFavorite(final List<String> path) { void addFavorite(final List<String> path) {
wrapAction( wrapAction(
() async => client.webdav.proppatch( () async => account.client.webdav.proppatch(
path.join('/'), path.join('/'),
set: WebDavProp(ocfavorite: 1), set: WebDavProp(ocfavorite: 1),
), ),
@ -75,17 +75,17 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override @override
void copy(final List<String> path, final List<String> destination) { void copy(final List<String> path, final List<String> destination) {
wrapAction(() async => client.webdav.copy(path.join('/'), destination.join('/'))); wrapAction(() async => account.client.webdav.copy(path.join('/'), destination.join('/')));
} }
@override @override
void delete(final List<String> path) { void delete(final List<String> path) {
wrapAction(() async => client.webdav.delete(path.join('/'))); wrapAction(() async => account.client.webdav.delete(path.join('/')));
} }
@override @override
void move(final List<String> path, final List<String> destination) { void move(final List<String> path, final List<String> destination) {
wrapAction(() async => client.webdav.move(path.join('/'), destination.join('/'))); wrapAction(() async => account.client.webdav.move(path.join('/'), destination.join('/')));
} }
@override @override
@ -124,7 +124,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override @override
void removeFavorite(final List<String> path) { void removeFavorite(final List<String> path) {
wrapAction( wrapAction(
() async => client.webdav.proppatch( () async => account.client.webdav.proppatch(
path.join('/'), path.join('/'),
set: WebDavProp(ocfavorite: 0), set: WebDavProp(ocfavorite: 0),
), ),
@ -134,7 +134,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override @override
void rename(final List<String> path, final String name) { void rename(final List<String> path, final String name) {
wrapAction( wrapAction(
() async => client.webdav.move( () async => account.client.webdav.move(
path.join('/'), path.join('/'),
(path.sublist(0, path.length - 1)..add(name)).join('/'), (path.sublist(0, path.length - 1)..add(name)).join('/'),
), ),
@ -148,7 +148,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
final file = File( final file = File(
p.join( p.join(
await _platform.getUserAccessibleAppDataPath(), await _platform.getUserAccessibleAppDataPath(),
client.humanReadableID, account.humanReadableID,
'files', 'files',
path.join(Platform.pathSeparator), path.join(Platform.pathSeparator),
), ),
@ -175,7 +175,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
lastModified: stat.modified, lastModified: stat.modified,
); );
uploadTasks.add(uploadTasks.value..add(task)); uploadTasks.add(uploadTasks.value..add(task));
await _uploadQueue.add(() => task.execute(client, file.openRead())); await _uploadQueue.add(() => task.execute(account.client, file.openRead()));
uploadTasks.add(uploadTasks.value..removeWhere((final t) => t == task)); uploadTasks.add(uploadTasks.value..removeWhere((final t) => t == task));
}, },
disableTimeout: true, disableTimeout: true,
@ -192,14 +192,14 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
path: path, path: path,
); );
downloadTasks.add(downloadTasks.value..add(task)); downloadTasks.add(downloadTasks.value..add(task));
await _downloadQueue.add(() => task.execute(client, sink)); await _downloadQueue.add(() => task.execute(account.client, sink));
downloadTasks.add(downloadTasks.value..removeWhere((final t) => t == task)); downloadTasks.add(downloadTasks.value..removeWhere((final t) => t == task));
} finally { } finally {
await sink.close(); await sink.close();
} }
} }
FilesBrowserBloc getNewFilesBrowserBloc() => FilesBrowserBloc(_requestManager, options, client); FilesBrowserBloc getNewFilesBrowserBloc() => FilesBrowserBloc(_requestManager, options, account);
void _downloadParalelismListener() { void _downloadParalelismListener() {
_downloadQueue.parallel = options.downloadQueueParallelism.value; _downloadQueue.parallel = options.downloadQueueParallelism.value;

4
packages/neon/neon_files/lib/neon_files.dart

@ -61,9 +61,9 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
FilesAppSpecificOptions buildOptions(final AppStorage storage) => FilesAppSpecificOptions(storage); FilesAppSpecificOptions buildOptions(final AppStorage storage) => FilesAppSpecificOptions(storage);
@override @override
FilesBloc buildBloc(final NextcloudClient client) => FilesBloc( FilesBloc buildBloc(final Account account) => FilesBloc(
options, options,
client, account,
requestManager, requestManager,
platform, platform,
); );

8
packages/neon/neon_news/lib/blocs/article.dart

@ -49,7 +49,7 @@ class NewsArticleBloc extends InteractiveBloc implements NewsArticleBlocEvents,
@override @override
void markArticleAsRead() { void markArticleAsRead() {
_wrapArticleAction(() async { _wrapArticleAction(() async {
await _newsArticlesBloc.client.news.markArticleAsRead(itemId: _id); await _newsArticlesBloc.account.client.news.markArticleAsRead(itemId: _id);
unread.add(false); unread.add(false);
}); });
} }
@ -57,7 +57,7 @@ class NewsArticleBloc extends InteractiveBloc implements NewsArticleBlocEvents,
@override @override
void markArticleAsUnread() { void markArticleAsUnread() {
_wrapArticleAction(() async { _wrapArticleAction(() async {
await _newsArticlesBloc.client.news.markArticleAsUnread(itemId: _id); await _newsArticlesBloc.account.client.news.markArticleAsUnread(itemId: _id);
unread.add(true); unread.add(true);
}); });
} }
@ -65,7 +65,7 @@ class NewsArticleBloc extends InteractiveBloc implements NewsArticleBlocEvents,
@override @override
void starArticle() { void starArticle() {
_wrapArticleAction(() async { _wrapArticleAction(() async {
await _newsArticlesBloc.client.news.starArticle(itemId: _id); await _newsArticlesBloc.account.client.news.starArticle(itemId: _id);
starred.add(true); starred.add(true);
}); });
} }
@ -73,7 +73,7 @@ class NewsArticleBloc extends InteractiveBloc implements NewsArticleBlocEvents,
@override @override
void unstarArticle() { void unstarArticle() {
_wrapArticleAction(() async { _wrapArticleAction(() async {
await _newsArticlesBloc.client.news.unstarArticle(itemId: _id); await _newsArticlesBloc.account.client.news.unstarArticle(itemId: _id);
starred.add(false); starred.add(false);
}); });
} }

18
packages/neon/neon_news/lib/blocs/articles.dart

@ -34,7 +34,7 @@ class NewsMainArticlesBloc extends NewsArticlesBloc {
super.newsBloc, super.newsBloc,
super.options, super.options,
super.requestManager, super.requestManager,
super.client, super.account,
); );
} }
@ -43,7 +43,7 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
this._newsBloc, this._newsBloc,
this.options, this.options,
this.requestManager, this.requestManager,
this.client, { this.account, {
this.id, this.id,
this.listType, this.listType,
}) { }) {
@ -60,7 +60,7 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
final NewsBloc _newsBloc; final NewsBloc _newsBloc;
final NewsAppSpecificOptions options; final NewsAppSpecificOptions options;
final RequestManager requestManager; final RequestManager requestManager;
final NextcloudClient client; final Account account;
final int? id; final int? id;
final ListType? listType; final ListType? listType;
@ -126,10 +126,10 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
} }
await requestManager.wrapNextcloud<List<NewsArticle>, NewsListArticles>( await requestManager.wrapNextcloud<List<NewsArticle>, NewsListArticles>(
client.id, account.id,
'news-articles-${type.code}-$id-$getRead', 'news-articles-${type.code}-$id-$getRead',
articles, articles,
() async => client.news.listArticles( () async => account.client.news.listArticles(
type: type.code, type: type.code,
id: id ?? 0, id: id ?? 0,
getRead: getRead ?? true ? 1 : 0, getRead: getRead ?? true ? 1 : 0,
@ -140,12 +140,12 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
@override @override
void markArticleAsRead(final NewsArticle article) { void markArticleAsRead(final NewsArticle article) {
wrapAction(() async => client.news.markArticleAsRead(itemId: article.id)); wrapAction(() async => account.client.news.markArticleAsRead(itemId: article.id));
} }
@override @override
void markArticleAsUnread(final NewsArticle article) { void markArticleAsUnread(final NewsArticle article) {
wrapAction(() async => client.news.markArticleAsUnread(itemId: article.id)); wrapAction(() async => account.client.news.markArticleAsUnread(itemId: article.id));
} }
@override @override
@ -155,11 +155,11 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
@override @override
void starArticle(final NewsArticle article) { void starArticle(final NewsArticle article) {
wrapAction(() async => client.news.starArticle(itemId: article.id)); wrapAction(() async => account.client.news.starArticle(itemId: article.id));
} }
@override @override
void unstarArticle(final NewsArticle article) { void unstarArticle(final NewsArticle article) {
wrapAction(() async => client.news.unstarArticle(itemId: article.id)); wrapAction(() async => account.client.news.unstarArticle(itemId: article.id));
} }
} }

32
packages/neon/neon_news/lib/blocs/news.dart

@ -32,7 +32,7 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
NewsBloc( NewsBloc(
this.options, this.options,
this.requestManager, this.requestManager,
this.client, this.account,
) { ) {
mainArticlesBloc.articles.listen((final result) { mainArticlesBloc.articles.listen((final result) {
if (result.hasData) { if (result.hasData) {
@ -52,12 +52,12 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
@override @override
final RequestManager requestManager; final RequestManager requestManager;
@override @override
final NextcloudClient client; final Account account;
late final mainArticlesBloc = NewsMainArticlesBloc( late final mainArticlesBloc = NewsMainArticlesBloc(
this, this,
options, options,
requestManager, requestManager,
client, account,
); );
late int _newestItemId; late int _newestItemId;
@ -96,17 +96,17 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
Future refresh() async { Future refresh() async {
await Future.wait([ await Future.wait([
requestManager.wrapNextcloud<List<NewsFolder>, NewsListFolders>( requestManager.wrapNextcloud<List<NewsFolder>, NewsListFolders>(
client.id, account.id,
'news-folders', 'news-folders',
folders, folders,
() async => client.news.listFolders(), () async => account.client.news.listFolders(),
(final response) => response.folders.toList(), (final response) => response.folders.toList(),
), ),
requestManager.wrapNextcloud<List<NewsFeed>, NewsListFeeds>( requestManager.wrapNextcloud<List<NewsFeed>, NewsListFeeds>(
client.id, account.id,
'news-feeds', 'news-feeds',
feeds, feeds,
() async => client.news.listFeeds(), () async => account.client.news.listFeeds(),
(final response) { (final response) {
// This is a bit ugly, but IDGAF right now // This is a bit ugly, but IDGAF right now
if (response.newestItemId != null) { if (response.newestItemId != null) {
@ -121,47 +121,47 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
@override @override
void addFeed(final String url, final int? folderId) { void addFeed(final String url, final int? folderId) {
wrapAction(() async => client.news.addFeed(url: url, folderId: folderId)); wrapAction(() async => account.client.news.addFeed(url: url, folderId: folderId));
} }
@override @override
void createFolder(final String name) { void createFolder(final String name) {
wrapAction(() async => client.news.createFolder(name: name)); wrapAction(() async => account.client.news.createFolder(name: name));
} }
@override @override
void deleteFolder(final int folderId) { void deleteFolder(final int folderId) {
wrapAction(() async => client.news.deleteFolder(folderId: folderId)); wrapAction(() async => account.client.news.deleteFolder(folderId: folderId));
} }
@override @override
void markFeedAsRead(final int feedId) { void markFeedAsRead(final int feedId) {
wrapAction(() async => client.news.markFeedAsRead(feedId: feedId, newestItemId: _newestItemId)); wrapAction(() async => account.client.news.markFeedAsRead(feedId: feedId, newestItemId: _newestItemId));
} }
@override @override
void markFolderAsRead(final int folderId) { void markFolderAsRead(final int folderId) {
wrapAction(() async => client.news.markFolderAsRead(folderId: folderId, newestItemId: _newestItemId)); wrapAction(() async => account.client.news.markFolderAsRead(folderId: folderId, newestItemId: _newestItemId));
} }
@override @override
void moveFeed(final int feedId, final int? folderId) { void moveFeed(final int feedId, final int? folderId) {
wrapAction(() async => client.news.moveFeed(feedId: feedId, folderId: folderId)); wrapAction(() async => account.client.news.moveFeed(feedId: feedId, folderId: folderId));
} }
@override @override
void removeFeed(final int feedId) { void removeFeed(final int feedId) {
wrapAction(() async => client.news.deleteFeed(feedId: feedId)); wrapAction(() async => account.client.news.deleteFeed(feedId: feedId));
} }
@override @override
void renameFeed(final int feedId, final String feedTitle) { void renameFeed(final int feedId, final String feedTitle) {
wrapAction(() async => client.news.renameFeed(feedId: feedId, feedTitle: feedTitle)); wrapAction(() async => account.client.news.renameFeed(feedId: feedId, feedTitle: feedTitle));
} }
@override @override
void renameFolder(final int folderId, final String name) { void renameFolder(final int folderId, final String name) {
wrapAction(() async => client.news.renameFolder(folderId: folderId, name: name)); wrapAction(() async => account.client.news.renameFolder(folderId: folderId, name: name));
} }
@override @override

4
packages/neon/neon_news/lib/neon_news.dart

@ -67,10 +67,10 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
NewsAppSpecificOptions buildOptions(final AppStorage storage) => NewsAppSpecificOptions(storage, platform); NewsAppSpecificOptions buildOptions(final AppStorage storage) => NewsAppSpecificOptions(storage, platform);
@override @override
NewsBloc buildBloc(final NextcloudClient client) => NewsBloc( NewsBloc buildBloc(final Account account) => NewsBloc(
options, options,
requestManager, requestManager,
client, account,
); );
@override @override

2
packages/neon/neon_news/lib/pages/feed.dart

@ -21,7 +21,7 @@ class NewsFeedPage extends StatelessWidget {
bloc, bloc,
bloc.options, bloc.options,
bloc.requestManager, bloc.requestManager,
bloc.client, bloc.account,
id: feed.id, id: feed.id,
listType: ListType.feed, listType: ListType.feed,
), ),

2
packages/neon/neon_news/lib/widgets/folder_view.dart

@ -48,7 +48,7 @@ class _NewsFolderViewState extends State<NewsFolderView> {
widget.bloc, widget.bloc,
widget.bloc.options, widget.bloc.options,
widget.bloc.requestManager, widget.bloc.requestManager,
widget.bloc.client, widget.bloc.account,
id: widget.folder.id, id: widget.folder.id,
listType: ListType.folder, listType: ListType.folder,
), ),

6
packages/neon/neon_notes/lib/blocs/note.dart

@ -67,7 +67,7 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note
@override @override
void updateCategory(final String category) { void updateCategory(final String category) {
_wrapAction( _wrapAction(
(final etag) async => _notesBloc.client.notes.updateNote( (final etag) async => _notesBloc.account.client.notes.updateNote(
id: id, id: id,
category: category, category: category,
ifMatch: '"$etag"', ifMatch: '"$etag"',
@ -78,7 +78,7 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note
@override @override
void updateContent(final String content) { void updateContent(final String content) {
_wrapAction( _wrapAction(
(final etag) async => _notesBloc.client.notes.updateNote( (final etag) async => _notesBloc.account.client.notes.updateNote(
id: id, id: id,
content: content, content: content,
ifMatch: '"$etag"', ifMatch: '"$etag"',
@ -89,7 +89,7 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note
@override @override
void updateTitle(final String title) { void updateTitle(final String title) {
_wrapAction( _wrapAction(
(final etag) async => _notesBloc.client.notes.updateNote( (final etag) async => _notesBloc.account.client.notes.updateNote(
id: id, id: id,
title: title, title: title,
ifMatch: '"$etag"', ifMatch: '"$etag"',

14
packages/neon/neon_notes/lib/blocs/notes.dart

@ -26,14 +26,14 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
NotesBloc( NotesBloc(
this.options, this.options,
this.requestManager, this.requestManager,
this.client, this.account,
) { ) {
unawaited(refresh()); unawaited(refresh());
} }
final NotesAppSpecificOptions options; final NotesAppSpecificOptions options;
final RequestManager requestManager; final RequestManager requestManager;
final NextcloudClient client; final Account account;
@override @override
void dispose() { void dispose() {
@ -47,10 +47,10 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
@override @override
Future refresh() async { Future refresh() async {
await requestManager.wrapNextcloud<List<NotesNote>, BuiltList>( await requestManager.wrapNextcloud<List<NotesNote>, BuiltList>(
client.id, account.id,
'notes-notes', 'notes-notes',
notes, notes,
() async => client.notes.getNotes(), () async => account.client.notes.getNotes(),
List<NotesNote>.from, List<NotesNote>.from,
); );
} }
@ -58,7 +58,7 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
@override @override
void createNote({final String title = '', final String category = ''}) { void createNote({final String title = '', final String category = ''}) {
wrapAction( wrapAction(
() async => client.notes.createNote( () async => account.client.notes.createNote(
title: title, title: title,
category: category, category: category,
), ),
@ -67,7 +67,7 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
@override @override
void deleteNote(final int id) { void deleteNote(final int id) {
wrapAction(() async => client.notes.deleteNote(id: id)); wrapAction(() async => account.client.notes.deleteNote(id: id));
} }
@override @override
@ -80,7 +80,7 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
final bool? favorite, final bool? favorite,
}) { }) {
wrapAction( wrapAction(
() async => client.notes.updateNote( () async => account.client.notes.updateNote(
id: id, id: id,
title: title, title: title,
category: category, category: category,

4
packages/neon/neon_notes/lib/neon_notes.dart

@ -57,10 +57,10 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
NotesAppSpecificOptions buildOptions(final AppStorage storage) => NotesAppSpecificOptions(storage); NotesAppSpecificOptions buildOptions(final AppStorage storage) => NotesAppSpecificOptions(storage);
@override @override
NotesBloc buildBloc(final NextcloudClient client) => NotesBloc( NotesBloc buildBloc(final Account account) => NotesBloc(
options, options,
requestManager, requestManager,
client, account,
); );
@override @override

12
packages/neon/neon_notifications/lib/blocs/notifications.dart

@ -17,7 +17,7 @@ class NotificationsBloc extends InteractiveBloc
NotificationsBloc( NotificationsBloc(
this.options, this.options,
this._requestManager, this._requestManager,
this._client, this._account,
) { ) {
notifications.listen((final result) { notifications.listen((final result) {
if (result.hasData) { if (result.hasData) {
@ -32,7 +32,7 @@ class NotificationsBloc extends InteractiveBloc
@override @override
final NotificationsAppSpecificOptions options; final NotificationsAppSpecificOptions options;
final RequestManager _requestManager; final RequestManager _requestManager;
final NextcloudClient _client; final Account _account;
late final NeonTimer _timer; late final NeonTimer _timer;
@override @override
@ -53,21 +53,21 @@ class NotificationsBloc extends InteractiveBloc
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapNextcloud<List<NotificationsNotification>, NotificationsListNotifications>( await _requestManager.wrapNextcloud<List<NotificationsNotification>, NotificationsListNotifications>(
_client.id, _account.id,
'notifications-notifications', 'notifications-notifications',
notifications, notifications,
() async => _client.notifications.listNotifications(), () async => _account.client.notifications.listNotifications(),
(final response) => response.ocs.data.toList(), (final response) => response.ocs.data.toList(),
); );
} }
@override @override
void deleteAllNotifications() { void deleteAllNotifications() {
wrapAction(() async => _client.notifications.deleteAllNotifications()); wrapAction(() async => _account.client.notifications.deleteAllNotifications());
} }
@override @override
void deleteNotification(final int id) { void deleteNotification(final int id) {
wrapAction(() async => _client.notifications.deleteNotification(id: id)); wrapAction(() async => _account.client.notifications.deleteNotification(id: id));
} }
} }

4
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -37,10 +37,10 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification
NotificationsAppSpecificOptions buildOptions(final AppStorage storage) => NotificationsAppSpecificOptions(storage); NotificationsAppSpecificOptions buildOptions(final AppStorage storage) => NotificationsAppSpecificOptions(storage);
@override @override
NotificationsBloc buildBloc(final NextcloudClient client) => NotificationsBloc( NotificationsBloc buildBloc(final Account account) => NotificationsBloc(
options, options,
requestManager, requestManager,
client, account,
); );
@override @override

7
packages/nextcloud/lib/src/client.dart

@ -17,14 +17,12 @@ class NextcloudClient extends DynamiteClient {
NextcloudClient( NextcloudClient(
super.baseURL, { super.baseURL, {
this.loginName, this.loginName,
this.username,
final String? password, final String? password,
final String? language, final String? language,
final AppType appType = AppType.unknown, final AppType appType = AppType.unknown,
final String? userAgentOverride, final String? userAgentOverride,
super.cookieJar, super.cookieJar,
}) : assert(loginName != null || username == null, 'Provide loginName instead of username or both'), }) : super(
super(
baseHeaders: (<String, String?>{ baseHeaders: (<String, String?>{
'OCS-APIRequest': 'true', 'OCS-APIRequest': 'true',
'Accept-Language': language, 'Accept-Language': language,
@ -44,9 +42,6 @@ class NextcloudClient extends DynamiteClient {
/// Identifier used for authentication. This can be the username or email or something else. /// Identifier used for authentication. This can be the username or email or something else.
final String? loginName; final String? loginName;
/// Username of the user on the server
final String? username;
WebDavClient? _webdav; WebDavClient? _webdav;
CoreClient? _core; CoreClient? _core;
NewsClient? _news; NewsClient? _news;

2
packages/nextcloud/test/helper.dart

@ -76,7 +76,6 @@ class TestNextcloudClient extends NextcloudClient {
TestNextcloudClient( TestNextcloudClient(
super.baseURL, { super.baseURL, {
super.loginName, super.loginName,
super.username,
super.password, super.password,
super.language, super.language,
super.appType, super.appType,
@ -126,7 +125,6 @@ Future<TestNextcloudClient> getTestClient(
final client = TestNextcloudClient( final client = TestNextcloudClient(
'http://localhost:${container.port}', 'http://localhost:${container.port}',
loginName: username, loginName: username,
username: username,
password: clientPassword, password: clientPassword,
appType: appType, appType: appType,
userAgentOverride: userAgentOverride, userAgentOverride: userAgentOverride,

Loading…
Cancel
Save