Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/named records #1044

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/neon/neon/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
final notSupported = <String, String?>{};

try {
final (coreSupported, coreMinimumVersion) = _account.client.core.isSupported(capabilities.requireData);
if (!coreSupported) {
notSupported['core'] = coreMinimumVersion.toString();
final coreCheck = _account.client.core.isSupported(capabilities.requireData);
if (!coreCheck.isSupported) {
notSupported['core'] = coreCheck.minimumVersion.toString();
}
} catch (e, s) {
debugPrint(e.toString());
Expand All @@ -134,9 +134,14 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates

for (final app in apps.requireData) {
try {
final (supported, minimumVersion) = await app.isSupported(_account, capabilities.requireData);
if (!(supported ?? true)) {
notSupported[app.id] = minimumVersion;
final check = await app.isSupported(_account, capabilities.requireData);

if (check == null) {
continue;
}

if (!check.isSupported) {
notSupported[app.id] = check.minimumVersion;
}
} catch (e, s) {
debugPrint(e.toString());
Expand Down
10 changes: 5 additions & 5 deletions packages/neon/neon/lib/src/models/app_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart' show VersionSupported;
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:vector_graphics/vector_graphics.dart';
Expand All @@ -36,15 +37,14 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>

/// Checks if the app is supported on the server of the [account].
///
/// A `supported` value of `null` means that it can not be known if the app is supported.
/// A value of `null` means that it can not be known if the app is supported.
/// This is the case for apps that depend on the server version like files and we assume that the app is supported.
/// The server support is handled differently.
///
/// The first value of the record is the supported status and the second value is the supported minimum version.
FutureOr<(bool? supported, String? minimumVersion)> isSupported(
FutureOr<VersionSupported<String>?> isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
);
) =>
null;

final blocsCache = AccountCache<T>();

Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/sort_box/sort_box_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SortBoxBuilder<T extends Enum, R> extends StatelessWidget {
final SortBoxWidgetBuilder<R> builder;

/// Pre sorts input.
final Set<(T property, SortBoxOrder order)>? presort;
final Set<Box<T>>? presort;

@override
Widget build(final BuildContext context) {
Expand All @@ -52,7 +52,7 @@ class SortBoxBuilder<T extends Enum, R> extends StatelessWidget {
builder: (final context, final property, final _) => ValueListenableBuilder<SortBoxOrder>(
valueListenable: sortBoxOrder,
builder: (final context, final order, final _) {
final box = (property, order);
final box = (property: property, order: order);

return builder(context, sortBox.sort(input, box, presort));
},
Expand Down
8 changes: 0 additions & 8 deletions packages/neon/neon_dashboard/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:neon_dashboard/src/blocs/dashboard.dart';
import 'package:neon_dashboard/src/options.dart';
import 'package:neon_dashboard/src/pages/main.dart';
import 'package:neon_dashboard/src/routes.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';

/// Implementation of the server `dashboard` app.
Expand Down Expand Up @@ -34,11 +33,4 @@ class DashboardApp extends AppImplementation<DashboardBloc, DashboardAppSpecific

@override
final RouteBase route = $dashboardAppRoute;

@override
(bool?, String?) isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
const (null, null);
}
7 changes: 0 additions & 7 deletions packages/neon/neon_files/lib/neon_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,4 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {

@override
final RouteBase route = $filesAppRoute;

@override
(bool? supported, String? minimumVersion) isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
const (null, null);
}
4 changes: 2 additions & 2 deletions packages/neon/neon_files/lib/sort/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ final filesSortBox = SortBox<FilesSortProperty, WebDavFile>(
},
{
FilesSortProperty.modifiedDate: {
(FilesSortProperty.name, SortBoxOrder.ascending),
(property: FilesSortProperty.name, order: SortBoxOrder.ascending),
},
FilesSortProperty.size: {
(FilesSortProperty.name, SortBoxOrder.ascending),
(property: FilesSortProperty.name, order: SortBoxOrder.ascending),
},
},
);
2 changes: 1 addition & 1 deletion packages/neon/neon_files/lib/widgets/browser_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
sortProperty: widget.bloc.options.filesSortPropertyOption,
sortBoxOrder: widget.bloc.options.filesSortBoxOrderOption,
presort: const {
(FilesSortProperty.isFolder, SortBoxOrder.ascending),
(property: FilesSortProperty.isFolder, order: SortBoxOrder.ascending),
},
input: files,
builder: (final context, final sorted) {
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_news/lib/neon_news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
BehaviorSubject<int> getUnreadCounter(final NewsBloc bloc) => bloc.unreadCounter;

@override
Future<(bool? supported, String? minimumVersion)> isSupported(
Future<VersionSupported<String>> isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_news/lib/sort/articles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ final articlesSortBox = SortBox<ArticlesSortProperty, news.Article>(
},
{
ArticlesSortProperty.alphabetical: {
(ArticlesSortProperty.publishDate, SortBoxOrder.descending),
(property: ArticlesSortProperty.publishDate, order: SortBoxOrder.descending),
},
ArticlesSortProperty.byFeed: {
(ArticlesSortProperty.alphabetical, SortBoxOrder.ascending),
(property: ArticlesSortProperty.alphabetical, order: SortBoxOrder.ascending),
},
},
);
4 changes: 2 additions & 2 deletions packages/neon/neon_news/lib/sort/feeds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ final feedsSortBox = SortBox<FeedsSortProperty, news.Feed>(
},
{
FeedsSortProperty.alphabetical: {
(FeedsSortProperty.unreadCount, SortBoxOrder.descending),
(property: FeedsSortProperty.unreadCount, order: SortBoxOrder.descending),
},
FeedsSortProperty.unreadCount: {
(FeedsSortProperty.alphabetical, SortBoxOrder.ascending),
(property: FeedsSortProperty.alphabetical, order: SortBoxOrder.ascending),
},
},
);
10 changes: 5 additions & 5 deletions packages/neon/neon_news/lib/sort/folders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ part of '../neon_news.dart';

final foldersSortBox = SortBox<FoldersSortProperty, FolderFeedsWrapper>(
{
FoldersSortProperty.alphabetical: (final folderFeedsWrapper) => folderFeedsWrapper.$1.name.toLowerCase(),
FoldersSortProperty.unreadCount: (final folderFeedsWrapper) => folderFeedsWrapper.$3,
FoldersSortProperty.alphabetical: (final folderFeedsWrapper) => folderFeedsWrapper.folder.name.toLowerCase(),
FoldersSortProperty.unreadCount: (final folderFeedsWrapper) => folderFeedsWrapper.unreadCount,
},
{
FoldersSortProperty.alphabetical: {
(FoldersSortProperty.unreadCount, SortBoxOrder.descending),
(property: FoldersSortProperty.unreadCount, order: SortBoxOrder.descending),
},
FoldersSortProperty.unreadCount: {
(FoldersSortProperty.alphabetical, SortBoxOrder.ascending),
(property: FoldersSortProperty.alphabetical, order: SortBoxOrder.ascending),
},
},
);

typedef FolderFeedsWrapper = (news.Folder folder, int feedCount, int unreadCount);
typedef FolderFeedsWrapper = ({news.Folder folder, int feedCount, int unreadCount});
4 changes: 2 additions & 2 deletions packages/neon/neon_news/lib/widgets/folders_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NewsFoldersView extends StatelessWidget {
final feedCount = feedsInFolder.length;
final unreadCount = feedsInFolder.fold(0, (final a, final b) => a + b.unreadCount!);

return (folder, feedCount, unreadCount);
return (folder: folder, feedCount: feedCount, unreadCount: unreadCount);
}).toList()
: null,
builder: (final context, final sorted) => NeonListView(
Expand All @@ -45,7 +45,7 @@ class NewsFoldersView extends StatelessWidget {
final BuildContext context,
final FolderFeedsWrapper folderFeedsWrapper,
) {
final (folder, feedCount, unreadCount) = folderFeedsWrapper;
final (folder: folder, feedCount: feedCount, unreadCount: unreadCount) = folderFeedsWrapper;
return ListTile(
title: Text(
folder.name,
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_notes/lib/neon_notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
final RouteBase route = $notesAppRoute;

@override
(bool? supported, String? minimumVersion) isSupported(
VersionSupported<String> isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) {
final (supported, minimumVersion) = account.client.notes.isSupported(capabilities);
return (supported, minimumVersion.toString());
final result = account.client.notes.isSupported(capabilities);
return (isSupported: result.isSupported, minimumVersion: result.minimumVersion.toString());
}
}
2 changes: 1 addition & 1 deletion packages/neon/neon_notes/lib/sort/categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final categoriesSortBox = SortBox<CategoriesSortProperty, NoteCategory>(
},
{
CategoriesSortProperty.notesCount: {
(CategoriesSortProperty.alphabetical, SortBoxOrder.ascending),
(property: CategoriesSortProperty.alphabetical, order: SortBoxOrder.ascending),
},
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_notes/lib/sort/notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ final notesSortBox = SortBox<NotesSortProperty, notes.Note>(
},
{
NotesSortProperty.alphabetical: {
(NotesSortProperty.lastModified, SortBoxOrder.descending),
(property: NotesSortProperty.lastModified, order: SortBoxOrder.descending),
},
NotesSortProperty.lastModified: {
(NotesSortProperty.alphabetical, SortBoxOrder.ascending),
(property: NotesSortProperty.alphabetical, order: SortBoxOrder.ascending),
},
},
);
2 changes: 1 addition & 1 deletion packages/neon/neon_notes/lib/widgets/notes_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NotesView extends StatelessWidget {
builder: (final context, final notesList) => SortBoxBuilder<NotesSortProperty, notes.Note>(
sortBox: notesSortBox,
presort: const {
(NotesSortProperty.favorite, SortBoxOrder.ascending),
(property: NotesSortProperty.favorite, order: SortBoxOrder.ascending),
},
sortProperty: bloc.options.notesSortPropertyOption,
sortBoxOrder: bloc.options.notesSortBoxOrderOption,
Expand Down
8 changes: 0 additions & 8 deletions packages/neon/neon_notifications/lib/neon_notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:neon/utils.dart';
import 'package:neon/widgets.dart';
import 'package:neon_notifications/l10n/localizations.dart';
import 'package:neon_notifications/routes.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:rxdart/rxdart.dart';
Expand Down Expand Up @@ -54,11 +53,4 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification

@override
BehaviorSubject<int> getUnreadCounter(final NotificationsBloc bloc) => bloc.unreadCounter;

@override
(bool? supported, String? minimumVersion) isSupported(
final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
const (null, null);
}
1 change: 1 addition & 0 deletions packages/nextcloud/lib/nextcloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export 'package:dynamite_runtime/models.dart';

export 'ids.dart';
export 'src/client.dart';
export 'src/helpers/common.dart';
export 'webdav.dart';
2 changes: 2 additions & 0 deletions packages/nextcloud/lib/src/helpers/common.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// The result of a version check.
typedef VersionSupported<T> = ({bool isSupported, T minimumVersion});
10 changes: 7 additions & 3 deletions packages/nextcloud/lib/src/helpers/core.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: public_member_api_docs

import 'package:nextcloud/src/api/core.openapi.dart' as core;
import 'package:nextcloud/src/helpers/common.dart';

/// Version of core/Server supported
const supportedVersion = 27;
Expand All @@ -9,9 +10,12 @@ extension CoreVersionSupported on core.Client {
/// Check if the core/Server version is supported by this client
///
/// Also returns the supported version number
(bool, int) isSupported(final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => (
capabilities.version.major == supportedVersion,
supportedVersion,
VersionSupported<int> isSupported(
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
(
isSupported: capabilities.version.major == supportedVersion,
minimumVersion: supportedVersion,
);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/nextcloud/lib/src/helpers/news.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: public_member_api_docs

import 'package:nextcloud/src/api/news.openapi.dart' as news;
import 'package:nextcloud/src/helpers/common.dart';

/// API version of the news app supported
const supportedVersion = 'v1-3';
Expand All @@ -9,11 +10,11 @@ extension NewsVersionSupported on news.Client {
/// Check if the news app version is supported by this client
///
/// Also returns the supported API version number
Future<(bool, String)> isSupported() async {
Future<VersionSupported<String>> isSupported() async {
final response = await getSupportedApiVersions();
return (
response.body.apiLevels!.contains(supportedVersion),
supportedVersion,
isSupported: response.body.apiLevels!.contains(supportedVersion),
minimumVersion: supportedVersion,
);
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/nextcloud/lib/src/helpers/notes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:nextcloud/src/api/core.openapi.dart' as core;
import 'package:nextcloud/src/api/notes.openapi.dart' as notes;
import 'package:nextcloud/src/helpers/common.dart';
import 'package:version/version.dart';

/// API version of the notes app supported
Expand All @@ -11,11 +12,14 @@ extension NotesVersionSupported on notes.Client {
/// Check if the notes app version is supported by this client
///
/// Also returns the supported API version number
(bool, int) isSupported(final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => (
capabilities.capabilities.notesCapabilities?.notes.apiVersion
VersionSupported<int> isSupported(
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
(
isSupported: capabilities.capabilities.notesCapabilities?.notes.apiVersion
?.map(Version.parse)
.firstWhereOrNull((final version) => version.major == supportedVersion) !=
null,
supportedVersion,
minimumVersion: supportedVersion,
);
}
4 changes: 2 additions & 2 deletions packages/nextcloud/test/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void main() {
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

final (supported, _) = client.core.isSupported(response.body.ocs.data);
expect(supported, isTrue);
final result = client.core.isSupported(response.body.ocs.data);
expect(result.isSupported, isTrue);
});

test('Is supported from status', () async {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextcloud/test/news_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void main() {
);

test('Is supported', () async {
final (supported, _) = await client.news.isSupported();
expect(supported, isTrue);
final result = await client.news.isSupported();
expect(result.isSupported, isTrue);
});

test('Add feed', () async {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextcloud/test/notes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void main() {
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

final (supported, _) = client.notes.isSupported(response.body.ocs.data);
expect(supported, isTrue);
final result = client.notes.isSupported(response.body.ocs.data);
expect(result.isSupported, isTrue);
});

test('Create note favorite', () async {
Expand Down
Loading