diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart index f8c96f084..8ae69c2cc 100644 --- a/lib/db/files_db.dart +++ b/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) { diff --git a/lib/services/sync_service.dart b/lib/services/sync_service.dart index 84d3e9ddc..e28144908 100644 --- a/lib/services/sync_service.dart +++ b/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(); + _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(); for (final uploadedFileID in updatedFileIDs) { if (_syncStopRequested) { _syncStopRequested = false; @@ -286,10 +292,12 @@ class SyncService { Future _storeDiff(List 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; diff --git a/lib/utils/file_downloader.dart b/lib/utils/file_downloader.dart index 77f147c37..329e461c0 100644 --- a/lib/utils/file_downloader.dart +++ b/lib/utils/file_downloader.dart @@ -18,7 +18,7 @@ class DiffFetcher { final _logger = Logger("FileDownloader"); final _dio = Network.instance.getDio(); - Future> getEncryptedFilesDiff( + Future 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(), 0); } - return files; }); } } + +class Diff { + final List updatedFiles; + final int fetchCount; + + Diff(this.updatedFiles, this.fetchCount); +} diff --git a/pubspec.lock b/pubspec.lock index ce13f81e5..bef490ab8 100644 --- a/pubspec.lock +++ b/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: diff --git a/pubspec.yaml b/pubspec.yaml index 3bd9f0285..89b1434ab 100644 --- a/pubspec.yaml +++ b/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 diff --git a/thirdparty/flutter_photo_manager b/thirdparty/flutter_photo_manager new file mode 160000 index 000000000..ea7dcc4f2 --- /dev/null +++ b/thirdparty/flutter_photo_manager @@ -0,0 +1 @@ +Subproject commit ea7dcc4f2a5769d46881ae6b661ab8f253a5c9a2