Skip to content

Commit

Permalink
TW-1699: send files ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-Z committed May 3, 2024
1 parent 50f8040 commit 400fda4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/domain/model/extensions/xfile_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:file_selector/file_selector.dart';
import 'package:matrix/matrix.dart';

extension XFileExtension on XFile {

Future<MatrixFile> toMatrixFile() async{
return MatrixFile.fromMimeType(
bytes: await readAsBytes(),
mimeType: mimeType,
name: name,
filePath: path,
sizeInBytes: await length(),
);
}
}
3 changes: 3 additions & 0 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,9 @@ class ChatController extends State<Chat>
void onSendFileClick(BuildContext context) async {
if (PlatformInfos.isMobile) {
_showMediaPicker(context);
} else if (PlatformInfos.isDesktop) {
final matrixFiles = await pickFilesFromDesktop();
sendFileOnWebAction(context, room: room, matrixFilesList: matrixFiles);
} else {
final matrixFiles = await pickFilesFromSystem();
sendFileOnWebAction(context, room: room, matrixFilesList: matrixFiles);
Expand Down
20 changes: 20 additions & 0 deletions lib/presentation/mixins/send_files_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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/model/extensions/xfile_extension.dart';
import 'package:fluffychat/domain/usecase/send_file_interactor.dart';
import 'package:fluffychat/domain/usecase/send_images_interactor.dart';
import 'package:fluffychat/pages/chat/chat_actions.dart';
import 'package:fluffychat/presentation/model/file/file_asset_entity.dart';
import 'package:flutter/material.dart';
import 'package:linagora_design_flutter/images_picker/images_picker.dart';
import 'package:file_selector/file_selector.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';

Expand Down Expand Up @@ -68,6 +70,24 @@ mixin SendFilesMixin {
return result.files.map((file) => file.toMatrixFileOnWeb()).toList();
}

Future<List<MatrixFile>> pickFilesFromDesktop() async {
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;
final List<XFile> xFiles =
await openFiles(initialDirectory: initialDirectory);

if (xFiles.isEmpty) return [];

final matrixFiles = <MatrixFile>[];

for (final xFile in xFiles) {
final matrixFile = await xFile.toMatrixFile();
matrixFiles.add(matrixFile);
}

return matrixFiles;
}

void onPickerTypeClick({
required BuildContext context,
Room? room,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ packages:
source: hosted
version: "0.2.12"
file_selector:
dependency: "direct overridden"
dependency: "direct main"
description:
name: file_selector
sha256: "1d2fde93dddf634a9c3c0faa748169d7ac0d83757135555707e52f02c017ad4f"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ dependencies:
open_app_file:
git:
url: [email protected]:aws1313/open_app_file.git
file_selector: ^0.9.2+2

dev_dependencies:
build_runner: ^2.3.3
Expand Down

0 comments on commit 400fda4

Please sign in to comment.