TF-3416 Implement parse email by blob id interactor

This commit is contained in:
dab246
2025-01-10 16:36:26 +07:00
committed by Dat H. Pham
parent ebbca0ee20
commit 7cbdfddb6d
26 changed files with 227 additions and 33 deletions
@@ -1,3 +1,5 @@
import 'package:jmap_dart_client/jmap/core/id.dart';
class NotFoundEmailException implements Exception {}
class NotFoundEmailContentException implements Exception {}
@@ -8,4 +10,16 @@ class NotFoundEmailRecoveryActionException implements Exception {}
class NotFoundEmailBlobIdException implements Exception {}
class CannotCreateEmailObjectException implements Exception {}
class CannotCreateEmailObjectException implements Exception {}
class NotFoundBlobIdException implements Exception {
final List<Id> ids;
NotFoundBlobIdException(this.ids);
}
class NotParsableBlobIdToEmailException implements Exception {
final List<Id>? ids;
NotParsableBlobIdToEmailException({this.ids});
}
@@ -179,4 +179,6 @@ abstract class EmailRepository {
AccountId accountId,
EmailId emailId,
EventActionType eventActionType);
Future<List<Email>> parseEmailByBlobIds(AccountId accountId, Set<Id> blobIds);
}
@@ -0,0 +1,19 @@
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 ParsingEmailByBlobId extends LoadingState {}
class ParseEmailByBlobIdSuccess extends UIState {
final Email email;
ParseEmailByBlobIdSuccess(this.email);
@override
List<Object> get props => [email];
}
class ParseEmailByBlobIdFailure extends FeatureFailure {
ParseEmailByBlobIdFailure(dynamic exception) : super(exception: exception);
}
@@ -0,0 +1,28 @@
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/id.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/parse_email_by_blob_id_state.dart';
class ParseEmailByBlobIdInteractor {
final EmailRepository _emailRepository;
const ParseEmailByBlobIdInteractor(this._emailRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, Id blobId) async* {
try {
yield Right<Failure, Success>(ParsingEmailByBlobId());
final emailParsed = await _emailRepository.parseEmailByBlobIds(
accountId,
{blobId},
);
yield Right<Failure, Success>(ParseEmailByBlobIdSuccess(emailParsed.first));
} catch (e) {
yield Left<Failure, Success>(ParseEmailByBlobIdFailure(e));
}
}
}