Fix deletion behavior

This commit is contained in:
Vishnu Mohandas 2020-11-01 13:07:23 +05:30
parent e3329805ac
commit 49af595268
3 changed files with 19 additions and 1 deletions

View file

@ -120,6 +120,9 @@ class FilesDB {
final db = await instance.database;
final results = await db.query(table,
where: '$columnGeneratedID = ?', whereArgs: [generatedID]);
if (results.isEmpty) {
return null;
}
return _convertToFiles(results)[0];
}
@ -386,6 +389,15 @@ class FilesDB {
);
}
Future<int> deleteLocalFile(String localID) async {
final db = await instance.database;
return db.delete(
table,
where: '$columnLocalID =?',
whereArgs: [localID],
);
}
Future<int> deleteFromCollection(int uploadedFileID, int collectionID) async {
final db = await instance.database;
return db.delete(

View file

@ -218,7 +218,11 @@ class SyncService {
.getOrCreateForPath(file.deviceFolder))
.id;
final existingFile = await _db.getFile(file.generatedID);
if (existingFile == null) {
// File was deleted locally while being uploaded
await _deleteFileOnServer(file.uploadedFileID);
continue;
}
if (existingFile.uploadedFileID != null) {
// The file was uploaded outside this loop
// Eg: Addition to an album or favorites

View file

@ -37,6 +37,8 @@ Future<void> deleteFiles(List<File> files) async {
if (file.uploadedFileID != null) {
hasUploadedFiles = true;
await FilesDB.instance.markForDeletion(file.uploadedFileID);
} else {
await FilesDB.instance.deleteLocalFile(file.localID);
}
}
await PhotoManager.editor.deleteWithIds(localIDs);