AppFlowy/frontend/appflowy_flutter/lib/user/application/user_settings_service.dart

61 lines
1.9 KiB
Dart
Raw Normal View History

2022-01-28 18:34:21 +08:00
import 'package:dartz/dartz.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/appflowy_backend.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart';
2022-01-28 18:34:21 +08:00
class UserSettingsBackendService {
Future<AppearanceSettingsPB> getAppearanceSetting() async {
2022-01-28 18:34:21 +08:00
final result = await UserEventGetAppearanceSetting().send();
return result.fold(
2023-10-02 09:12:24 +02:00
(AppearanceSettingsPB setting) => setting,
(error) =>
throw FlowySDKException(ExceptionType.AppearanceSettingsIsEmpty),
2022-01-28 18:34:21 +08:00
);
}
2022-11-11 17:24:10 +08:00
Future<Either<UserSettingPB, FlowyError>> getUserSetting() {
return UserEventGetUserSetting().send();
}
Future<Either<Unit, FlowyError>> setAppearanceSetting(
AppearanceSettingsPB setting,
) {
return UserEventSetAppearanceSetting(setting).send();
2022-01-28 18:34:21 +08:00
}
2023-10-02 09:12:24 +02:00
Future<DateTimeSettingsPB> getDateTimeSettings() async {
final result = await UserEventGetDateTimeSettings().send();
return result.fold(
(DateTimeSettingsPB setting) => setting,
(error) =>
throw FlowySDKException(ExceptionType.AppearanceSettingsIsEmpty),
);
}
Future<Either<FlowyError, Unit>> setDateTimeSettings(
DateTimeSettingsPB settings,
) async {
return (await UserEventSetDateTimeSettings(settings).send()).swap();
}
Future<Either<FlowyError, Unit>> setNotificationSettings(
NotificationSettingsPB settings,
) async {
return (await UserEventSetNotificationSettings(settings).send()).swap();
}
Future<NotificationSettingsPB> getNotificationSettings() async {
final result = await UserEventGetNotificationSettings().send();
return result.fold(
(NotificationSettingsPB setting) => setting,
(error) =>
throw FlowySDKException(ExceptionType.AppearanceSettingsIsEmpty),
);
}
2022-01-28 18:34:21 +08:00
}