From add5c9193e542f18decd9b335aa00b5e879d5a3b Mon Sep 17 00:00:00 2001 From: Julian KOUNE Date: Mon, 2 Oct 2023 15:57:49 +0200 Subject: [PATCH] fix: drag & drop on web version --- .../platform_file_list_extension.dart | 14 ++++++++++++++ .../usecase/send_file_on_web_interactor.dart | 15 ++------------- lib/pages/chat/chat.dart | 12 ++++-------- lib/pages/chat_draft/draft_chat.dart | 3 ++- lib/presentation/mixins/send_files_mixin.dart | 6 +++++- 5 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 lib/domain/model/extensions/platform_file/platform_file_list_extension.dart diff --git a/lib/domain/model/extensions/platform_file/platform_file_list_extension.dart b/lib/domain/model/extensions/platform_file/platform_file_list_extension.dart new file mode 100644 index 0000000000..64bd8eae37 --- /dev/null +++ b/lib/domain/model/extensions/platform_file/platform_file_list_extension.dart @@ -0,0 +1,14 @@ +import 'package:file_picker/file_picker.dart'; +import 'package:matrix/matrix.dart'; + +extension PlatformFileListExtension on List { + List toMatrixFileList() { + return map( + (xFile) => MatrixFile.fromMimeType( + bytes: xFile.bytes, + name: xFile.name, + filePath: '', + ), + ).toList(); + } +} diff --git a/lib/domain/usecase/send_file_on_web_interactor.dart b/lib/domain/usecase/send_file_on_web_interactor.dart index 4d71e52c58..643b041e11 100644 --- a/lib/domain/usecase/send_file_on_web_interactor.dart +++ b/lib/domain/usecase/send_file_on_web_interactor.dart @@ -1,11 +1,10 @@ -import 'package:file_picker/file_picker.dart'; import 'package:fluffychat/presentation/extensions/send_file_web_extension.dart'; import 'package:matrix/matrix.dart'; class SendFileOnWebInteractor { Future execute({ required Room room, - required FilePickerResult filePickerResult, + required List files, String? txId, Event? inReplyTo, String? editEventId, @@ -13,17 +12,7 @@ class SendFileOnWebInteractor { Map? extraContent, }) async { try { - final matrixFiles = filePickerResult.files - .map( - (xFile) => MatrixFile.fromMimeType( - bytes: xFile.bytes, - name: xFile.name, - filePath: '', - ), - ) - .toList(); - - for (final matrixFile in matrixFiles) { + for (final matrixFile in files) { await room.sendFileOnWebEvent( matrixFile, txid: txId, diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index fe3e3fa96b..dd8cbe563a 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -13,6 +13,7 @@ import 'package:fluffychat/domain/model/download_file/download_file_for_preview_ import 'package:fluffychat/domain/model/preview_file/document_uti.dart'; import 'package:fluffychat/domain/model/preview_file/supported_preview_file_types.dart'; import 'package:fluffychat/domain/usecase/download_file_for_preview_interactor.dart'; +import 'package:fluffychat/domain/usecase/send_file_on_web_interactor.dart'; import 'package:fluffychat/pages/chat/chat_context_menu_actions.dart'; import 'package:fluffychat/domain/usecase/send_file_interactor.dart'; import 'package:fluffychat/pages/chat/chat_horizontal_action_menu.dart'; @@ -145,6 +146,8 @@ class ChatController extends State void onDragExited(_) => draggingNotifier.value = false; void onDragDone(DropDoneDetails details) async { + final sendFileOnWebInteractor = getIt.get(); + draggingNotifier.value = false; final bytesList = await showFutureLoadingDialog( context: context, @@ -166,14 +169,7 @@ class ChatController extends State ); } - await showDialog( - context: context, - useRootNavigator: false, - builder: (c) => SendFileDialog( - files: matrixFiles, - room: room!, - ), - ); + sendFileOnWebInteractor.execute(room: room!, files: matrixFiles); } bool get canSaveSelectedEvent => diff --git a/lib/pages/chat_draft/draft_chat.dart b/lib/pages/chat_draft/draft_chat.dart index f28396d2ef..1f84540d1c 100644 --- a/lib/pages/chat_draft/draft_chat.dart +++ b/lib/pages/chat_draft/draft_chat.dart @@ -4,6 +4,7 @@ import 'package:emoji_picker_flutter/emoji_picker_flutter.dart'; import 'package:file_picker/file_picker.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/domain/app_state/direct_chat/create_direct_chat_success.dart'; +import 'package:fluffychat/domain/model/extensions/platform_file/platform_file_list_extension.dart'; import 'package:fluffychat/domain/usecase/create_direct_chat_interactor.dart'; import 'package:fluffychat/domain/usecase/send_file_on_web_interactor.dart'; import 'package:fluffychat/pages/chat/chat.dart'; @@ -286,7 +287,7 @@ class DraftChatController extends State onRoomCreatedSuccess: (newRoom) { sendFileOnWebInteractor.execute( room: newRoom, - filePickerResult: result, + files: result.files.toMatrixFileList(), ); }, ); diff --git a/lib/presentation/mixins/send_files_mixin.dart b/lib/presentation/mixins/send_files_mixin.dart index c2ce849779..ea10598a16 100644 --- a/lib/presentation/mixins/send_files_mixin.dart +++ b/lib/presentation/mixins/send_files_mixin.dart @@ -1,5 +1,6 @@ import 'package:file_picker/file_picker.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/model/extensions/platform_file/platform_file_list_extension.dart'; import 'package:fluffychat/domain/usecase/send_file_interactor.dart'; import 'package:fluffychat/domain/usecase/send_file_on_web_interactor.dart'; import 'package:fluffychat/domain/usecase/send_images_interactor.dart'; @@ -65,7 +66,10 @@ mixin SendFilesMixin { ); if (result == null || result.files.isEmpty) return; - sendFileOnWebInteractor.execute(room: room!, filePickerResult: result); + sendFileOnWebInteractor.execute( + room: room!, + files: result.files.toMatrixFileList(), + ); } void onPickerTypeClick({