Explorar o código

Merge branch 'master' into ui_refresh

Vishnu Mohandas %!s(int64=4) %!d(string=hai) anos
pai
achega
97fbdceae4

+ 1 - 3
lib/db/files_db.dart

@@ -425,18 +425,16 @@ class FilesDB {
     String title,
     String deviceFolder,
     int creationTime,
-    int modificationTime,
   ) async {
     final db = await instance.database;
     final rows = await db.query(
       table,
       where: '''$columnTitle=? AND $columnDeviceFolder=? AND 
-          $columnCreationTime=? AND $columnModificationTime=?''',
+          $columnCreationTime=?''',
       whereArgs: [
         title,
         deviceFolder,
         creationTime,
-        modificationTime,
       ],
     );
     if (rows.isNotEmpty) {

+ 21 - 7
lib/services/sync_service.dart

@@ -203,12 +203,15 @@ class SyncService {
       _collectionsService.getCollectionSyncTime(collectionID),
       _diffLimit,
     );
-    if (diff.isNotEmpty) {
-      await _storeDiff(diff, collectionID);
-      _logger.info("Updated files in collection " + collectionID.toString());
+    if (diff.updatedFiles.isNotEmpty) {
+      await _storeDiff(diff.updatedFiles, collectionID);
+      _logger.info("Updated " +
+          diff.updatedFiles.length.toString() +
+          " files in collection " +
+          collectionID.toString());
       FileRepository.instance.reloadFiles();
       Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
-      if (diff.length == _diffLimit) {
+      if (diff.fetchCount == _diffLimit) {
         return await _fetchEncryptedFilesDiff(collectionID);
       }
     }
@@ -222,9 +225,11 @@ class SyncService {
       filesToBeUploaded
           .removeWhere((element) => element.fileType == FileType.video);
     }
-    final futures = List<Future>();
+    _logger.info(
+        filesToBeUploaded.length.toString() + " new files to be uploaded.");
 
     final updatedFileIDs = await _db.getUploadedFileIDsToBeUpdated();
+    _logger.info(updatedFileIDs.length.toString() + " files updated.");
 
     int uploadCounter = 0;
     final totalUploads = filesToBeUploaded.length + updatedFileIDs.length;
@@ -233,6 +238,7 @@ class SyncService {
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparing_for_upload));
     }
 
+    final futures = List<Future>();
     for (final uploadedFileID in updatedFileIDs) {
       if (_syncStopRequested) {
         _syncStopRequested = false;
@@ -286,10 +292,12 @@ class SyncService {
 
   Future _storeDiff(List<File> diff, int collectionID) async {
     for (File file in diff) {
-      final existingFiles = await _db.getMatchingFiles(file.title,
-          file.deviceFolder, file.creationTime, file.modificationTime);
+      final existingFiles = await _db.getMatchingFiles(
+          file.title, file.deviceFolder, file.creationTime);
       if (existingFiles == null) {
         // File uploaded from a different device
+        _logger.info("Could not find a matching file for " +
+            file.uploadedFileID.toString());
         file.localID = null;
         await _db.insert(file);
       } else {
@@ -300,6 +308,12 @@ class SyncService {
             existingFiles.length == 1 && existingFiles[0].collectionID == null;
         if (wasUploadedOnAPreviousInstallation) {
           file.generatedID = existingFiles[0].generatedID;
+          if (file.modificationTime != existingFiles[0].modificationTime) {
+            // File was updated since the app was uninstalled
+            _logger.info("Updated since last installation: " +
+                file.uploadedFileID.toString());
+            file.updationTime = null;
+          }
           await _db.update(file);
         } else {
           bool foundMatchingCollection = false;

+ 10 - 2
lib/utils/file_downloader.dart

@@ -18,7 +18,7 @@ class DiffFetcher {
   final _logger = Logger("FileDownloader");
   final _dio = Network.instance.getDio();
 
-  Future<List<File>> getEncryptedFilesDiff(
+  Future<Diff> getEncryptedFilesDiff(
       int collectionID, int sinceTime, int limit) async {
     return _dio
         .get(
@@ -75,10 +75,18 @@ class DiffFetcher {
               file.applyMetadata(metadata);
               files.add(file);
             }
+            return Diff(files, diff.length);
           } else {
             Bus.instance.fire(RemoteSyncEvent(false));
+            return Diff(List<File>(), 0);
           }
-          return files;
         });
   }
 }
+
+class Diff {
+  final List<File> updatedFiles;
+  final int fetchCount;
+
+  Diff(this.updatedFiles, this.fetchCount);
+}

+ 4 - 4
pubspec.lock

@@ -497,10 +497,10 @@ packages:
   photo_manager:
     dependency: "direct main"
     description:
-      name: photo_manager
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.6.0-dev.7"
+      path: "thirdparty/flutter_photo_manager"
+      relative: true
+    source: path
+    version: "0.6.0-dev.8"
   photo_view:
     dependency: "direct main"
     description:

+ 2 - 1
pubspec.yaml

@@ -23,7 +23,8 @@ dependencies:
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^0.1.2
-  photo_manager: ^0.6.0-dev.7
+  photo_manager:
+    path: thirdparty/flutter_photo_manager
   provider: ^3.1.0
   sqflite: ^1.3.0
   path_provider: ^1.6.5

+ 1 - 0
thirdparty/flutter_photo_manager

@@ -0,0 +1 @@
+Subproject commit ea7dcc4f2a5769d46881ae6b661ab8f253a5c9a2