From 6fe62cb068a246760739931f60527508fc4fd780 Mon Sep 17 00:00:00 2001 From: DatDang Date: Tue, 27 Feb 2024 15:58:59 +0700 Subject: [PATCH] TF-2628 [Part-2] Add attachment property to DownloadAttachmentForWebFailure & ViewAttachmentForWebFailure --- .../domain/state/download_attachment_for_web_state.dart | 6 +++++- .../email/domain/state/view_attachment_for_web_state.dart | 6 +++++- .../usecases/download_attachment_for_web_interactor.dart | 1 + .../usecases/view_attachment_for_web_interactor.dart | 1 + .../presentation/controller/single_email_controller.dart | 8 ++++++-- .../usecases/view_attachment_for_web_interactor_test.dart | 2 ++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/features/email/domain/state/download_attachment_for_web_state.dart b/lib/features/email/domain/state/download_attachment_for_web_state.dart index 844ad20f4..616173d2b 100644 --- a/lib/features/email/domain/state/download_attachment_for_web_state.dart +++ b/lib/features/email/domain/state/download_attachment_for_web_state.dart @@ -1,6 +1,7 @@ import 'dart:typed_data'; import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:model/download/download_task_id.dart'; import 'package:model/email/attachment.dart'; @@ -56,9 +57,12 @@ class DownloadAttachmentForWebSuccess extends UIState { class DownloadAttachmentForWebFailure extends FeatureFailure { final DownloadTaskId? taskId; + final Id? attachmentBlobId; DownloadAttachmentForWebFailure({ - this.taskId, dynamic exception + required this.attachmentBlobId, + this.taskId, + dynamic exception }) : super(exception: exception); @override diff --git a/lib/features/email/domain/state/view_attachment_for_web_state.dart b/lib/features/email/domain/state/view_attachment_for_web_state.dart index ea31ba3b9..bb2477415 100644 --- a/lib/features/email/domain/state/view_attachment_for_web_state.dart +++ b/lib/features/email/domain/state/view_attachment_for_web_state.dart @@ -19,5 +19,9 @@ class ViewAttachmentForWebSuccess extends DownloadAttachmentForWebSuccess { } class ViewAttachmentForWebFailure extends DownloadAttachmentForWebFailure { - ViewAttachmentForWebFailure({super.taskId, super.exception}); + ViewAttachmentForWebFailure({ + required super.attachmentBlobId, + super.taskId, + super.exception, + }); } diff --git a/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart b/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart index b560205b9..9e7b82088 100644 --- a/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart +++ b/lib/features/email/domain/usecases/download_attachment_for_web_interactor.dart @@ -72,6 +72,7 @@ class DownloadAttachmentForWebInteractor { } catch (exception) { yield Left( DownloadAttachmentForWebFailure( + attachmentBlobId: attachment.blobId, taskId: taskId, exception: exception ) diff --git a/lib/features/email/domain/usecases/view_attachment_for_web_interactor.dart b/lib/features/email/domain/usecases/view_attachment_for_web_interactor.dart index 3990d2cdb..f69ff81d8 100644 --- a/lib/features/email/domain/usecases/view_attachment_for_web_interactor.dart +++ b/lib/features/email/domain/usecases/view_attachment_for_web_interactor.dart @@ -34,6 +34,7 @@ class ViewAttachmentForWebInteractor { (failure) { if (failure is DownloadAttachmentForWebFailure) { return Left(ViewAttachmentForWebFailure( + attachmentBlobId: attachment.blobId, taskId: failure.taskId, exception: failure.exception, )); diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 39b1560c9..4fe02342e 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -744,7 +744,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin { _downloadProgressStateController)); } else { consumeState(Stream.value( - Left(DownloadAttachmentForWebFailure(exception: NotFoundSessionException())) + Left(DownloadAttachmentForWebFailure( + attachment: attachment, + exception: NotFoundSessionException())) )); } } @@ -763,7 +765,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin { _downloadProgressStateController)); } else { consumeState(Stream.value( - Left(ViewAttachmentForWebFailure(exception: NotFoundSessionException())) + Left(ViewAttachmentForWebFailure( + attachment: attachment, + exception: NotFoundSessionException())) )); } } diff --git a/test/features/email/domain/usecases/view_attachment_for_web_interactor_test.dart b/test/features/email/domain/usecases/view_attachment_for_web_interactor_test.dart index 1e82f618a..6b947149c 100644 --- a/test/features/email/domain/usecases/view_attachment_for_web_interactor_test.dart +++ b/test/features/email/domain/usecases/view_attachment_for_web_interactor_test.dart @@ -55,6 +55,7 @@ void main() { (_) => Stream.value( Left( DownloadAttachmentForWebFailure( + attachmentBlobId: testAttachment.blobId, taskId: testDownloadTaskId, exception: testException, ), @@ -74,6 +75,7 @@ void main() { emitsInOrder([ Left( ViewAttachmentForWebFailure( + attachmentBlobId: testAttachment.blobId, taskId: testDownloadTaskId, exception: testException, ),