Browse Source

More changes related to backup folder tracking

Neeraj Gupta 2 years ago
parent
commit
0c07eb4d05

+ 0 - 6
lib/core/configuration.dart

@@ -400,12 +400,6 @@ class Configuration {
     SyncService.instance.sync();
   }
 
-  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?.toJson());
   }

+ 17 - 12
lib/ui/sharing/share_collection_widget.dart

@@ -8,10 +8,13 @@ import 'package:fluttercontactpicker/fluttercontactpicker.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
+import 'package:photos/db/device_files_db.dart';
+import 'package:photos/db/files_db.dart';
 import 'package:photos/db/public_keys_db.dart';
 import 'package:photos/ente_theme_data.dart';
 import 'package:photos/events/backup_folders_updated_event.dart';
 import 'package:photos/models/collection.dart';
+import 'package:photos/models/device_folder.dart';
 import 'package:photos/models/public_key.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/feature_flag_service.dart';
@@ -29,8 +32,10 @@ import 'package:photos/utils/toast_util.dart';
 
 class SharingDialog extends StatefulWidget {
   final Collection collection;
+  final DevicePathCollection devicePathCollection;
 
-  const SharingDialog(this.collection, {Key key}) : super(key: key);
+  const SharingDialog(this.collection, {Key key, this.devicePathCollection})
+      : super(key: key);
 
   @override
   State<SharingDialog> createState() => _SharingDialogState();
@@ -122,13 +127,11 @@ class _SharingDialogState extends State<SharingDialog> {
                     // Add local folder in backup patch before creating
                     // sharable link
                     if (widget.collection.type == CollectionType.folder) {
-                      final path = CollectionsService.instance
-                          .decryptCollectionPath(widget.collection);
-                      if (!Configuration.instance
-                          .getPathsToBackUp()
-                          .contains(path)) {
-                        await Configuration.instance
-                            .addPathToFoldersToBeBackedUp(path);
+                      if (widget.devicePathCollection != null &&
+                          !widget.devicePathCollection.sync) {
+                        await FilesDB.instance.updateDevicePathSyncStatus(
+                          {widget.devicePathCollection.id: true},
+                        );
                         Bus.instance.fire(BackupFoldersUpdatedEvent());
                       }
                     }
@@ -409,10 +412,12 @@ class _SharingDialogState extends State<SharingDialog> {
       final collection = widget.collection;
       try {
         if (collection.type == CollectionType.folder) {
-          final path =
-              CollectionsService.instance.decryptCollectionPath(collection);
-          if (!Configuration.instance.getPathsToBackUp().contains(path)) {
-            await Configuration.instance.addPathToFoldersToBeBackedUp(path);
+          if (widget.devicePathCollection != null &&
+              !widget.devicePathCollection.sync) {
+            await FilesDB.instance.updateDevicePathSyncStatus(
+              {widget.devicePathCollection.id: true},
+            );
+            Bus.instance.fire(BackupFoldersUpdatedEvent());
           }
         }
         await CollectionsService.instance

+ 1 - 1
lib/ui/viewer/gallery/device_folder_page.dart

@@ -51,7 +51,7 @@ class DeviceFolderPage extends StatelessWidget {
           GalleryType.localFolder,
           devicePathCollection.name,
           _selectedFiles,
-          path: devicePathCollection.thumbnail.deviceFolder,
+          devicePathCollection: devicePathCollection,
         ),
       ),
       body: Stack(

+ 9 - 5
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -6,6 +6,7 @@ import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/models/collection.dart';
+import 'package:photos/models/device_folder.dart';
 import 'package:photos/models/gallery_type.dart';
 import 'package:photos/models/magic_metadata.dart';
 import 'package:photos/models/selected_files.dart';
@@ -19,7 +20,7 @@ class GalleryAppBarWidget extends StatefulWidget {
   final GalleryType type;
   final String title;
   final SelectedFiles selectedFiles;
-  final String path;
+  final DevicePathCollection devicePathCollection;
   final Collection collection;
 
   const GalleryAppBarWidget(
@@ -27,7 +28,7 @@ class GalleryAppBarWidget extends StatefulWidget {
     this.title,
     this.selectedFiles, {
     Key key,
-    this.path,
+    this.devicePathCollection,
     this.collection,
   }) : super(key: key);
 
@@ -200,8 +201,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
     try {
       if (collection == null) {
         if (widget.type == GalleryType.localFolder) {
-          collection =
-              await CollectionsService.instance.getOrCreateForPath(widget.path);
+          collection = await CollectionsService.instance
+              .getOrCreateForPath(widget.devicePathCollection.name);
         } else {
           throw Exception(
             "Cannot create a collection of type" + widget.type.toString(),
@@ -216,7 +217,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
       return showDialog<void>(
         context: context,
         builder: (BuildContext context) {
-          return SharingDialog(collection);
+          return SharingDialog(
+            collection,
+            devicePathCollection: widget.devicePathCollection,
+          );
         },
       );
     } catch (e, s) {