TF-1599 Implement GetEmailChanges to remove notification
(cherry picked from commit 9a41ea84a40c97091b4c4c5d2e0c19afcafc712f)
This commit is contained in:
@@ -9,3 +9,5 @@ class NotFoundEmailDeliveryStateException implements Exception {}
|
|||||||
class NotFoundFirebaseSubscriptionException implements Exception {}
|
class NotFoundFirebaseSubscriptionException implements Exception {}
|
||||||
|
|
||||||
class NotFoundSubscriptionException implements Exception {}
|
class NotFoundSubscriptionException implements Exception {}
|
||||||
|
|
||||||
|
class NotFoundEmailStateException implements Exception {}
|
||||||
@@ -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/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/properties/properties.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/session/session.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
import 'package:model/mailbox/presentation_mailbox.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/fcm_subscription.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||||
@@ -37,4 +38,14 @@ abstract class FCMRepository {
|
|||||||
Future<bool> destroySubscription(String subscriptionId);
|
Future<bool> destroySubscription(String subscriptionId);
|
||||||
|
|
||||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId);
|
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId);
|
||||||
|
|
||||||
|
Future<List<EmailId>> getEmailChangesToRemoveNotification(
|
||||||
|
Session session,
|
||||||
|
AccountId accountId,
|
||||||
|
jmap.State currentState,
|
||||||
|
{
|
||||||
|
Properties? propertiesCreated,
|
||||||
|
Properties? propertiesUpdated
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+24
@@ -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<EmailId> emailIds;
|
||||||
|
|
||||||
|
GetEmailChangesToRemoveNotificationSuccess(this.emailIds);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [emailIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetEmailChangesToRemoveNotificationFailure extends FeatureFailure {
|
||||||
|
|
||||||
|
GetEmailChangesToRemoveNotificationFailure(exception) : super(exception: exception);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [exception];
|
||||||
|
}
|
||||||
+49
@@ -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<Either<Failure, Success>> execute(
|
||||||
|
Session session,
|
||||||
|
AccountId accountId,
|
||||||
|
jmap.State newState,
|
||||||
|
{
|
||||||
|
Properties? propertiesCreated,
|
||||||
|
Properties? propertiesUpdated
|
||||||
|
}
|
||||||
|
) async* {
|
||||||
|
try {
|
||||||
|
yield Right<Failure, Success>(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<Failure, Success>(GetEmailChangesToRemoveNotificationSuccess(emailIds));
|
||||||
|
} else {
|
||||||
|
yield Left<Failure, Success>(GetEmailChangesToRemoveNotificationFailure(NotFoundEmailStateException()));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
yield Left<Failure, Success>(GetEmailChangesToRemoveNotificationFailure(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user