Make sure that the right files are updated while applying a diff

This commit is contained in:
Vishnu Mohandas 2020-11-14 16:17:28 +05:30
parent b42c84cf42
commit 8334ec809e

View file

@ -231,17 +231,17 @@ class SyncService {
file.generatedID = existingFiles[0].generatedID;
await _db.update(file);
} else {
bool wasUpdatedInExistingCollection = false;
bool foundMatchingCollection = false;
for (final existingFile in existingFiles) {
if (file.collectionID == existingFile.collectionID) {
if (file.collectionID == existingFile.collectionID &&
file.uploadedFileID == existingFile.uploadedFileID) {
foundMatchingCollection = true;
file.generatedID = existingFile.generatedID;
wasUpdatedInExistingCollection = true;
await _db.update(file);
break;
}
}
if (wasUpdatedInExistingCollection) {
await _db.update(file);
} else {
if (!foundMatchingCollection) {
// Added to a new collection
await _db.insert(file);
}