TF-2628 [Part-2] Add attachment property to DownloadAttachmentForWebFailure & ViewAttachmentForWebFailure

This commit is contained in:
DatDang
2024-02-27 15:58:59 +07:00
committed by Dat H. Pham
parent ab8544c3ad
commit 6fe62cb068
6 changed files with 20 additions and 4 deletions
@@ -1,6 +1,7 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.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/download/download_task_id.dart';
import 'package:model/email/attachment.dart'; import 'package:model/email/attachment.dart';
@@ -56,9 +57,12 @@ class DownloadAttachmentForWebSuccess extends UIState {
class DownloadAttachmentForWebFailure extends FeatureFailure { class DownloadAttachmentForWebFailure extends FeatureFailure {
final DownloadTaskId? taskId; final DownloadTaskId? taskId;
final Id? attachmentBlobId;
DownloadAttachmentForWebFailure({ DownloadAttachmentForWebFailure({
this.taskId, dynamic exception required this.attachmentBlobId,
this.taskId,
dynamic exception
}) : super(exception: exception); }) : super(exception: exception);
@override @override
@@ -19,5 +19,9 @@ class ViewAttachmentForWebSuccess extends DownloadAttachmentForWebSuccess {
} }
class ViewAttachmentForWebFailure extends DownloadAttachmentForWebFailure { class ViewAttachmentForWebFailure extends DownloadAttachmentForWebFailure {
ViewAttachmentForWebFailure({super.taskId, super.exception}); ViewAttachmentForWebFailure({
required super.attachmentBlobId,
super.taskId,
super.exception,
});
} }
@@ -72,6 +72,7 @@ class DownloadAttachmentForWebInteractor {
} catch (exception) { } catch (exception) {
yield Left<Failure, Success>( yield Left<Failure, Success>(
DownloadAttachmentForWebFailure( DownloadAttachmentForWebFailure(
attachmentBlobId: attachment.blobId,
taskId: taskId, taskId: taskId,
exception: exception exception: exception
) )
@@ -34,6 +34,7 @@ class ViewAttachmentForWebInteractor {
(failure) { (failure) {
if (failure is DownloadAttachmentForWebFailure) { if (failure is DownloadAttachmentForWebFailure) {
return Left(ViewAttachmentForWebFailure( return Left(ViewAttachmentForWebFailure(
attachmentBlobId: attachment.blobId,
taskId: failure.taskId, taskId: failure.taskId,
exception: failure.exception, exception: failure.exception,
)); ));
@@ -744,7 +744,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_downloadProgressStateController)); _downloadProgressStateController));
} else { } else {
consumeState(Stream.value( consumeState(Stream.value(
Left(DownloadAttachmentForWebFailure(exception: NotFoundSessionException())) Left(DownloadAttachmentForWebFailure(
attachment: attachment,
exception: NotFoundSessionException()))
)); ));
} }
} }
@@ -763,7 +765,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_downloadProgressStateController)); _downloadProgressStateController));
} else { } else {
consumeState(Stream.value( consumeState(Stream.value(
Left(ViewAttachmentForWebFailure(exception: NotFoundSessionException())) Left(ViewAttachmentForWebFailure(
attachment: attachment,
exception: NotFoundSessionException()))
)); ));
} }
} }
@@ -55,6 +55,7 @@ void main() {
(_) => Stream.value( (_) => Stream.value(
Left( Left(
DownloadAttachmentForWebFailure( DownloadAttachmentForWebFailure(
attachmentBlobId: testAttachment.blobId,
taskId: testDownloadTaskId, taskId: testDownloadTaskId,
exception: testException, exception: testException,
), ),
@@ -74,6 +75,7 @@ void main() {
emitsInOrder([ emitsInOrder([
Left( Left(
ViewAttachmentForWebFailure( ViewAttachmentForWebFailure(
attachmentBlobId: testAttachment.blobId,
taskId: testDownloadTaskId, taskId: testDownloadTaskId,
exception: testException, exception: testException,
), ),