diff --git a/lib/features/push_notification/domain/exceptions/fcm_exception.dart b/lib/features/push_notification/domain/exceptions/fcm_exception.dart index 0ec2be971..d352558b3 100644 --- a/lib/features/push_notification/domain/exceptions/fcm_exception.dart +++ b/lib/features/push_notification/domain/exceptions/fcm_exception.dart @@ -8,4 +8,6 @@ class NotFoundEmailDeliveryStateException implements Exception {} class NotFoundFirebaseSubscriptionException implements Exception {} -class NotFoundSubscriptionException implements Exception {} \ No newline at end of file +class NotFoundSubscriptionException implements Exception {} + +class NotFoundEmailStateException 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 dbe7e8e90..14dec7177 100644 --- a/lib/features/push_notification/domain/repository/fcm_repository.dart +++ b/lib/features/push_notification/domain/repository/fcm_repository.dart @@ -3,6 +3,7 @@ import 'package:fcm/model/type_name.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; +import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:model/mailbox/presentation_mailbox.dart'; import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart'; import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart'; @@ -37,4 +38,14 @@ abstract class FCMRepository { Future destroySubscription(String subscriptionId); Future> getMailboxesNotPutNotifications(Session session, AccountId accountId); + + Future> getEmailChangesToRemoveNotification( + Session session, + AccountId accountId, + jmap.State currentState, + { + Properties? propertiesCreated, + Properties? propertiesUpdated + } + ); } \ No newline at end of file diff --git a/lib/features/push_notification/domain/state/get_email_changes_to_remove_notification_state.dart b/lib/features/push_notification/domain/state/get_email_changes_to_remove_notification_state.dart new file mode 100644 index 000000000..92cae03ef --- /dev/null +++ b/lib/features/push_notification/domain/state/get_email_changes_to_remove_notification_state.dart @@ -0,0 +1,24 @@ + +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:jmap_dart_client/jmap/mail/email/email.dart'; + +class GetEmailChangesToRemoveNotificationLoading extends UIState {} + +class GetEmailChangesToRemoveNotificationSuccess extends UIState { + + final List emailIds; + + GetEmailChangesToRemoveNotificationSuccess(this.emailIds); + + @override + List get props => [emailIds]; +} + +class GetEmailChangesToRemoveNotificationFailure extends FeatureFailure { + + GetEmailChangesToRemoveNotificationFailure(exception) : super(exception: exception); + + @override + List get props => [exception]; +} \ No newline at end of file diff --git a/lib/features/push_notification/domain/usecases/get_email_changes_to_remove_notification_interactor.dart b/lib/features/push_notification/domain/usecases/get_email_changes_to_remove_notification_interactor.dart new file mode 100644 index 000000000..1ed2e3cd6 --- /dev/null +++ b/lib/features/push_notification/domain/usecases/get_email_changes_to_remove_notification_interactor.dart @@ -0,0 +1,49 @@ +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:core/utils/app_logger.dart'; +import 'package:dartz/dartz.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; +import 'package:jmap_dart_client/jmap/core/session/session.dart'; +import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; +import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.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_email_changes_to_remove_notification_state.dart'; + +class GetEmailChangesToRemoveNotificationInteractor { + final FCMRepository _fcmRepository; + final EmailRepository _emailRepository; + + GetEmailChangesToRemoveNotificationInteractor(this._fcmRepository, this._emailRepository); + + Stream> execute( + Session session, + AccountId accountId, + jmap.State newState, + { + Properties? propertiesCreated, + Properties? propertiesUpdated + } + ) async* { + try { + yield Right(GetEmailChangesToRemoveNotificationLoading()); + + final currentState = await _emailRepository.getEmailState(); + log('GetEmailChangesToRemoveNotificationInteractor::execute():currentState: $currentState'); + if (currentState != null) { + final emailIds = await _fcmRepository.getEmailChangesToRemoveNotification( + session, + accountId, + currentState, + propertiesCreated: propertiesCreated, + propertiesUpdated: propertiesUpdated); + yield Right(GetEmailChangesToRemoveNotificationSuccess(emailIds)); + } else { + yield Left(GetEmailChangesToRemoveNotificationFailure(NotFoundEmailStateException())); + } + } catch (e) { + yield Left(GetEmailChangesToRemoveNotificationFailure(e)); + } + } +} \ No newline at end of file