From 7afb4b2f9e08012ef016b6545c083364db6e8861 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 25 Sep 2022 01:21:57 +0200 Subject: [PATCH] nextcloud: Add methods to check if app is supported --- packages/neon/pubspec.lock | 7 ++++ packages/nextcloud/lib/nextcloud.dart | 2 ++ .../nextcloud/lib/src/version_supported.dart | 32 +++++++++++++++++++ packages/nextcloud/pubspec.yaml | 1 + packages/nextcloud/test/core_test.dart | 6 ++++ packages/nextcloud/test/news_test.dart | 5 +++ packages/nextcloud/test/notes_test.dart | 5 +++ 7 files changed, 58 insertions(+) create mode 100644 packages/nextcloud/lib/src/version_supported.dart diff --git a/packages/neon/pubspec.lock b/packages/neon/pubspec.lock index bd76ca16..159d239f 100644 --- a/packages/neon/pubspec.lock +++ b/packages/neon/pubspec.lock @@ -1226,6 +1226,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + version: + dependency: transitive + description: + name: version + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" vm_service: dependency: transitive description: diff --git a/packages/nextcloud/lib/nextcloud.dart b/packages/nextcloud/lib/nextcloud.dart index ab075061..c92b3394 100644 --- a/packages/nextcloud/lib/nextcloud.dart +++ b/packages/nextcloud/lib/nextcloud.dart @@ -7,6 +7,7 @@ import 'dart:typed_data'; import 'package:crypto/crypto.dart'; import 'package:intl/intl.dart'; import 'package:nextcloud/nextcloud.dart'; +import 'package:version/version.dart'; import 'package:xml/xml.dart' as xml; export 'package:crypton/crypton.dart' show RSAKeypair, RSAPublicKey, RSAPrivateKey; @@ -16,6 +17,7 @@ export 'src/nextcloud.openapi.dart'; part 'src/app_type.dart'; part 'src/client.dart'; part 'src/helpers.dart'; +part 'src/version_supported.dart'; part 'src/webdav/client.dart'; part 'src/webdav/file.dart'; part 'src/webdav/props.dart'; diff --git a/packages/nextcloud/lib/src/version_supported.dart b/packages/nextcloud/lib/src/version_supported.dart new file mode 100644 index 00000000..cdc323c4 --- /dev/null +++ b/packages/nextcloud/lib/src/version_supported.dart @@ -0,0 +1,32 @@ +part of '../nextcloud.dart'; + +// ignore: public_member_api_docs +extension CoreVersionSupported on CoreClient { + /// Checks if the app on the server is supported by the client + Future isSupported([final CoreServerCapabilitiesOcsData? capabilities]) async => + (capabilities ?? (await rootClient.core.getCapabilities()).ocs!.data!).version!.major! == 24; +} + +// ignore: public_member_api_docs +extension NewsVersionSupported on NewsClient { + /// Checks if the app on the server is supported by the client + Future isSupported() async { + final versions = await getSupportedApiVersions(); + return versions.apiLevels!.contains('v1-2'); + } +} + +// ignore: public_member_api_docs +extension NotesVersionSupported on NotesClient { + /// Checks if the app on the server is supported by the client + Future isSupported([final CoreServerCapabilitiesOcsData? capabilities]) async => + (capabilities ?? (await rootClient.core.getCapabilities()).ocs!.data!) + .capabilities! + .notes! + .apiVersion! + .map(Version.parse) + .where((final version) => version.major == 1) + .isNotEmpty; +} + +// Notifications, ProvisioningApi, UserStatus and Webdav are shipped with the Nextcloud server, so their supported versions depend on the major version of the Nextcloud instance. diff --git a/packages/nextcloud/pubspec.yaml b/packages/nextcloud/pubspec.yaml index cfb29ca7..3c5054e2 100644 --- a/packages/nextcloud/pubspec.yaml +++ b/packages/nextcloud/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: intl: ^0.17.0 json_annotation: ^4.6.0 meta: ^1.7.0 + version: ^3.0.2 xml: ^6.1.0 dev_dependencies: diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index dccdba27..d1f08a90 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -1,3 +1,4 @@ +import 'package:nextcloud/nextcloud.dart'; import 'package:test/test.dart'; import 'helper.dart'; @@ -17,6 +18,11 @@ Future main() async { }); tearDown(() => client.destroy()); + test('Is supported', () async { + final response = await client.core.isSupported(); + expect(response, isTrue); + }); + test('Get status', () async { final status = await client.core.getStatus(); expect(status.installed, true); diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index 5ca0b713..1cc3d6e3 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -25,6 +25,11 @@ Future main() async { url: nasaFeedURL, ); + test('Is supported', () async { + final response = await client.news.isSupported(); + expect(response, isTrue); + }); + test('Add feed', () async { var response = await client.news.listFeeds(); expect(response.starredCount, 0); diff --git a/packages/nextcloud/test/notes_test.dart b/packages/nextcloud/test/notes_test.dart index c974cb36..f3f1b0d9 100644 --- a/packages/nextcloud/test/notes_test.dart +++ b/packages/nextcloud/test/notes_test.dart @@ -13,6 +13,11 @@ Future main() async { }); tearDown(() => client.destroy()); + test('Is supported', () async { + final response = await client.notes.isSupported(); + expect(response, isTrue); + }); + test('Create note favorite', () async { final response = await client.notes.createNote( title: 'a',