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(neon_framework): Respect the configured apps order #2067

Merged
merged 1 commit into from
May 24, 2024
Merged
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
47 changes: 28 additions & 19 deletions packages/neon_framework/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,24 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
required this.allAppImplementations,
}) {
apps.listen((result) {
appImplementations.add(result.transform((data) => filteredAppImplementations(data.map((a) => a.id))));
appImplementations.add(
result.transform(
(data) {
final apps = SetBuilder<AppImplementation>();

for (final entry in data) {
for (final app in allAppImplementations) {
if (app.id == entry.id || (app.additionalMatchingIDs?.contains(entry.id) ?? false)) {
apps.add(app);
break;
}
}
}

return apps.build();
},
),
);

if (result.hasData) {
unawaited(updateApps());
Expand All @@ -85,7 +102,9 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
notificationsAppImplementation.add(
result.transform(
(data) => data.capabilities.notificationsCapabilities?.notifications != null
? findAppImplementation(AppIDs.notifications)
? allAppImplementations.firstWhereOrNull(
(a) => a.id == AppIDs.notifications,
) as NotificationsAppInterface?
: null,
),
);
Expand Down Expand Up @@ -207,22 +226,6 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
appVersionChecks.add(checks.build());
}

T? findAppImplementation<T extends AppImplementation>(String id) {
final matches = filteredAppImplementations([id]);
if (matches.isNotEmpty) {
return matches.single as T;
}

return null;
}

BuiltSet<AppImplementation> filteredAppImplementations(Iterable<String> appIds) => BuiltSet(
allAppImplementations.where(
(a) =>
appIds.contains(a.id) || a.additionalMatchingIDs?.firstWhereOrNull((id) => appIds.contains(id)) != null,
),
);

final BehaviorSubject<Result<core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data>> capabilitiesSubject;
final Account account;
final AccountOptions accountOptions;
Expand Down Expand Up @@ -268,7 +271,9 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
subject: apps,
getRequest: account.client.core.navigation.$getAppsNavigation_Request,
serializer: account.client.core.navigation.$getAppsNavigation_Serializer(),
unwrap: (response) => response.body.ocs.data,
unwrap: (response) => response.body.ocs.data.rebuild(
(b) => b..sort((a, b) => (a.getOrder()).compareTo(b.getOrder())),
),
);
}

Expand Down Expand Up @@ -301,3 +306,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
List<Provider<Bloc>> get appBlocProviders =>
allAppImplementations.map((appImplementation) => appImplementation.blocProvider).toList();
}

extension _NavigationEntryOrder on core.NavigationEntry {
int getOrder() => order.$int ?? int.parse(order.string!);
}