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,
password: username,
).core.appPassword.getAppPassword())
.body
.ocs
.data
.apppassword;
@ -149,7 +150,7 @@ Future<void> 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(

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

@ -199,12 +199,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future<void> refresh() async {
await RequestManager.instance
.wrapNextcloud<List<CoreNavigationEntry>, CoreNavigationGetAppsNavigationResponseApplicationJson>(
.wrapNextcloud<List<CoreNavigationEntry>, 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(),
);
}

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

@ -39,12 +39,12 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
@override
Future<void> refresh() async {
await RequestManager.instance.wrapNextcloud<CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data,
CoreOcsGetCapabilitiesResponseApplicationJson>(
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,
);
}
}

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

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();
state.add(Result.success(status));
state.add(Result.success(status.body));
} catch (e, s) {
debugPrint(e.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());
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());

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) {
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());

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

5
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());

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

@ -39,12 +39,12 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,
@override
Future<void> refresh() async {
await RequestManager.instance
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponseApplicationJson>(
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponseApplicationJson, void>(
_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,
);
}
}

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(
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));

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

@ -82,7 +82,7 @@ class _HomePageState extends State<HomePage> {
Future<void> _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,
);

7
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)

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 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 {
const NeonCachedImage({
@ -223,7 +223,10 @@ class NeonApiImage extends StatelessWidget {
final account = NeonProvider.of<AccountsBloc>(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',
);
}

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

@ -64,19 +64,17 @@ class _UserAvatarState extends State<NeonUserAvatar> {
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(
final response = switch (brightness) {
Brightness.dark => await widget.account.client.core.avatar.getAvatarDark(
userId: widget.username,
size: pixelSize,
))
.data;
} else {
return (await widget.account.client.core.avatar.getAvatar(
),
Brightness.light => await widget.account.client.core.avatar.getAvatar(
userId: widget.username,
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,
'files-${path.value.join('/')}',
files,
() async => account.client.webdav.propfind(
() => account.client.webdav.propfind(
Uri(pathSegments: path.value),
prop: WebDavPropWithoutValues.fromBools(
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,
'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(),
);
}

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

@ -92,23 +92,23 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates
@override
Future<void> refresh() async {
await Future.wait([
RequestManager.instance.wrapNextcloud<List<NewsFolder>, NewsListFolders>(
RequestManager.instance.wrapNextcloud<List<NewsFolder>, 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<List<NewsFeed>, NewsListFeeds>(
RequestManager.instance.wrapNextcloud<List<NewsFeed>, 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(),

6
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<NotesNote> Function(String etag) call) async {
void _wrapAction(final Future<DynamiteResponse<NotesNote, dynamic>> 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());

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

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

Loading…
Cancel
Save