|
@@ -1,5 +1,8 @@
|
|
|
+import 'dart:developer';
|
|
|
+
|
|
|
import 'package:dio/dio.dart';
|
|
|
import 'package:photos/core/configuration.dart';
|
|
|
+import 'package:photos/models/folder.dart';
|
|
|
|
|
|
class FolderSharingService {
|
|
|
final _dio = Dio();
|
|
@@ -9,8 +12,6 @@ class FolderSharingService {
|
|
|
FolderSharingService._privateConstructor();
|
|
|
|
|
|
Future<Map<String, bool>> getSharingStatus(String path) async {
|
|
|
- // TODO fetch folderID from path
|
|
|
- var folderID = 0;
|
|
|
return _dio
|
|
|
.get(
|
|
|
Configuration.instance.getHttpEndpoint() + "/users",
|
|
@@ -20,17 +21,28 @@ class FolderSharingService {
|
|
|
.then((usersResponse) {
|
|
|
return _dio
|
|
|
.get(
|
|
|
- Configuration.instance.getHttpEndpoint() +
|
|
|
- "/folders/folder/" +
|
|
|
- folderID.toString(),
|
|
|
+ Configuration.instance.getHttpEndpoint() + "/folders/",
|
|
|
options: Options(
|
|
|
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
|
|
)
|
|
|
- .then((sharedFoldersResponse) {
|
|
|
- final sharedUsers =
|
|
|
- (sharedFoldersResponse.data["sharedWith"] as List).toSet();
|
|
|
+ .then((foldersResponse) {
|
|
|
+ var folders = (foldersResponse.data as List)
|
|
|
+ .map((f) => Folder.fromMap(f))
|
|
|
+ .toList();
|
|
|
+ Folder sharedFolder;
|
|
|
+ for (var folder in folders) {
|
|
|
+ if (folder.owner == Configuration.instance.getUsername() &&
|
|
|
+ folder.deviceFolder == path) {
|
|
|
+ sharedFolder = folder;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var sharedUsers = Set<String>();
|
|
|
+ if (sharedFolder != null) {
|
|
|
+ sharedUsers.addAll(sharedFolder.sharedWith);
|
|
|
+ }
|
|
|
final result = Map<String, bool>();
|
|
|
- (usersResponse.data as List).forEach((user) {
|
|
|
+ (usersResponse.data["users"] as List).forEach((user) {
|
|
|
if (user != Configuration.instance.getUsername()) {
|
|
|
result[user] = sharedUsers.contains(user);
|
|
|
}
|
|
@@ -40,7 +52,5 @@ class FolderSharingService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- void shareFolder(
|
|
|
- String path,
|
|
|
- ) {}
|
|
|
+ void shareFolder(String path) {}
|
|
|
}
|