Browse Source

refactor(app,neon_files,neon_news,neon_notes,neon_notifications): adapt to new request manager

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/846/head
Nikolas Rimikis 1 year ago
parent
commit
f8765fb2fb
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 3
      packages/app/integration_test/screenshot_test.dart
  2. 6
      packages/neon/neon/lib/src/blocs/apps.dart
  3. 6
      packages/neon/neon/lib/src/blocs/capabilities.dart
  4. 2
      packages/neon/neon/lib/src/blocs/login_check_account.dart
  5. 2
      packages/neon/neon/lib/src/blocs/login_check_server_status.dart
  6. 6
      packages/neon/neon/lib/src/blocs/login_flow.dart
  7. 3
      packages/neon/neon/lib/src/blocs/next_push.dart
  8. 2
      packages/neon/neon/lib/src/blocs/push_notifications.dart
  9. 5
      packages/neon/neon/lib/src/blocs/unified_search.dart
  10. 6
      packages/neon/neon/lib/src/blocs/user_details.dart
  11. 4
      packages/neon/neon/lib/src/blocs/user_statuses.dart
  12. 2
      packages/neon/neon/lib/src/pages/home.dart
  13. 7
      packages/neon/neon/lib/src/utils/push_utils.dart
  14. 7
      packages/neon/neon/lib/src/widgets/cached_image.dart
  15. 16
      packages/neon/neon/lib/src/widgets/user_avatar.dart
  16. 2
      packages/neon/neon_files/lib/blocs/browser.dart
  17. 6
      packages/neon/neon_news/lib/blocs/articles.dart
  18. 16
      packages/neon/neon_news/lib/blocs/news.dart
  19. 6
      packages/neon/neon_notes/lib/blocs/note.dart
  20. 6
      packages/neon/neon_notes/lib/blocs/notes.dart
  21. 11
      packages/neon/neon_notifications/lib/blocs/notifications.dart

3
packages/app/integration_test/screenshot_test.dart

@ -53,6 +53,7 @@ Future<Account> getAccount(final String username) async {
loginName: username, loginName: username,
password: username, password: username,
).core.appPassword.getAppPassword()) ).core.appPassword.getAppPassword())
.body
.ocs .ocs
.data .data
.apppassword; .apppassword;
@ -149,7 +150,7 @@ Future<void> main() async {
final folder = await account.client.news.createFolder(name: 'test'); final folder = await account.client.news.createFolder(name: 'test');
await account.client.news.addFeed( await account.client.news.addFeed(
url: nasaFeedURL, url: nasaFeedURL,
folderId: folder.folders.single.id, folderId: folder.body.folders.single.id,
); );
await runTestApp( await runTestApp(

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

@ -199,12 +199,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await RequestManager.instance await RequestManager.instance
.wrapNextcloud<List<CoreNavigationEntry>, CoreNavigationGetAppsNavigationResponseApplicationJson>( .wrapNextcloud<List<CoreNavigationEntry>, CoreNavigationGetAppsNavigationResponseApplicationJson, void>(
_account.id, _account.id,
'apps-apps', 'apps-apps',
apps, apps,
() async => _account.client.core.navigation.getAppsNavigation(), _account.client.core.navigation.getAppsNavigationRaw(),
(final response) => response.ocs.data.toList(), (final response) => response.body.ocs.data.toList(),
); );
} }

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

@ -39,12 +39,12 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await RequestManager.instance.wrapNextcloud<CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data, await RequestManager.instance.wrapNextcloud<CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data,
CoreOcsGetCapabilitiesResponseApplicationJson>( CoreOcsGetCapabilitiesResponseApplicationJson, void>(
_account.id, _account.id,
'capabilities', 'capabilities',
capabilities, capabilities,
() async => _account.client.core.ocs.getCapabilities(), _account.client.core.ocs.getCapabilitiesRaw(),
(final response) => response.ocs.data, (final response) => response.body.ocs.data,
); );
} }
} }

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

@ -59,7 +59,7 @@ class LoginCheckAccountBloc extends InteractiveBloc
final account = Account( final account = Account(
serverURL: serverURL, serverURL: serverURL,
username: response.ocs.data.id, username: response.body.ocs.data.id,
password: password, password: password,
userAgent: neonUserAgent, userAgent: neonUserAgent,
); );

2
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(); final status = await client.core.getStatus();
state.add(Result.success(status)); state.add(Result.success(status.body));
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());

6
packages/neon/neon/lib/src/blocs/login_flow.dart

@ -54,14 +54,14 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
init.add(Result.loading()); init.add(Result.loading());
final initResponse = await _client.core.clientFlowLoginV2.init(); final initResponse = await _client.core.clientFlowLoginV2.init();
init.add(Result.success(initResponse)); init.add(Result.success(initResponse.body));
_cancelPollTimer(); _cancelPollTimer();
_pollTimer = Timer.periodic(const Duration(seconds: 1), (final _) async { _pollTimer = Timer.periodic(const Duration(seconds: 1), (final _) async {
try { 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(); _cancelPollTimer();
_resultController.add(resultResponse); _resultController.add(resultResponse.body);
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());

3
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) { for (final account in _accountsBloc.accounts.value) {
if (!_supported.containsKey(account)) { if (!_supported.containsKey(account)) {
try { try {
_supported[account] = (await account.client.uppush.check()).success; final response = await account.client.uppush.check();
_supported[account] = response.body.success;
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());

2
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); await _storage.setString(_keyLastEndpoint(account), endpoint);
debugPrint( 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, onMessage: PushUtils.onMessage,

5
packages/neon/neon/lib/src/blocs/unified_search.dart

@ -88,7 +88,8 @@ class UnifiedSearchBloc extends InteractiveBloc implements UnifiedSearchBlocEven
try { try {
results.add(results.value.asLoading()); 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( results.add(
Result.success(Map.fromEntries(_getLoadingProviders(providers))), Result.success(Map.fromEntries(_getLoadingProviders(providers))),
); );
@ -117,7 +118,7 @@ class UnifiedSearchBloc extends InteractiveBloc implements UnifiedSearchBlocEven
providerId: provider.id, providerId: provider.id,
term: _term, term: _term,
); );
_updateResults(provider, Result.success(response.ocs.data)); _updateResults(provider, Result.success(response.body.ocs.data));
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());

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

@ -39,12 +39,12 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await RequestManager.instance await RequestManager.instance
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponseApplicationJson>( .wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponseApplicationJson, void>(
_account.id, _account.id,
'user-details', 'user-details',
userDetails, userDetails,
() async => _account.client.provisioningApi.users.getCurrentUser(), _account.client.provisioningApi.users.getCurrentUserRaw(),
(final response) => response.ocs.data, (final response) => response.body.ocs.data,
); );
} }
} }

4
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( final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online', status: isAway ? 'away' : 'online',
); );
data = response.ocs.data; data = response.body.ocs.data;
} catch (e) { } catch (e) {
// 204 is returned if the heartbeat failed because the current status is different. Ignore this and fetch the normal status // 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) { if (e is! DynamiteApiException || e.statusCode != 204) {
@ -84,7 +84,7 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
if (data == null) { if (data == null) {
final response = await _account.client.userStatus.statuses.find(userId: username); final response = await _account.client.userStatus.statuses.find(userId: username);
data = response.ocs.data; data = response.body.ocs.data;
} }
_updateStatus(username, Result.success(data)); _updateStatus(username, Result.success(data));

2
packages/neon/neon/lib/src/pages/home.dart

@ -82,7 +82,7 @@ class _HomePageState extends State<HomePage> {
Future<void> _checkMaintenanceMode() async { Future<void> _checkMaintenanceMode() async {
try { try {
final status = await _account.client.core.getStatus(); final status = await _account.client.core.getStatus();
if (status.maintenance && mounted) { if (status.body.maintenance && mounted) {
await _showProblem( await _showProblem(
AppLocalizations.of(context).errorServerInMaintenanceMode, AppLocalizations.of(context).errorServerInMaintenanceMode,
); );

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

@ -102,10 +102,9 @@ class PushUtils {
try { try {
account = accounts.tryFind(instance); account = accounts.tryFind(instance);
if (account != null) { if (account != null) {
notification = final response =
(await account.client.notifications.endpoint.getNotification(id: pushNotification.subject.nid!)) await account.client.notifications.endpoint.getNotification(id: pushNotification.subject.nid!);
.ocs notification = response.body.ocs.data;
.data;
if (notification.icon?.endsWith('.svg') ?? false) { if (notification.icon?.endsWith('.svg') ?? false) {
// Only SVG icons are supported right now (should be most of them) // Only SVG icons are supported right now (should be most of them)

7
packages/neon/neon/lib/src/widgets/cached_image.dart

@ -17,7 +17,7 @@ typedef ImageDownloader = FutureOr<Uint8List> Function();
typedef CacheWriter = Future<void> Function(CacheManager cacheManager, Uint8List image); typedef CacheWriter = Future<void> Function(CacheManager cacheManager, Uint8List image);
typedef ErrorWidgetBuilder = Widget? Function(BuildContext, dynamic); typedef ErrorWidgetBuilder = Widget? Function(BuildContext, dynamic);
typedef ApiImageDownloader = FutureOr<Uint8List> Function(NextcloudClient client); typedef ApiImageDownloader = FutureOr<DynamiteResponse<Uint8List, dynamic>> Function(NextcloudClient client);
class NeonCachedImage extends StatefulWidget { class NeonCachedImage extends StatefulWidget {
const NeonCachedImage({ const NeonCachedImage({
@ -223,7 +223,10 @@ class NeonApiImage extends StatelessWidget {
final account = NeonProvider.of<AccountsBloc>(context).activeAccount.value!; final account = NeonProvider.of<AccountsBloc>(context).activeAccount.value!;
return NeonCachedImage.custom( return NeonCachedImage.custom(
getImage: () async => getImage(account.client), getImage: () async {
final response = await getImage(account.client);
return response.body;
},
cacheKey: '${account.id}-$cacheKey', cacheKey: '${account.id}-$cacheKey',
); );
} }

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

@ -64,19 +64,17 @@ class _UserAvatarState extends State<NeonUserAvatar> {
child: NeonCachedImage.custom( child: NeonCachedImage.custom(
cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize', cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize',
getImage: () async { getImage: () async {
if (brightness == Brightness.dark) { final response = switch (brightness) {
return (await widget.account.client.core.avatar.getAvatarDark( Brightness.dark => await widget.account.client.core.avatar.getAvatarDark(
userId: widget.username, userId: widget.username,
size: pixelSize, size: pixelSize,
)) ),
.data; Brightness.light => await widget.account.client.core.avatar.getAvatar(
} else {
return (await widget.account.client.core.avatar.getAvatar(
userId: widget.username, userId: widget.username,
size: pixelSize, size: pixelSize,
)) ),
.data; };
} return response.body;
}, },
), ),
), ),

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

@ -47,7 +47,7 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
account.id, account.id,
'files-${path.value.join('/')}', 'files-${path.value.join('/')}',
files, files,
() async => account.client.webdav.propfind( () => account.client.webdav.propfind(
Uri(pathSegments: path.value), Uri(pathSegments: path.value),
prop: WebDavPropWithoutValues.fromBools( prop: WebDavPropWithoutValues.fromBools(
davgetcontenttype: true, davgetcontenttype: true,

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

@ -115,16 +115,16 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
} }
} }
await RequestManager.instance.wrapNextcloud<List<NewsArticle>, NewsListArticles>( await RequestManager.instance.wrapNextcloud<List<NewsArticle>, NewsListArticles, void>(
account.id, account.id,
'news-articles-${type.index}-$id-$getRead', 'news-articles-${type.index}-$id-$getRead',
articles, articles,
() async => account.client.news.listArticles( account.client.news.listArticlesRaw(
type: type.index, type: type.index,
id: id ?? 0, id: id ?? 0,
getRead: getRead ?? true ? 1 : 0, getRead: getRead ?? true ? 1 : 0,
), ),
(final response) => response.items.toList(), (final response) => response.body.items.toList(),
); );
} }

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

@ -92,23 +92,23 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await Future.wait([ await Future.wait([
RequestManager.instance.wrapNextcloud<List<NewsFolder>, NewsListFolders>( RequestManager.instance.wrapNextcloud<List<NewsFolder>, NewsListFolders, void>(
account.id, account.id,
'news-folders', 'news-folders',
folders, folders,
() async => account.client.news.listFolders(), account.client.news.listFoldersRaw(),
(final response) => response.folders.toList(), (final response) => response.body.folders.toList(),
), ),
RequestManager.instance.wrapNextcloud<List<NewsFeed>, NewsListFeeds>( RequestManager.instance.wrapNextcloud<List<NewsFeed>, NewsListFeeds, void>(
account.id, account.id,
'news-feeds', 'news-feeds',
feeds, feeds,
() async => account.client.news.listFeeds(), account.client.news.listFeedsRaw(),
(final response) { (final response) {
if (response.newestItemId != null) { if (response.body.newestItemId != null) {
_newestItemId = response.newestItemId!; _newestItemId = response.body.newestItemId!;
} }
return response.feeds.toList(); return response.body.feeds.toList();
}, },
), ),
mainArticlesBloc.reload(), mainArticlesBloc.reload(),

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

@ -29,11 +29,11 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note
} }
// ignore: avoid_void_async // ignore: avoid_void_async
void _wrapAction(final Future<NotesNote> Function(String etag) call) async { void _wrapAction(final Future<DynamiteResponse<NotesNote, dynamic>> Function(String etag) call) async {
await _updateQueue.add(() async { await _updateQueue.add(() async {
try { try {
final data = await call(_etag); final response = await call(_etag);
_emitNote(data); _emitNote(response.body);
await _notesBloc.refresh(); await _notesBloc.refresh();
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());

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

@ -44,12 +44,12 @@ class NotesBloc extends InteractiveBloc implements NotesBlocEvents, NotesBlocSta
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await RequestManager.instance.wrapNextcloud<List<NotesNote>, BuiltList<NotesNote>>( await RequestManager.instance.wrapNextcloud<List<NotesNote>, BuiltList<NotesNote>, void>(
account.id, account.id,
'notes-notes', 'notes-notes',
notes, notes,
() async => account.client.notes.getNotes(), account.client.notes.getNotesRaw(),
List<NotesNote>.from, (final response) => List<NotesNote>.from(response.body),
); );
} }

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

@ -50,16 +50,13 @@ class NotificationsBloc extends InteractiveBloc
@override @override
Future<void> refresh() async { Future<void> refresh() async {
await RequestManager.instance await RequestManager.instance.wrapNextcloud<List<NotificationsNotification>,
.wrapNextcloud<List<NotificationsNotification>, NotificationsEndpointListNotificationsResponseApplicationJson>( NotificationsEndpointListNotificationsResponseApplicationJson, void>(
_account.id, _account.id,
'notifications-notifications', 'notifications-notifications',
notifications, notifications,
() async { _account.client.notifications.endpoint.listNotificationsRaw(),
final response = await _account.client.notifications.endpoint.listNotifications(); (final response) => response.body.ocs.data.toList(),
return response.data;
},
(final response) => response.ocs.data.toList(),
); );
} }

Loading…
Cancel
Save