Added file upload in talk
This commit is contained in:
parent
f5afd7eb5e
commit
213c815eee
30
lib/api/marianumcloud/files-sharing/fileSharingApi.dart
Normal file
30
lib/api/marianumcloud/files-sharing/fileSharingApi.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'fileSharingApiParams.dart';
|
||||
|
||||
class FileSharingApi {
|
||||
Future<void> share(FileSharingApiParams query) async {
|
||||
var preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Map<String, String> headers = {};
|
||||
headers.putIfAbsent("Accept", () => "application/json");
|
||||
headers.putIfAbsent("OCS-APIRequest", () => "true");
|
||||
|
||||
Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/files_sharing/api/v1/shares", query.toJson().map((key, value) => MapEntry(key, value.toString())));
|
||||
|
||||
log("request file share");
|
||||
Response response = await http.post(endpoint, headers: headers);
|
||||
|
||||
if(response.statusCode != HttpStatus.ok) {
|
||||
throw Exception("Api call failed with ${response.statusCode}: ${response.body}");
|
||||
} else {
|
||||
log("File share successfull: ${response.body}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'fileSharingApiParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FileSharingApiParams {
|
||||
int shareType;
|
||||
String shareWith;
|
||||
String path;
|
||||
String? referenceId;
|
||||
String? talkMetaData;
|
||||
|
||||
FileSharingApiParams({
|
||||
required this.shareType,
|
||||
required this.shareWith,
|
||||
required this.path,
|
||||
this.referenceId,
|
||||
this.talkMetaData
|
||||
});
|
||||
|
||||
factory FileSharingApiParams.fromJson(Map<String, dynamic> json) => _$FileSharingApiParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$FileSharingApiParamsToJson(this);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'fileSharingApiParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FileSharingApiParams _$FileSharingApiParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
FileSharingApiParams(
|
||||
shareType: json['shareType'] as int,
|
||||
shareWith: json['shareWith'] as String,
|
||||
path: json['path'] as String,
|
||||
referenceId: json['referenceId'] as String?,
|
||||
talkMetaData: json['talkMetaData'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FileSharingApiParamsToJson(
|
||||
FileSharingApiParams instance) =>
|
||||
<String, dynamic>{
|
||||
'shareType': instance.shareType,
|
||||
'shareWith': instance.shareWith,
|
||||
'path': instance.path,
|
||||
'referenceId': instance.referenceId,
|
||||
'talkMetaData': instance.talkMetaData,
|
||||
};
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
if(path == null) {
|
||||
void _query() {
|
||||
Provider.of<ChatProps>(context, listen: false).run();
|
||||
}
|
||||
|
||||
void mediaUpload(String? path) async {
|
||||
context.loaderOverlay.hide();
|
||||
|
||||
if(path == null) {
|
||||
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;
|
||||
|
@ -80,6 +80,7 @@ dependencies:
|
||||
animated_digit: ^3.2.1
|
||||
syncfusion_flutter_pdfviewer: ^21.2.8
|
||||
photo_view: ^0.14.0
|
||||
uuid: ^3.0.7
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user