TF-1810 Add GetNewReceiveEmailFromNotificationInteractor to get new receive email from notification

(cherry picked from commit df7a84a932f8496d92e5eed8ccd66c0b8709ae61)
This commit is contained in:
dab246
2023-05-10 16:31:00 +07:00
committed by Dat Vu
parent 41ed9a230d
commit 7e0f338fa0
5 changed files with 110 additions and 1 deletions
@@ -10,4 +10,8 @@ class NotFoundFirebaseSubscriptionException implements Exception {}
class NotFoundSubscriptionException implements Exception {}
class NotFoundEmailStateException implements Exception {}
class NotFoundEmailStateException implements Exception {}
class NotFoundNewReceiveEmailException implements Exception {}
class EmailStateNoChangeException implements Exception {}
@@ -49,4 +49,6 @@ abstract class FCMRepository {
Properties? propertiesUpdated
}
);
Future<List<EmailId>> getNewReceiveEmailFromNotification(Session session, AccountId accountId, jmap.State currentState);
}
@@ -0,0 +1,28 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
class GetNewReceiveEmailFromNotificationLoading extends UIState {}
class GetNewReceiveEmailFromNotificationSuccess extends UIState {
final List<EmailId> emailIds;
final AccountId accountId;
final UserName userName;
GetNewReceiveEmailFromNotificationSuccess(this.accountId, this.userName, this.emailIds);
@override
List<Object> get props => [accountId, userName, emailIds];
}
class GetNewReceiveEmailFromNotificationFailure extends FeatureFailure {
GetNewReceiveEmailFromNotificationFailure(exception) : super(exception: exception);
@override
List<Object> get props => [exception];
}
@@ -0,0 +1,43 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/core/user_name.dart';
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_new_receive_email_from_notification_state.dart';
class GetNewReceiveEmailFromNotificationInteractor {
final FCMRepository _fcmRepository;
final EmailRepository _emailRepository;
GetNewReceiveEmailFromNotificationInteractor(this._fcmRepository, this._emailRepository);
Stream<Either<Failure, Success>> execute(
Session session,
AccountId accountId,
UserName userName,
jmap.State newState
) async* {
try {
yield Right<Failure, Success>(GetNewReceiveEmailFromNotificationLoading());
final currentState = await _emailRepository.getEmailState(session, accountId);
if (currentState != null && currentState != newState) {
final listEmailIds = await _fcmRepository.getNewReceiveEmailFromNotification(
session,
accountId,
currentState);
yield Right<Failure, Success>(GetNewReceiveEmailFromNotificationSuccess(accountId, userName, listEmailIds));
} else {
yield Left<Failure, Success>(GetNewReceiveEmailFromNotificationFailure(EmailStateNoChangeException()));
}
} catch (e) {
yield Left<Failure, Success>(GetNewReceiveEmailFromNotificationFailure(e));
}
}
}