2022-01-28 18:34:21 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
2023-01-08 12:10:53 +08:00
|
|
|
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
|
|
|
|
2023-02-26 16:27:17 +08:00
|
|
|
class UserSettingsBackendService {
|
2022-09-28 11:44:44 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:44:44 +08:00
|
|
|
Future<Either<Unit, FlowyError>> setAppearanceSetting(
|
2023-04-10 15:10:42 +08:00
|
|
|
AppearanceSettingsPB setting,
|
|
|
|
) {
|
2022-09-28 11:44:44 +08:00
|
|
|
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();
|
|
|
|
}
|
2023-10-12 06:54:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|