From f8765fb2fb5d18e8ed609bff1efbc0bb583a5818 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 26 Sep 2023 22:56:46 +0200 Subject: [PATCH] refactor(app,neon_files,neon_news,neon_notes,neon_notifications): adapt to new request manager Signed-off-by: Nikolas Rimikis --- .../app/integration_test/screenshot_test.dart | 3 ++- packages/neon/neon/lib/src/blocs/apps.dart | 6 ++--- .../neon/neon/lib/src/blocs/capabilities.dart | 6 ++--- .../lib/src/blocs/login_check_account.dart | 2 +- .../src/blocs/login_check_server_status.dart | 2 +- .../neon/neon/lib/src/blocs/login_flow.dart | 6 ++--- .../neon/neon/lib/src/blocs/next_push.dart | 3 ++- .../lib/src/blocs/push_notifications.dart | 2 +- .../neon/lib/src/blocs/unified_search.dart | 5 ++-- .../neon/neon/lib/src/blocs/user_details.dart | 6 ++--- .../neon/lib/src/blocs/user_statuses.dart | 4 ++-- packages/neon/neon/lib/src/pages/home.dart | 2 +- .../neon/neon/lib/src/utils/push_utils.dart | 7 +++--- .../neon/lib/src/widgets/cached_image.dart | 7 ++++-- .../neon/lib/src/widgets/user_avatar.dart | 24 +++++++++---------- .../neon/neon_files/lib/blocs/browser.dart | 2 +- .../neon/neon_news/lib/blocs/articles.dart | 6 ++--- packages/neon/neon_news/lib/blocs/news.dart | 16 ++++++------- packages/neon/neon_notes/lib/blocs/note.dart | 6 ++--- packages/neon/neon_notes/lib/blocs/notes.dart | 6 ++--- .../lib/blocs/notifications.dart | 11 ++++----- 21 files changed, 66 insertions(+), 66 deletions(-) diff --git a/packages/app/integration_test/screenshot_test.dart b/packages/app/integration_test/screenshot_test.dart index 50973fea..86f83251 100644 --- a/packages/app/integration_test/screenshot_test.dart +++ b/packages/app/integration_test/screenshot_test.dart @@ -53,6 +53,7 @@ Future getAccount(final String username) async { loginName: username, password: username, ).core.appPassword.getAppPassword()) + .body .ocs .data .apppassword; @@ -149,7 +150,7 @@ Future main() async { final folder = await account.client.news.createFolder(name: 'test'); await account.client.news.addFeed( url: nasaFeedURL, - folderId: folder.folders.single.id, + folderId: folder.body.folders.single.id, ); await runTestApp( diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 54fd9fa7..9733e0f6 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -199,12 +199,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates @override Future refresh() async { await RequestManager.instance - .wrapNextcloud, CoreNavigationGetAppsNavigationResponseApplicationJson>( + .wrapNextcloud, CoreNavigationGetAppsNavigationResponseApplicationJson, void>( _account.id, 'apps-apps', apps, - () async => _account.client.core.navigation.getAppsNavigation(), - (final response) => response.ocs.data.toList(), + _account.client.core.navigation.getAppsNavigationRaw(), + (final response) => response.body.ocs.data.toList(), ); } diff --git a/packages/neon/neon/lib/src/blocs/capabilities.dart b/packages/neon/neon/lib/src/blocs/capabilities.dart index a2f91e95..f67a1d43 100644 --- a/packages/neon/neon/lib/src/blocs/capabilities.dart +++ b/packages/neon/neon/lib/src/blocs/capabilities.dart @@ -39,12 +39,12 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents @override Future refresh() async { await RequestManager.instance.wrapNextcloud( + CoreOcsGetCapabilitiesResponseApplicationJson, void>( _account.id, 'capabilities', capabilities, - () async => _account.client.core.ocs.getCapabilities(), - (final response) => response.ocs.data, + _account.client.core.ocs.getCapabilitiesRaw(), + (final response) => response.body.ocs.data, ); } } diff --git a/packages/neon/neon/lib/src/blocs/login_check_account.dart b/packages/neon/neon/lib/src/blocs/login_check_account.dart index 337b3e56..1d1b7bf0 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_account.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_account.dart @@ -59,7 +59,7 @@ class LoginCheckAccountBloc extends InteractiveBloc final account = Account( serverURL: serverURL, - username: response.ocs.data.id, + username: response.body.ocs.data.id, password: password, userAgent: neonUserAgent, ); diff --git a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart index 1f7eeb4d..73a42f57 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart @@ -47,7 +47,7 @@ class LoginCheckServerStatusBloc extends InteractiveBloc ); final status = await client.core.getStatus(); - state.add(Result.success(status)); + state.add(Result.success(status.body)); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/blocs/login_flow.dart b/packages/neon/neon/lib/src/blocs/login_flow.dart index a0d3e892..2f640bdd 100644 --- a/packages/neon/neon/lib/src/blocs/login_flow.dart +++ b/packages/neon/neon/lib/src/blocs/login_flow.dart @@ -54,14 +54,14 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi init.add(Result.loading()); final initResponse = await _client.core.clientFlowLoginV2.init(); - init.add(Result.success(initResponse)); + init.add(Result.success(initResponse.body)); _cancelPollTimer(); _pollTimer = Timer.periodic(const Duration(seconds: 1), (final _) async { try { - final resultResponse = await _client.core.clientFlowLoginV2.poll(token: initResponse.poll.token); + final resultResponse = await _client.core.clientFlowLoginV2.poll(token: initResponse.body.poll.token); _cancelPollTimer(); - _resultController.add(resultResponse); + _resultController.add(resultResponse.body); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/blocs/next_push.dart b/packages/neon/neon/lib/src/blocs/next_push.dart index 0e9184f1..79ad6e62 100644 --- a/packages/neon/neon/lib/src/blocs/next_push.dart +++ b/packages/neon/neon/lib/src/blocs/next_push.dart @@ -46,7 +46,8 @@ class NextPushBloc extends Bloc implements NextPushBlocEvents, NextPushBlocState for (final account in _accountsBloc.accounts.value) { if (!_supported.containsKey(account)) { try { - _supported[account] = (await account.client.uppush.check()).success; + final response = await account.client.uppush.check(); + _supported[account] = response.body.success; } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/blocs/push_notifications.dart b/packages/neon/neon/lib/src/blocs/push_notifications.dart index bc5c7051..9571bb53 100644 --- a/packages/neon/neon/lib/src/blocs/push_notifications.dart +++ b/packages/neon/neon/lib/src/blocs/push_notifications.dart @@ -96,7 +96,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, await _storage.setString(_keyLastEndpoint(account), endpoint); debugPrint( - 'Account $instance registered for push notifications ${json.encode(subscription.ocs.data.toJson())}', + 'Account $instance registered for push notifications ${json.encode(subscription.body.ocs.data.toJson())}', ); }, onMessage: PushUtils.onMessage, diff --git a/packages/neon/neon/lib/src/blocs/unified_search.dart b/packages/neon/neon/lib/src/blocs/unified_search.dart index a20e59ad..e99933ab 100644 --- a/packages/neon/neon/lib/src/blocs/unified_search.dart +++ b/packages/neon/neon/lib/src/blocs/unified_search.dart @@ -88,7 +88,8 @@ class UnifiedSearchBloc extends InteractiveBloc implements UnifiedSearchBlocEven try { results.add(results.value.asLoading()); - final providers = (await _account.client.core.unifiedSearch.getProviders()).ocs.data; + final response = await _account.client.core.unifiedSearch.getProviders(); + final providers = response.body.ocs.data; results.add( Result.success(Map.fromEntries(_getLoadingProviders(providers))), ); @@ -117,7 +118,7 @@ class UnifiedSearchBloc extends InteractiveBloc implements UnifiedSearchBlocEven providerId: provider.id, term: _term, ); - _updateResults(provider, Result.success(response.ocs.data)); + _updateResults(provider, Result.success(response.body.ocs.data)); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/blocs/user_details.dart b/packages/neon/neon/lib/src/blocs/user_details.dart index d109406b..2336ab9c 100644 --- a/packages/neon/neon/lib/src/blocs/user_details.dart +++ b/packages/neon/neon/lib/src/blocs/user_details.dart @@ -39,12 +39,12 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents, @override Future refresh() async { await RequestManager.instance - .wrapNextcloud( + .wrapNextcloud( _account.id, 'user-details', userDetails, - () async => _account.client.provisioningApi.users.getCurrentUser(), - (final response) => response.ocs.data, + _account.client.provisioningApi.users.getCurrentUserRaw(), + (final response) => response.body.ocs.data, ); } } diff --git a/packages/neon/neon/lib/src/blocs/user_statuses.dart b/packages/neon/neon/lib/src/blocs/user_statuses.dart index 5cf0dd3b..eee802de 100644 --- a/packages/neon/neon/lib/src/blocs/user_statuses.dart +++ b/packages/neon/neon/lib/src/blocs/user_statuses.dart @@ -73,7 +73,7 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents final response = await _account.client.userStatus.heartbeat.heartbeat( status: isAway ? 'away' : 'online', ); - data = response.ocs.data; + data = response.body.ocs.data; } catch (e) { // 204 is returned if the heartbeat failed because the current status is different. Ignore this and fetch the normal status if (e is! DynamiteApiException || e.statusCode != 204) { @@ -84,7 +84,7 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents if (data == null) { final response = await _account.client.userStatus.statuses.find(userId: username); - data = response.ocs.data; + data = response.body.ocs.data; } _updateStatus(username, Result.success(data)); diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index 2ff64712..a66a881a 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -82,7 +82,7 @@ class _HomePageState extends State { Future _checkMaintenanceMode() async { try { final status = await _account.client.core.getStatus(); - if (status.maintenance && mounted) { + if (status.body.maintenance && mounted) { await _showProblem( AppLocalizations.of(context).errorServerInMaintenanceMode, ); diff --git a/packages/neon/neon/lib/src/utils/push_utils.dart b/packages/neon/neon/lib/src/utils/push_utils.dart index 0880f97c..49a99188 100644 --- a/packages/neon/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/neon/lib/src/utils/push_utils.dart @@ -102,10 +102,9 @@ class PushUtils { try { account = accounts.tryFind(instance); if (account != null) { - notification = - (await account.client.notifications.endpoint.getNotification(id: pushNotification.subject.nid!)) - .ocs - .data; + final response = + await account.client.notifications.endpoint.getNotification(id: pushNotification.subject.nid!); + notification = response.body.ocs.data; if (notification.icon?.endsWith('.svg') ?? false) { // Only SVG icons are supported right now (should be most of them) diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index 4f393d73..08a58bb6 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -17,7 +17,7 @@ typedef ImageDownloader = FutureOr Function(); typedef CacheWriter = Future Function(CacheManager cacheManager, Uint8List image); typedef ErrorWidgetBuilder = Widget? Function(BuildContext, dynamic); -typedef ApiImageDownloader = FutureOr Function(NextcloudClient client); +typedef ApiImageDownloader = FutureOr> Function(NextcloudClient client); class NeonCachedImage extends StatefulWidget { const NeonCachedImage({ @@ -223,7 +223,10 @@ class NeonApiImage extends StatelessWidget { final account = NeonProvider.of(context).activeAccount.value!; return NeonCachedImage.custom( - getImage: () async => getImage(account.client), + getImage: () async { + final response = await getImage(account.client); + return response.body; + }, cacheKey: '${account.id}-$cacheKey', ); } diff --git a/packages/neon/neon/lib/src/widgets/user_avatar.dart b/packages/neon/neon/lib/src/widgets/user_avatar.dart index f4277785..76c7c391 100644 --- a/packages/neon/neon/lib/src/widgets/user_avatar.dart +++ b/packages/neon/neon/lib/src/widgets/user_avatar.dart @@ -64,19 +64,17 @@ class _UserAvatarState extends State { child: NeonCachedImage.custom( cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize', getImage: () async { - if (brightness == Brightness.dark) { - return (await widget.account.client.core.avatar.getAvatarDark( - userId: widget.username, - size: pixelSize, - )) - .data; - } else { - return (await widget.account.client.core.avatar.getAvatar( - userId: widget.username, - size: pixelSize, - )) - .data; - } + final response = switch (brightness) { + Brightness.dark => await widget.account.client.core.avatar.getAvatarDark( + userId: widget.username, + size: pixelSize, + ), + Brightness.light => await widget.account.client.core.avatar.getAvatar( + userId: widget.username, + size: pixelSize, + ), + }; + return response.body; }, ), ), diff --git a/packages/neon/neon_files/lib/blocs/browser.dart b/packages/neon/neon_files/lib/blocs/browser.dart index b644e9a7..80c97062 100644 --- a/packages/neon/neon_files/lib/blocs/browser.dart +++ b/packages/neon/neon_files/lib/blocs/browser.dart @@ -47,7 +47,7 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents account.id, 'files-${path.value.join('/')}', files, - () async => account.client.webdav.propfind( + () => account.client.webdav.propfind( Uri(pathSegments: path.value), prop: WebDavPropWithoutValues.fromBools( davgetcontenttype: true, diff --git a/packages/neon/neon_news/lib/blocs/articles.dart b/packages/neon/neon_news/lib/blocs/articles.dart index c8ae115f..45b2c287 100644 --- a/packages/neon/neon_news/lib/blocs/articles.dart +++ b/packages/neon/neon_news/lib/blocs/articles.dart @@ -115,16 +115,16 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents } } - await RequestManager.instance.wrapNextcloud, NewsListArticles>( + await RequestManager.instance.wrapNextcloud, NewsListArticles, void>( account.id, 'news-articles-${type.index}-$id-$getRead', articles, - () async => account.client.news.listArticles( + account.client.news.listArticlesRaw( type: type.index, id: id ?? 0, getRead: getRead ?? true ? 1 : 0, ), - (final response) => response.items.toList(), + (final response) => response.body.items.toList(), ); } diff --git a/packages/neon/neon_news/lib/blocs/news.dart b/packages/neon/neon_news/lib/blocs/news.dart index 224fec85..1f7033de 100644 --- a/packages/neon/neon_news/lib/blocs/news.dart +++ b/packages/neon/neon_news/lib/blocs/news.dart @@ -92,23 +92,23 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates @override Future refresh() async { await Future.wait([ - RequestManager.instance.wrapNextcloud, NewsListFolders>( + RequestManager.instance.wrapNextcloud, NewsListFolders, void>( account.id, 'news-folders', folders, - () async => account.client.news.listFolders(), - (final response) => response.folders.toList(), + account.client.news.listFoldersRaw(), + (final response) => response.body.folders.toList(), ), - RequestManager.instance.wrapNextcloud, NewsListFeeds>( + RequestManager.instance.wrapNextcloud, NewsListFeeds, void>( account.id, 'news-feeds', feeds, - () async => account.client.news.listFeeds(), + account.client.news.listFeedsRaw(), (final response) { - if (response.newestItemId != null) { - _newestItemId = response.newestItemId!; + if (response.body.newestItemId != null) { + _newestItemId = response.body.newestItemId!; } - return response.feeds.toList(); + return response.body.feeds.toList(); }, ), mainArticlesBloc.reload(), diff --git a/packages/neon/neon_notes/lib/blocs/note.dart b/packages/neon/neon_notes/lib/blocs/note.dart index de552b54..02e8b9aa 100644 --- a/packages/neon/neon_notes/lib/blocs/note.dart +++ b/packages/neon/neon_notes/lib/blocs/note.dart @@ -29,11 +29,11 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note } // ignore: avoid_void_async - void _wrapAction(final Future Function(String etag) call) async { + void _wrapAction(final Future> Function(String etag) call) async { await _updateQueue.add(() async { try { - final data = await call(_etag); - _emitNote(data); + final response = await call(_etag); + _emitNote(response.body); await _notesBloc.refresh(); } catch (e, s) { debugPrint(e.toString()); diff --git a/packages/neon/neon_notes/lib/blocs/notes.dart b/packages/neon/neon_notes/lib/blocs/notes.dart index 2f24714b..64e3a38f 100644 --- a/packages/neon/neon_notes/lib/blocs/notes.dart +++ b/packages/neon/neon_notes/lib/blocs/notes.dart @@ -44,12 +44,12 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta @override Future refresh() async { - await RequestManager.instance.wrapNextcloud, BuiltList>( + await RequestManager.instance.wrapNextcloud, BuiltList, void>( account.id, 'notes-notes', notes, - () async => account.client.notes.getNotes(), - List.from, + account.client.notes.getNotesRaw(), + (final response) => List.from(response.body), ); } diff --git a/packages/neon/neon_notifications/lib/blocs/notifications.dart b/packages/neon/neon_notifications/lib/blocs/notifications.dart index e0da4a9f..6ea611e0 100644 --- a/packages/neon/neon_notifications/lib/blocs/notifications.dart +++ b/packages/neon/neon_notifications/lib/blocs/notifications.dart @@ -50,16 +50,13 @@ class NotificationsBloc extends InteractiveBloc @override Future refresh() async { - await RequestManager.instance - .wrapNextcloud, NotificationsEndpointListNotificationsResponseApplicationJson>( + await RequestManager.instance.wrapNextcloud, + NotificationsEndpointListNotificationsResponseApplicationJson, void>( _account.id, 'notifications-notifications', notifications, - () async { - final response = await _account.client.notifications.endpoint.listNotifications(); - return response.data; - }, - (final response) => response.ocs.data.toList(), + _account.client.notifications.endpoint.listNotificationsRaw(), + (final response) => response.body.ocs.data.toList(), ); }