diff --git a/lib/features/email/domain/state/download_all_attachments_for_web_state.dart b/lib/features/email/domain/state/download_all_attachments_for_web_state.dart index 7f63a1f01..dddb53b1c 100644 --- a/lib/features/email/domain/state/download_all_attachments_for_web_state.dart +++ b/lib/features/email/domain/state/download_all_attachments_for_web_state.dart @@ -1,16 +1,18 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; +import 'package:dio/dio.dart'; import 'package:model/download/download_task_id.dart'; import 'package:model/email/attachment.dart'; class StartDownloadAllAttachmentsForWeb extends UIState { - StartDownloadAllAttachmentsForWeb(this.taskId, this.attachment); + StartDownloadAllAttachmentsForWeb(this.taskId, this.attachment, {this.cancelToken}); final DownloadTaskId taskId; final Attachment attachment; + final CancelToken? cancelToken; @override - List get props => [taskId, attachment]; + List get props => [taskId, attachment, cancelToken]; } class DownloadingAllAttachmentsForWeb extends LoadingState { @@ -42,10 +44,11 @@ class DownloadAllAttachmentsForWebSuccess extends UIState { } class DownloadAllAttachmentsForWebFailure extends FeatureFailure { - DownloadAllAttachmentsForWebFailure({super.exception, required this.taskId}); + DownloadAllAttachmentsForWebFailure({super.exception, required this.taskId, this.cancelToken}); final DownloadTaskId taskId; + final CancelToken? cancelToken; @override - List get props => [exception, taskId]; + List get props => [exception, taskId, cancelToken]; } \ No newline at end of file diff --git a/lib/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart b/lib/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart index eb928b99d..755981deb 100644 --- a/lib/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart +++ b/lib/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart @@ -49,6 +49,7 @@ class DownloadAllAttachmentsForWebInteractor { onReceiveController.add(Right(StartDownloadAllAttachmentsForWeb( taskId, attachment, + cancelToken: cancelToken, ))); final currentAccount = await _accountRepository.getCurrentAccount(); AccountRequest accountRequest; @@ -77,7 +78,11 @@ class DownloadAllAttachmentsForWebInteractor { yield Right(DownloadAllAttachmentsForWebSuccess(taskId: taskId)); } catch (e) { logError('DownloadAllAttachmentsForWebInteractor::execute():EXCEPTION: $e'); - yield Left(DownloadAllAttachmentsForWebFailure(exception: e, taskId: taskId)); + yield Left(DownloadAllAttachmentsForWebFailure( + exception: e, + taskId: taskId, + cancelToken: cancelToken, + )); } } } \ No newline at end of file diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 0f06c92c6..eb4e13679 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -478,6 +478,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin { DownloadTaskState( taskId: success.taskId, attachment: success.attachment, + onCancel: () => success.cancelToken?.cancel(), ), ); @@ -1073,11 +1074,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin { DownloadAllAttachmentsForWebFailure failure, ) { mailboxDashBoardController.deleteDownloadTask(failure.taskId); - if (currentOverlayContext != null && currentContext != null) { - appToast.showToastErrorMessage( - currentOverlayContext!, - AppLocalizations.of(currentContext!).attachment_download_failed); - } + if (currentOverlayContext == null || currentContext == null) return; + String message = AppLocalizations.of(currentContext!).attachment_download_failed; + if (failure.cancelToken?.isCancelled == true) { + message = AppLocalizations.of(currentContext!).downloadAttachmentHasBeenCancelled; + } + appToast.showToastErrorMessage(currentOverlayContext!, message); } void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) {