Skip to content

Commit

Permalink
fix: drag & drop on web version
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Oct 5, 2023
1 parent a8a9589 commit 5a56fe1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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: '',
);
}
}
15 changes: 2 additions & 13 deletions lib/domain/usecase/send_file_on_web_interactor.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
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<void> execute({
required Room room,
required FilePickerResult filePickerResult,
required List<MatrixFile> files,
String? txId,
Event? inReplyTo,
String? editEventId,
int? shrinkImageMaxDimension,
Map<String, dynamic>? 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,
Expand Down
12 changes: 4 additions & 8 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -145,6 +146,8 @@ class ChatController extends State<Chat>
void onDragExited(_) => draggingNotifier.value = false;

void onDragDone(DropDoneDetails details) async {
final sendFileOnWebInteractor = getIt.get<SendFileOnWebInteractor>();

draggingNotifier.value = false;
final bytesList = await showFutureLoadingDialog(
context: context,
Expand All @@ -166,14 +169,7 @@ class ChatController extends State<Chat>
);
}

await showDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
files: matrixFiles,
room: room!,
),
);
sendFileOnWebInteractor.execute(room: room!, files: matrixFiles);
}

bool get canSaveSelectedEvent =>
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/chat_draft/draft_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -282,11 +283,13 @@ class DraftChatController extends State<DraftChat>
);
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,
);
},
);
Expand Down
9 changes: 7 additions & 2 deletions lib/presentation/mixins/send_files_mixin.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 5a56fe1

Please sign in to comment.