From af52c264db55dcb45f5f83e6683f7ecb0777144b Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Mon, 1 Apr 2024 15:44:48 +0700 Subject: [PATCH] Hotfix: Can't get file on web --- .../platform_file/platform_file_extension.dart | 12 +++++++++++- lib/pages/chat_draft/draft_chat.dart | 7 +------ lib/presentation/mixins/send_files_mixin.dart | 11 ++--------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/domain/model/extensions/platform_file/platform_file_extension.dart b/lib/domain/model/extensions/platform_file/platform_file_extension.dart index 1be8141af4..74da8aa8f9 100644 --- a/lib/domain/model/extensions/platform_file/platform_file_extension.dart +++ b/lib/domain/model/extensions/platform_file/platform_file_extension.dart @@ -2,7 +2,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:matrix/matrix.dart'; extension PlatformFileListExtension on PlatformFile { - MatrixFile toMatrixFile({ + MatrixFile toMatrixFileOnMobile({ required String temporaryDirectoryPath, }) { return MatrixFile.fromMimeType( @@ -14,6 +14,16 @@ extension PlatformFileListExtension on PlatformFile { ); } + MatrixFile toMatrixFileOnWeb() { + return MatrixFile.fromMimeType( + bytes: bytes, + name: name, + filePath: '', + readStream: readStream, + sizeInBytes: size, + ); + } + FileInfo toFileInfo({ required String temporaryDirectoryPath, }) { diff --git a/lib/pages/chat_draft/draft_chat.dart b/lib/pages/chat_draft/draft_chat.dart index 78701a0a5c..e977175043 100644 --- a/lib/pages/chat_draft/draft_chat.dart +++ b/lib/pages/chat_draft/draft_chat.dart @@ -32,7 +32,6 @@ import 'package:linagora_design_flutter/images_picker/asset_counter.dart'; import 'package:linagora_design_flutter/images_picker/images_picker.dart' hide ImagePicker; import 'package:matrix/matrix.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:scroll_to_index/scroll_to_index.dart'; typedef OnRoomCreatedSuccess = FutureOr Function(Room room)?; @@ -329,13 +328,9 @@ class DraftChatController extends State ); if (result == null || result.files.isEmpty) return; - final temporaryDirectory = await getTemporaryDirectory(); - final matrixFilesList = result.files .map( - (file) => file - .toMatrixFile(temporaryDirectoryPath: temporaryDirectory.path) - .detectFileType, + (file) => file.toMatrixFileOnWeb().detectFileType, ) .toList(); diff --git a/lib/presentation/mixins/send_files_mixin.dart b/lib/presentation/mixins/send_files_mixin.dart index 39ee901e00..1b7fa60c87 100644 --- a/lib/presentation/mixins/send_files_mixin.dart +++ b/lib/presentation/mixins/send_files_mixin.dart @@ -46,7 +46,7 @@ mixin SendFilesMixin { fileInfos ??= result?.files .map( (xFile) => FileInfo.fromMatrixFile( - xFile.toMatrixFile( + xFile.toMatrixFileOnMobile( temporaryDirectoryPath: temporaryDirectory.path, ), ), @@ -65,14 +65,7 @@ mixin SendFilesMixin { withReadStream: true, ); if (result == null || result.files.isEmpty) return []; - final temporaryDirectory = await getTemporaryDirectory(); - return result.files - .map( - (file) => file.toMatrixFile( - temporaryDirectoryPath: temporaryDirectory.path, - ), - ) - .toList(); + return result.files.map((file) => file.toMatrixFileOnWeb()).toList(); } void onPickerTypeClick({