diff --git a/lib/features/push_notification/domain/exceptions/fcm_exception.dart b/lib/features/push_notification/domain/exceptions/fcm_exception.dart index 499ec4d5d..0ec2be971 100644 --- a/lib/features/push_notification/domain/exceptions/fcm_exception.dart +++ b/lib/features/push_notification/domain/exceptions/fcm_exception.dart @@ -8,4 +8,4 @@ class NotFoundEmailDeliveryStateException implements Exception {} class NotFoundFirebaseSubscriptionException implements Exception {} -class NotFoundDeviceIdException implements Exception {} \ No newline at end of file +class NotFoundSubscriptionException implements Exception {} \ No newline at end of file diff --git a/lib/features/push_notification/domain/repository/fcm_repository.dart b/lib/features/push_notification/domain/repository/fcm_repository.dart index 1f9805629..266ad23ab 100644 --- a/lib/features/push_notification/domain/repository/fcm_repository.dart +++ b/lib/features/push_notification/domain/repository/fcm_repository.dart @@ -28,4 +28,6 @@ abstract class FCMRepository { Future getFirebaseSubscriptionByDeviceId(String deviceId); Future registerNewToken(RegisterNewTokenRequest newTokenRequest); + + Future getSubscription(); } \ No newline at end of file diff --git a/lib/features/push_notification/domain/state/get_fcm_subscription_local.dart b/lib/features/push_notification/domain/state/get_fcm_subscription_local.dart new file mode 100644 index 000000000..1b274b1bd --- /dev/null +++ b/lib/features/push_notification/domain/state/get_fcm_subscription_local.dart @@ -0,0 +1,25 @@ + +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart'; + +class GetFCMSubscriptionLocalLoading extends UIState {} + +class GetFCMSubscriptionLocalSuccess extends UIState { + + final FCMSubscription fcmSubscription; + + GetFCMSubscriptionLocalSuccess(this.fcmSubscription); + + @override + List get props => [fcmSubscription]; +} + +class GetFCMSubscriptionLocalFailure extends FeatureFailure { + final dynamic exception; + + GetFCMSubscriptionLocalFailure(this.exception); + + @override + List get props => [exception]; +} \ No newline at end of file diff --git a/lib/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart b/lib/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart new file mode 100644 index 000000000..e045f7ced --- /dev/null +++ b/lib/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart @@ -0,0 +1,21 @@ +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:dartz/dartz.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/state/get_fcm_subscription_local.dart'; + +class GetFCMSubscriptionLocalInteractor { + final FCMRepository _fcmRepository; + + GetFCMSubscriptionLocalInteractor(this._fcmRepository); + + Stream> execute() async* { + try { + yield Right(GetFCMSubscriptionLocalLoading()); + final _subscription = await _fcmRepository.getSubscription(); + yield Right(GetFCMSubscriptionLocalSuccess(_subscription)); + } catch (e) { + yield Left(GetFCMSubscriptionLocalFailure(e)); + } + } +} \ No newline at end of file