From 81ce3f6b047ee6aedfc687cf3928eaacc3ebdf62 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 14 Oct 2025 13:24:29 +0700 Subject: [PATCH] TF-4058 Automatically save to storage when attachment export fails on mobile --- .../controller/single_email_controller.dart | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 988c781f9..484785f13 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -36,7 +36,6 @@ import 'package:model/error_type_handler/unknown_uri_exception.dart'; import 'package:model/model.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:pointer_interceptor/pointer_interceptor.dart'; -import 'package:share_plus/share_plus.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart'; import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart'; @@ -968,6 +967,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin { logError('SingleEmailController::_exportAttachmentAction(): $e'); consumeState(Stream.value(Left(ExportAttachmentFailure(e)))); } + } else { + consumeState(Stream.value(Left(ExportAttachmentFailure(NotFoundAccountIdException())))); } } @@ -1034,35 +1035,35 @@ class SingleEmailController extends BaseController with AppLoaderMixin { void _exportAllAttachmentsSuccessAction(ExportAllAttachmentsSuccess success) { popBack(); - _saveDownloadedZipAttachments(success.downloadedResponse.filePath); + _saveFileToStorage(success.downloadedResponse.filePath); } void _openDownloadedPreviewWorkGroupDocument(DownloadedResponse downloadedResponse) async { log('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): $downloadedResponse'); - if (downloadedResponse.mediaType == null) { - await Share.shareXFiles([XFile(downloadedResponse.filePath)]); + final filePath = downloadedResponse.filePath; + final mediaType = downloadedResponse.mediaType; + + if (mediaType == null) { + _saveFileToStorage(filePath); + return; } final openResult = await open_file.OpenFile.open( - downloadedResponse.filePath, - type: Platform.isAndroid ? downloadedResponse.mediaType!.mimeType : null, + filePath, + type: Platform.isAndroid ? mediaType.mimeType : null, // "xdg" is default value linuxDesktopName: Platform.isIOS - ? downloadedResponse.mediaType!.getDocumentUti().value ?? 'xdg' + ? mediaType.getDocumentUti().value ?? 'xdg' : 'xdg', ); if (openResult.type != open_file.ResultType.done) { logError('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): no preview available'); - if (currentOverlayContext != null && currentContext != null) { - appToast.showToastErrorMessage( - currentOverlayContext!, - AppLocalizations.of(currentContext!).noPreviewAvailable); - } + _saveFileToStorage(filePath); } } - Future _saveDownloadedZipAttachments(String filePath) async { + Future _saveFileToStorage(String filePath) async { final params = SaveFileDialogParams(sourceFilePath: filePath); await FlutterFileDialog.saveFile(params: params); }