瀏覽代碼

Merge branch 'rewrite_device_sync' into rewrite_device_sync_remote

Neeraj Gupta 2 年之前
父節點
當前提交
1ad387979e

+ 11 - 1
lib/db/files_db.dart

@@ -493,7 +493,7 @@ class FilesDB {
       whereArgs: [ownerID, visibility],
       distinct: true,
     );
-    Set<int> collectionIDsOfHiddenFiles = {};
+    final Set<int> collectionIDsOfHiddenFiles = {};
     for (var result in results) {
       collectionIDsOfHiddenFiles.add(result['collection_id']);
     }
@@ -960,6 +960,16 @@ class FilesDB {
     );
   }
 
+  Future<int> updateLocalIDForUploaded(int uploadedID, String localID) async {
+    final db = await instance.database;
+    return await db.update(
+      table,
+      {columnLocalID: localID},
+      where: '$columnUploadedFileID = ? AND $columnLocalID IS NULL',
+      whereArgs: [uploadedID],
+    );
+  }
+
   Future<int> delete(int uploadedFileID) async {
     final db = await instance.database;
     return db.delete(

+ 1 - 1
lib/services/feature_flag_service.dart

@@ -94,7 +94,7 @@ class FeatureFlagService {
   }
 
   bool isInternalUserOrDebugBuild() {
-    String email = Configuration.instance.getEmail();
+    final String email = Configuration.instance.getEmail();
     return (email != null && email.endsWith("@ente.io")) || kDebugMode;
   }
 

+ 18 - 8
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -134,8 +134,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
           child: IconButton(
             icon: Icon(Icons.adaptive.share),
             onPressed: () async {
-              if (FeatureFlagService.instance.isInternalUserOrDebugBuild() &&
-                  await _collectionHasHiddenFiles(widget.collection.id)) {
+              final bool showHiddenWarning =
+                  await _shouldShowHiddenFilesWarning(widget.collection);
+              if (showHiddenWarning) {
                 final choice = await showChoiceDialog(
                   context,
                   'Share hidden items?',
@@ -145,12 +146,11 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
                   secondActionColor:
                       Theme.of(context).colorScheme.defaultTextColor,
                 );
-                if (choice == DialogUserChoice.secondChoice) {
-                  _showShareCollectionDialog();
+                if (choice != DialogUserChoice.secondChoice) {
+                  return;
                 }
-              } else {
-                _showShareCollectionDialog();
               }
+              await _showShareCollectionDialog();
             },
           ),
         ),
@@ -250,11 +250,21 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
     }
   }
 
-  Future<bool> _collectionHasHiddenFiles(int collectionID) async {
+  Future<bool> _shouldShowHiddenFilesWarning(Collection collection) async {
+    // collection can be null for device folders which are not marked for
+    // back up
+    if (!FeatureFlagService.instance.isInternalUserOrDebugBuild() ||
+        collection == null) {
+      return false;
+    }
+    // collection is already shared
+    if (collection.sharees.isNotEmpty || collection.publicURLs.isNotEmpty) {
+      return false;
+    }
     final collectionIDsWithHiddenFiles =
         await FilesDB.instance.getCollectionIDsOfHiddenFiles(
       Configuration.instance.getUserID(),
     );
-    return collectionIDsWithHiddenFiles.contains(collectionID);
+    return collectionIDsWithHiddenFiles.contains(collection.id);
   }
 }

+ 1 - 3
lib/ui/viewer/gallery/gallery_overlay_widget.dart

@@ -268,9 +268,7 @@ class _OverlayWidgetState extends State<OverlayWidget> {
       if (widget.type == GalleryType.localFolder ||
           widget.type == GalleryType.localAll) {
         msg = "Upload";
-        iconData = Platform.isAndroid
-            ? Icons.cloud_upload
-            : CupertinoIcons.cloud_upload;
+        iconData = Icons.cloud_upload_outlined;
       }
       actions.add(
         Tooltip(

+ 31 - 5
lib/utils/file_uploader.dart

@@ -508,9 +508,8 @@ class FileUploader {
     if (existingUploadedFiles?.isEmpty ?? true) {
       // continueUploading this file
       return Tuple2(false, fileToUpload);
-    } else {
-      debugPrint("Found some matches");
     }
+
     // case a
     final File sameLocalSameCollection = existingUploadedFiles.firstWhere(
       (e) =>
@@ -518,12 +517,19 @@ class FileUploader {
       orElse: () => null,
     );
     if (sameLocalSameCollection != null) {
-      debugPrint(
+      _logger.fine(
         "sameLocalSameCollection: \n toUpload  ${fileToUpload.tag()} "
         "\n existing: ${sameLocalSameCollection.tag()}",
       );
       // should delete the fileToUploadEntry
       await FilesDB.instance.deleteByGeneratedID(fileToUpload.generatedID);
+
+      Bus.instance.fire(
+        LocalPhotosUpdatedEvent(
+          [fileToUpload],
+          type: EventType.deletedFromEverywhere, //
+        ),
+      );
       return Tuple2(true, sameLocalSameCollection);
     }
 
@@ -536,13 +542,23 @@ class FileUploader {
     if (fileMissingLocalButSameCollection != null) {
       // update the local id of the existing file and delete the fileToUpload
       // entry
-      debugPrint(
+      _logger.fine(
         "fileMissingLocalButSameCollection: \n toUpload  ${fileToUpload.tag()} "
         "\n existing: ${fileMissingLocalButSameCollection.tag()}",
       );
       fileMissingLocalButSameCollection.localID = fileToUpload.localID;
-      await FilesDB.instance.insert(fileMissingLocalButSameCollection);
+      // set localID for the given uploadedID across collections
+      await FilesDB.instance.updateLocalIDForUploaded(
+        fileMissingLocalButSameCollection.uploadedFileID,
+        fileToUpload.localID,
+      );
       await FilesDB.instance.deleteByGeneratedID(fileToUpload.generatedID);
+      Bus.instance.fire(
+        LocalPhotosUpdatedEvent(
+          [fileToUpload],
+          type: EventType.deletedFromEverywhere, //
+        ),
+      );
       return Tuple2(true, fileMissingLocalButSameCollection);
     }
 
@@ -565,6 +581,16 @@ class FileUploader {
       );
       return Tuple2(true, linkedFile);
     }
+    final Set<String> matchLocalIDs = existingUploadedFiles
+        .where(
+          (e) => e.localID != null,
+        )
+        .map((e) => e.localID)
+        .toSet();
+    _logger.fine(
+      "Found hashMatch but probably with diff localIDs "
+      "$matchLocalIDs",
+    );
     // case e
     return Tuple2(false, fileToUpload);
   }