Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-718 fix: drag & drop on web version #721

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
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