| 
									
										
										
										
											2023-01-08 12:10:53 +08:00
										 |  |  | import 'package:appflowy_backend/appflowy_backend.dart'; | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  | import 'package:appflowy_backend/dispatch/dispatch.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-08 12:10:53 +08:00
										 |  |  | 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'; | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  | import 'package:appflowy_result/appflowy_result.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
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |   Future<FlowyResult<UserSettingPB, FlowyError>> getUserSetting() { | 
					
						
							| 
									
										
										
										
											2022-11-11 17:24:10 +08:00
										 |  |  |     return UserEventGetUserSetting().send(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |   Future<FlowyResult<void, 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), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |   Future<FlowyResult<void, FlowyError>> setDateTimeSettings( | 
					
						
							| 
									
										
										
										
											2023-10-02 09:12:24 +02:00
										 |  |  |     DateTimeSettingsPB settings, | 
					
						
							|  |  |  |   ) async { | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |     return UserEventSetDateTimeSettings(settings).send(); | 
					
						
							| 
									
										
										
										
											2023-10-02 09:12:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-12 06:54:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |   Future<FlowyResult<void, FlowyError>> setNotificationSettings( | 
					
						
							| 
									
										
										
										
											2023-10-12 06:54:08 +02:00
										 |  |  |     NotificationSettingsPB settings, | 
					
						
							|  |  |  |   ) async { | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |     return UserEventSetNotificationSettings(settings).send(); | 
					
						
							| 
									
										
										
										
											2023-10-12 06:54:08 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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
										 |  |  | } |