Create a collection and back up the folder if a user attempts to share a folder that is not backed up

This commit is contained in:
Vishnu Mohandas 2020-10-17 22:51:32 +05:30
parent d64f34f6d7
commit 92d154b96e
4 changed files with 35 additions and 16 deletions

View file

@ -144,7 +144,7 @@ class Configuration {
// return _preferences.getBool(hasOptedForE2EKey);
}
Set<String> getFoldersToBackUp() {
Set<String> getPathsToBackUp() {
if (_preferences.containsKey(foldersToBackUpKey)) {
return _preferences.getStringList(foldersToBackUpKey).toSet();
} else {
@ -158,10 +158,16 @@ class Configuration {
}
}
Future<void> setFoldersToBackUp(Set<String> folders) async {
Future<void> setPathsToBackUp(Set<String> folders) async {
await _preferences.setStringList(foldersToBackUpKey, folders.toList());
}
Future<void> addPathToFoldersToBeBackedUp(String path) async {
final currentPaths = getPathsToBackUp();
currentPaths.add(path);
return setPathsToBackUp(currentPaths);
}
Future<void> setKeyAttributes(KeyAttributes attributes) async {
await _preferences.setString(
keyAttributesKey, attributes == null ? null : attributes.toJson());

View file

@ -184,7 +184,7 @@ class SyncService {
}
Future<void> _uploadDiff() async {
final foldersToBackUp = Configuration.instance.getFoldersToBackUp();
final foldersToBackUp = Configuration.instance.getPathsToBackUp();
List<File> filesToBeUploaded =
await _db.getFilesToBeUploadedWithinFolders(foldersToBackUp);
for (int i = 0; i < filesToBeUploaded.length; i++) {

View file

@ -169,7 +169,7 @@ class _BackedUpFoldersWidgetState extends State<BackedUpFoldersWidget> {
snapshot.data.sort((first, second) {
return first.toLowerCase().compareTo(second.toLowerCase());
});
final backedUpFolders = Configuration.instance.getFoldersToBackUp();
final backedUpFolders = Configuration.instance.getPathsToBackUp();
final foldersWidget = List<Row>();
for (final folder in snapshot.data) {
foldersWidget.add(Row(children: [
@ -182,7 +182,7 @@ class _BackedUpFoldersWidgetState extends State<BackedUpFoldersWidget> {
backedUpFolders.remove(folder);
}
await Configuration.instance
.setFoldersToBackUp(backedUpFolders);
.setPathsToBackUp(backedUpFolders);
setState(() {});
},
),

View file

@ -1,10 +1,13 @@
import 'dart:developer';
import 'dart:html';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/models/collection.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/services/sync_service.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/loading_widget.dart';
@ -38,7 +41,7 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
: CollectionsService.instance.getSharees(widget.collection.id),
builder: (context, snapshot) {
if (snapshot.hasData) {
return SharingDialog(widget.collection, snapshot.data);
return SharingDialog(widget.collection, snapshot.data, widget.path);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
} else {
@ -52,8 +55,10 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
class SharingDialog extends StatefulWidget {
final Collection collection;
final List<String> sharees;
final String path;
SharingDialog(this.collection, this.sharees, {Key key}) : super(key: key);
SharingDialog(this.collection, this.sharees, this.path, {Key key})
: super(key: key);
@override
_SharingDialogState createState() => _SharingDialogState();
@ -116,8 +121,8 @@ class _SharingDialogState extends State<SharingDialog> {
width: 220,
child: button(
"Add",
onPressed: () async {
await _addEmailToCollection(context);
onPressed: () {
_addEmailToCollection(context);
},
),
));
@ -173,14 +178,22 @@ class _SharingDialogState extends State<SharingDialog> {
},
);
} else {
if (widget.collection == null) {
log("Collection is null");
// TODO: Create collection
// TODO: Add files to collection
final dialog = createProgressDialog(context, "Sharing...");
await dialog.show();
var collectionID;
if (widget.collection != null) {
collectionID = widget.collection.id;
} else {
collectionID =
(await CollectionsService.instance.getOrCreateForPath(widget.path))
.id;
await Configuration.instance.addPathToFoldersToBeBackedUp(widget.path);
SyncService.instance.sync();
}
CollectionsService.instance
.share(widget.collection.id, _email, publicKey)
.then((value) {
return CollectionsService.instance
.share(collectionID, _email, publicKey)
.then((value) async {
await dialog.hide();
setState(() {
_sharees.add(_email);
_showEntryField = false;