Skip to content

Commit

Permalink
feat(neon): Adjust to generated specs
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin committed Jul 15, 2023
1 parent 956d566 commit 03e1497
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 79 deletions.
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart';
Expand All @@ -22,6 +21,7 @@ import 'package:neon/src/utils/global.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:neon/src/utils/localizations.dart';
import 'package:neon/src/utils/push_utils.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:tray_manager/tray_manager.dart' as tray;
Expand Down Expand Up @@ -285,7 +285,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
stream: _accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
FlutterNativeSplash.remove();
return ResultBuilder<Capabilities?>.behaviorSubject(
return ResultBuilder<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data?>.behaviorSubject(
stream: activeAccountSnapshot.hasData
? _accountsBloc.getCapabilitiesBlocFor(activeAccountSnapshot.data!).capabilities
: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/blocs/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState

unawaited(() async {
try {
await account.client.core.deleteAppPassword();
await account.client.core.appPassword.deleteAppPassword();
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
Expand Down
11 changes: 5 additions & 6 deletions packages/neon/neon/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';

typedef NextcloudApp = CoreNavigationApps_Ocs_Data;

abstract class AppsBlocEvents {
void setActiveApp(final String appID);
}

abstract class AppsBlocStates {
BehaviorSubject<Result<List<NextcloudApp>>> get apps;
BehaviorSubject<Result<List<CoreNavigationEntry>>> get apps;

BehaviorSubject<Result<Iterable<AppImplementation>>> get appImplementations;

Expand Down Expand Up @@ -181,7 +179,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<Result<Iterable<AppImplementation>>>();

@override
BehaviorSubject<Result<List<NextcloudApp>>> apps = BehaviorSubject<Result<List<NextcloudApp>>>();
BehaviorSubject<Result<List<CoreNavigationEntry>>> apps = BehaviorSubject<Result<List<CoreNavigationEntry>>>();

@override
BehaviorSubject<Result<NotificationsAppInterface?>> notificationsAppImplementation =
Expand All @@ -195,11 +193,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates

@override
Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>(
await _requestManager
.wrapNextcloud<List<CoreNavigationEntry>, CoreNavigationGetAppsNavigationResponse200ApplicationJson>(
_account.client.id,
'apps-apps',
apps,
() async => _account.client.core.getNavigationApps(),
() async => _account.client.core.navigation.getAppsNavigation(),
(final response) => response.ocs.data.toList(),
);
}
Expand Down
13 changes: 6 additions & 7 deletions packages/neon/neon/lib/src/blocs/capabilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import 'package:neon/src/utils/request_manager.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:rxdart/rxdart.dart';

typedef Capabilities = CoreServerCapabilities_Ocs_Data;
typedef NextcloudTheme = CoreServerCapabilities_Ocs_Data_Capabilities_Theming;

abstract class CapabilitiesBlocEvents {}

abstract class CapabilitiesBlocStates {
BehaviorSubject<Result<Capabilities>> get capabilities;
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>> get capabilities;
}

@internal
Expand All @@ -36,15 +33,17 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
}

@override
BehaviorSubject<Result<Capabilities>> capabilities = BehaviorSubject<Result<Capabilities>>();
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>> capabilities =
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>>();

@override
Future refresh() async {
await _requestManager.wrapNextcloud<CoreServerCapabilities_Ocs_Data, CoreServerCapabilities>(
await _requestManager.wrapNextcloud<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data,
CoreOcsGetCapabilitiesResponse200ApplicationJson>(
_client.id,
'capabilities',
capabilities,
() async => _client.core.getCapabilities(),
() async => _client.core.ocs.getCapabilities(),
(final response) => response.ocs.data,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/blocs/login_check_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LoginCheckAccountBloc extends InteractiveBloc
userAgentOverride: neonUserAgent,
);

final response = await client.provisioningApi.getCurrentUser();
final response = await client.provisioningApi.users.getCurrentUser();

final account = Account(
serverURL: serverURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract interface class LoginCheckServerStatusBlocEvents {}

abstract interface class LoginCheckServerStatusBlocStates {
/// Contains the current server connection state
BehaviorSubject<Result<CoreServerStatus>> get state;
BehaviorSubject<Result<CoreStatus>> get state;
}

class LoginCheckServerStatusBloc extends InteractiveBloc
Expand All @@ -28,7 +28,7 @@ class LoginCheckServerStatusBloc extends InteractiveBloc
}

@override
BehaviorSubject<Result<CoreServerStatus>> state = BehaviorSubject();
BehaviorSubject<Result<CoreStatus>> state = BehaviorSubject();

@override
Future refresh() async {
Expand Down
14 changes: 7 additions & 7 deletions packages/neon/neon/lib/src/blocs/login_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'package:rxdart/rxdart.dart';
abstract class LoginFlowBlocEvents {}

abstract class LoginFlowBlocStates {
BehaviorSubject<Result<CoreLoginFlowInit>> get init;
BehaviorSubject<Result<CoreLoginFlowV2>> get init;

Stream<CoreLoginFlowResult> get result;
Stream<CoreLoginFlowV2Credentials> get result;
}

class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, LoginFlowBlocStates {
Expand All @@ -25,7 +25,7 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
serverURL,
userAgentOverride: neonUserAgent,
);
final _resultController = StreamController<CoreLoginFlowResult>();
final _resultController = StreamController<CoreLoginFlowV2Credentials>();

Timer? _pollTimer;

Expand All @@ -37,23 +37,23 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
}

@override
BehaviorSubject<Result<CoreLoginFlowInit>> init = BehaviorSubject<Result<CoreLoginFlowInit>>();
BehaviorSubject<Result<CoreLoginFlowV2>> init = BehaviorSubject<Result<CoreLoginFlowV2>>();

@override
late Stream<CoreLoginFlowResult> result = _resultController.stream.asBroadcastStream();
late Stream<CoreLoginFlowV2Credentials> result = _resultController.stream.asBroadcastStream();

@override
Future refresh() async {
try {
init.add(Result.loading());

final initResponse = await _client.core.initLoginFlow();
final initResponse = await _client.core.clientFlowLoginV2.init();
init.add(Result.success(initResponse));

_cancelPollTimer();
_pollTimer = Timer.periodic(const Duration(seconds: 1), (final _) async {
try {
final resultResponse = await _client.core.getLoginFlowResult(token: initResponse.poll.token);
final resultResponse = await _client.core.clientFlowLoginV2.poll(token: initResponse.poll.token);
_cancelPollTimer();
_resultController.add(resultResponse);
} catch (e, s) {
Expand Down
5 changes: 3 additions & 2 deletions packages/neon/neon/lib/src/blocs/user_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,

@override
Future refresh() async {
await _requestManager.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>(
await _requestManager
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponse200ApplicationJson>(
_client.id,
'user-details',
userDetails,
() async => _client.provisioningApi.getCurrentUser(),
() async => _client.provisioningApi.users.getCurrentUser(),
(final response) => response.ocs.data,
);
}
Expand Down
23 changes: 11 additions & 12 deletions packages/neon/neon/lib/src/blocs/user_statuses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class UserStatusesBlocEvents {
}

abstract class UserStatusesBlocStates {
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>> get statuses;
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> get statuses;
}

@internal
Expand All @@ -41,8 +41,8 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}

@override
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>>();
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublic?>>>();

@override
Future refresh() async {
Expand All @@ -60,17 +60,17 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
try {
_updateStatus(username, Result.loading());

UserStatusPublicStatus? data;
UserStatusPublic? data;
if (_account.username == username) {
final isAway =
_platform.canUseWindowManager && (!(await windowManager.isFocused()) || !(await windowManager.isVisible()));
final response = await _account.client.userStatus.heartbeat(
status: isAway ? UserStatusType.away : UserStatusType.online,
final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online',
);
data = response.ocs.data.status?.publicStatus;
data = response.ocs.data.public;
} else {
final response = await _account.client.userStatus.getPublicStatus(userId: username);
data = response.ocs.data.publicStatus;
final response = await _account.client.userStatus.statuses.find(userId: username);
data = response.ocs.data;
}

_updateStatus(username, Result.success(data));
Expand All @@ -85,10 +85,9 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}
}

Map<String, Result<UserStatusPublicStatus?>> get _statuses =>
statuses.valueOrNull ?? <String, Result<UserStatusPublicStatus?>>{};
Map<String, Result<UserStatusPublic?>> get _statuses => statuses.valueOrNull ?? <String, Result<UserStatusPublic?>>{};

void _updateStatus(final String username, final Result<UserStatusPublicStatus?> result) {
void _updateStatus(final String username, final Result<UserStatusPublic?> result) {
statuses.add({
..._statuses,
username: result,
Expand Down
1 change: 1 addition & 0 deletions packages/neon/neon/lib/src/models/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Account implements Credentials {
);

factory Account.fromJson(final Map<String, dynamic> json) => _$AccountFromJson(json);

Map<String, dynamic> toJson() => _$AccountToJson(this);

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/models/push_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class PushNotification {

final String type;

final NotificationsNotificationDecryptedSubject subject;
final NotificationsDecryptedSubject subject;
}
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/models/push_notification.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/neon/neon/lib/src/pages/account_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ class AccountSettingsPage extends StatelessWidget {
children: [
if (userDetails.hasData) ...[
LinearProgressIndicator(
value: userDetails.requireData.quota.relative / 100,
value: (userDetails.requireData.quota.relative ?? 0) / 100,
backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3),
),
const SizedBox(
height: 10,
),
Text(
AppLocalizations.of(context).accountOptionsQuotaUsedOf(
filesize(userDetails.requireData.quota.used, 1),
filesize(userDetails.requireData.quota.total, 1),
userDetails.requireData.quota.relative.toString(),
filesize(userDetails.requireData.quota.used ?? 0, 1),
filesize(userDetails.requireData.quota.total ?? 0, 1),
(userDetails.requireData.quota.relative ?? 0).toString(),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
}
}

Widget _buildServerVersionTile(final Result<CoreServerStatus> result) {
Widget _buildServerVersionTile(final Result<CoreStatus> result) {
if (!result.hasData) {
return NeonValidationTile(
title: AppLocalizations.of(context).loginCheckingServerVersion,
Expand All @@ -122,7 +122,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
);
}

Widget _buildMaintenanceModeTile(final Result<CoreServerStatus> result) {
Widget _buildMaintenanceModeTile(final Result<CoreStatus> result) {
if (!result.hasData) {
return NeonValidationTile(
title: AppLocalizations.of(context).loginCheckingMaintenanceMode,
Expand Down
12 changes: 6 additions & 6 deletions packages/neon/neon/lib/src/theme/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ abstract final class NcColors {
static const Color accept = Colors.green;
}

/// [UserStatusType] color mapping.
extension UserStatusTypeColors on UserStatusType {
/// [UserStatusPublic] status color mapping.
extension UserStatusTypeColors on UserStatusPublic {
/// The color for the user status.
Color? get color => switch (this) {
UserStatusType.online => const Color(0xFF49B382),
UserStatusType.away => const Color(0xFFF4A331),
UserStatusType.dnd => const Color(0xFFED484C),
Color? get color => switch (status) {
'online' => const Color(0xFF49B382),
'away' => const Color(0xFFF4A331),
'dnd' => const Color(0xFFED484C),
_ => null,
};
}
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class AppTheme {
this.appThemes,
}) : keepOriginalAccentColor = nextcloudTheme == null || keepOriginalAccentColor;

final CoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme;
final CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data_Capabilities_Theming? nextcloudTheme;
final bool keepOriginalAccentColor;
final bool oledAsDark;
final Iterable<ThemeExtension>? appThemes;
final NeonTheme neonTheme;

ColorScheme _buildColorScheme(final Brightness brightness) {
final primary = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : neonTheme.colorScheme.primary;
final primary = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color) : neonTheme.colorScheme.primary;
final keepOriginalAccentColorOverride = keepOriginalAccentColor ? primary : null;
final oledBackgroundOverride = oledAsDark && brightness == Brightness.dark ? NcColors.oledBackground : null;

Expand Down
Loading

0 comments on commit 03e1497

Please sign in to comment.