Added file upload in talk

This commit is contained in:
2023-06-08 19:06:59 +02:00
parent f5afd7eb5e
commit 213c815eee
7 changed files with 123 additions and 24 deletions

View File

@ -11,8 +11,11 @@ class FileUploadDialog extends StatefulWidget {
final String localPath;
final List<String> remotePath;
final String fileName;
final void Function() triggerReload;
const FileUploadDialog({Key? key, required this.localPath, required this.remotePath, required this.fileName, required this.triggerReload}) : super(key: key);
final void Function() onUploadFinished;
final bool doShowFinish;
const FileUploadDialog({Key? key, required this.localPath, required this.remotePath, required this.fileName, required this.onUploadFinished, this.doShowFinish = true}) : super(key: key);
@override
State<FileUploadDialog> createState() => _FileUploadDialogState();
@ -40,6 +43,7 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
setState(() {
state = FileUploadState.checkConflict;
});
await (await WebdavApi.webdav).mkdirs(widget.remotePath.join("/"));
List<WebDavResponse> result = (await webdavClient.ls(widget.remotePath.join("/"))).responses;
if(result.any((element) => element.href!.endsWith("/$targetFileName"))) {
setState(() {
@ -174,9 +178,13 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
}
if(state == FileUploadState.done) {
widget.triggerReload();
widget.onUploadFinished();
if(!widget.doShowFinish) {
Navigator.of(context).pop();
return const SizedBox.shrink();
}
return AlertDialog(
icon: const Icon(Icons.upload),
icon: const Icon(Icons.done),
title: const Text("Upload fertig"),
content: Column(
mainAxisSize: MainAxisSize.min,

View File

@ -243,6 +243,6 @@ class _FilesState extends State<Files> {
}
var fileName = path.split(Platform.pathSeparator).last;
showDialog(context: context, builder: (context) => FileUploadDialog(localPath: path, remotePath: widget.path, fileName: fileName, triggerReload: () => _query()), barrierDismissible: false);
showDialog(context: context, builder: (context) => FileUploadDialog(localPath: path, remotePath: widget.path, fileName: fileName, onUploadFinished: () => _query()), barrierDismissible: false);
}
}

View File

@ -1,14 +1,17 @@
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart';
import '../../../api/marianumcloud/files-sharing/fileSharingApi.dart';
import '../../../api/marianumcloud/files-sharing/fileSharingApiParams.dart';
import '../../../api/marianumcloud/talk/sendMessage/sendMessage.dart';
import '../../../api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
import '../../../model/chatList/chatProps.dart';
import '../../../widget/filePick.dart';
import '../files/fileUploadDialog.dart';
class ChatTextfield extends StatefulWidget {
final String sendToToken;
@ -23,27 +26,34 @@ class _ChatTextfieldState extends State<ChatTextfield> {
bool sending = false;
bool isLoading = false;
void mediaUpload(String? path) {
void _query() {
Provider.of<ChatProps>(context, listen: false).run();
}
void mediaUpload(String? path) async {
context.loaderOverlay.hide();
if(path == null) {
context.loaderOverlay.hide();
return;
}
showDialog(context: context, builder: (context) {
return AlertDialog(
title: const Text("Datei senden"),
content: Image.file(File(path)),
actions: [
TextButton(onPressed: () {
Navigator.of(context).pop();
context.loaderOverlay.hide();
}, child: const Text("Abbrechen")),
TextButton(onPressed: () {
context.loaderOverlay.hide();
}, child: const Text("Senden")),
],
);
});
String filename = "${path.split("/").last.split(".").first}-${const Uuid().v4()}.${path.split(".").last}";
String shareFolder = "MarianumMobile";
showDialog(context: context, builder: (context) => FileUploadDialog(
doShowFinish: false,
fileName: filename,
localPath: path,
remotePath: [shareFolder],
onUploadFinished: () {
FileSharingApi().share(FileSharingApiParams(
shareType: 10,
shareWith: widget.sendToToken,
path: "$shareFolder/$filename",
//referenceId: "eae2d4497f0e1ffa1c71e6d86f7a59a43fd49198e799cc08a8a0fa8205b99969",
//talkMetaData: "{\"messageType\":\"\"}"
)).then((value) => _query());
},
), barrierDismissible: false);
}
@override
@ -123,7 +133,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
sending = true;
});
SendMessage(widget.sendToToken, SendMessageParams(_textBoxController.text)).run().then((value) => {
Provider.of<ChatProps>(context, listen: false).run(),
_query(),
_textBoxController.text = "",
setState(() {
sending = false;