Skip to content

Commit

Permalink
Hotfix: Can't get file on web
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Apr 3, 2024
1 parent 66bffae commit af52c26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
}) {
Expand Down
7 changes: 1 addition & 6 deletions lib/pages/chat_draft/draft_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> Function(Room room)?;
Expand Down Expand Up @@ -329,13 +328,9 @@ class DraftChatController extends State<DraftChat>
);
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();

Expand Down
11 changes: 2 additions & 9 deletions lib/presentation/mixins/send_files_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mixin SendFilesMixin {
fileInfos ??= result?.files
.map(
(xFile) => FileInfo.fromMatrixFile(
xFile.toMatrixFile(
xFile.toMatrixFileOnMobile(
temporaryDirectoryPath: temporaryDirectory.path,
),
),
Expand All @@ -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({
Expand Down

0 comments on commit af52c26

Please sign in to comment.