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 String localPath;
|
||||||
final List<String> remotePath;
|
final List<String> remotePath;
|
||||||
final String fileName;
|
final String fileName;
|
||||||
final void Function() triggerReload;
|
final void Function() onUploadFinished;
|
||||||
const FileUploadDialog({Key? key, required this.localPath, required this.remotePath, required this.fileName, required this.triggerReload}) : super(key: key);
|
|
||||||
|
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
|
@override
|
||||||
State<FileUploadDialog> createState() => _FileUploadDialogState();
|
State<FileUploadDialog> createState() => _FileUploadDialogState();
|
||||||
@ -40,6 +43,7 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
state = FileUploadState.checkConflict;
|
state = FileUploadState.checkConflict;
|
||||||
});
|
});
|
||||||
|
await (await WebdavApi.webdav).mkdirs(widget.remotePath.join("/"));
|
||||||
List<WebDavResponse> result = (await webdavClient.ls(widget.remotePath.join("/"))).responses;
|
List<WebDavResponse> result = (await webdavClient.ls(widget.remotePath.join("/"))).responses;
|
||||||
if(result.any((element) => element.href!.endsWith("/$targetFileName"))) {
|
if(result.any((element) => element.href!.endsWith("/$targetFileName"))) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -174,9 +178,13 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(state == FileUploadState.done) {
|
if(state == FileUploadState.done) {
|
||||||
widget.triggerReload();
|
widget.onUploadFinished();
|
||||||
|
if(!widget.doShowFinish) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
icon: const Icon(Icons.upload),
|
icon: const Icon(Icons.done),
|
||||||
title: const Text("Upload fertig"),
|
title: const Text("Upload fertig"),
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
@ -243,6 +243,6 @@ class _FilesState extends State<Files> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileName = path.split(Platform.pathSeparator).last;
|
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:developer';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:loader_overlay/loader_overlay.dart';
|
import 'package:loader_overlay/loader_overlay.dart';
|
||||||
import 'package:provider/provider.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/sendMessage.dart';
|
||||||
import '../../../api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
|
import '../../../api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
|
||||||
import '../../../model/chatList/chatProps.dart';
|
import '../../../model/chatList/chatProps.dart';
|
||||||
import '../../../widget/filePick.dart';
|
import '../../../widget/filePick.dart';
|
||||||
|
import '../files/fileUploadDialog.dart';
|
||||||
|
|
||||||
class ChatTextfield extends StatefulWidget {
|
class ChatTextfield extends StatefulWidget {
|
||||||
final String sendToToken;
|
final String sendToToken;
|
||||||
@ -23,27 +26,34 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
|||||||
bool sending = false;
|
bool sending = false;
|
||||||
bool isLoading = 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) {
|
if(path == null) {
|
||||||
context.loaderOverlay.hide();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog(context: context, builder: (context) {
|
String filename = "${path.split("/").last.split(".").first}-${const Uuid().v4()}.${path.split(".").last}";
|
||||||
return AlertDialog(
|
String shareFolder = "MarianumMobile";
|
||||||
title: const Text("Datei senden"),
|
showDialog(context: context, builder: (context) => FileUploadDialog(
|
||||||
content: Image.file(File(path)),
|
doShowFinish: false,
|
||||||
actions: [
|
fileName: filename,
|
||||||
TextButton(onPressed: () {
|
localPath: path,
|
||||||
Navigator.of(context).pop();
|
remotePath: [shareFolder],
|
||||||
context.loaderOverlay.hide();
|
onUploadFinished: () {
|
||||||
}, child: const Text("Abbrechen")),
|
FileSharingApi().share(FileSharingApiParams(
|
||||||
TextButton(onPressed: () {
|
shareType: 10,
|
||||||
context.loaderOverlay.hide();
|
shareWith: widget.sendToToken,
|
||||||
}, child: const Text("Senden")),
|
path: "$shareFolder/$filename",
|
||||||
],
|
//referenceId: "eae2d4497f0e1ffa1c71e6d86f7a59a43fd49198e799cc08a8a0fa8205b99969",
|
||||||
);
|
//talkMetaData: "{\"messageType\":\"\"}"
|
||||||
});
|
)).then((value) => _query());
|
||||||
|
},
|
||||||
|
), barrierDismissible: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -123,7 +133,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
|||||||
sending = true;
|
sending = true;
|
||||||
});
|
});
|
||||||
SendMessage(widget.sendToToken, SendMessageParams(_textBoxController.text)).run().then((value) => {
|
SendMessage(widget.sendToToken, SendMessageParams(_textBoxController.text)).run().then((value) => {
|
||||||
Provider.of<ChatProps>(context, listen: false).run(),
|
_query(),
|
||||||
_textBoxController.text = "",
|
_textBoxController.text = "",
|
||||||
setState(() {
|
setState(() {
|
||||||
sending = false;
|
sending = false;
|
||||||
|
@ -80,6 +80,7 @@ dependencies:
|
|||||||
animated_digit: ^3.2.1
|
animated_digit: ^3.2.1
|
||||||
syncfusion_flutter_pdfviewer: ^21.2.8
|
syncfusion_flutter_pdfviewer: ^21.2.8
|
||||||
photo_view: ^0.14.0
|
photo_view: ^0.14.0
|
||||||
|
uuid: ^3.0.7
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user