diff --git a/lib/domain/model/extensions/platform_file/platform_file_extension.dart b/lib/domain/model/extensions/platform_file/platform_file_extension.dart new file mode 100644 index 0000000000..01039f7d43 --- /dev/null +++ b/lib/domain/model/extensions/platform_file/platform_file_extension.dart @@ -0,0 +1,12 @@ +import 'package:file_picker/file_picker.dart'; +import 'package:matrix/matrix.dart'; + +extension PlatformFileListExtension on PlatformFile { + MatrixFile toMatrixFile() { + return MatrixFile.fromMimeType( + bytes: bytes, + name: name, + filePath: '', + ); + } +} 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 ea426efb52..673d230771 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..72e4262670 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_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'; @@ -282,11 +283,13 @@ class DraftChatController extends State ); if (result == null || result.files.isEmpty) return; + final matrixFilesList = + result.files.map((file) => file.toMatrixFile()).toList(); _createRoom( onRoomCreatedSuccess: (newRoom) { sendFileOnWebInteractor.execute( room: newRoom, - filePickerResult: result, + files: matrixFilesList, ); }, ); diff --git a/lib/presentation/mixins/send_files_mixin.dart b/lib/presentation/mixins/send_files_mixin.dart index c2ce849779..dd0bec5438 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_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'; @@ -64,8 +65,12 @@ mixin SendFilesMixin { withData: true, ); if (result == null || result.files.isEmpty) return; - - sendFileOnWebInteractor.execute(room: room!, filePickerResult: result); + final matrixFilesList = + result.files.map((file) => file.toMatrixFile()).toList(); + sendFileOnWebInteractor.execute( + room: room!, + files: matrixFilesList, + ); } void onPickerTypeClick({