Update photo when it was updated on remote
This commit is contained in:
parent
464829e650
commit
d196284dfd
2 changed files with 30 additions and 3 deletions
|
@ -149,6 +149,20 @@ class PhotoDB {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Photo> getMatchingRemotePhoto(int uploadedFileId) async {
|
||||
final db = await instance.database;
|
||||
final rows = await db.query(
|
||||
table,
|
||||
where: '$columnUploadedFileId=?',
|
||||
whereArgs: [uploadedFileId],
|
||||
);
|
||||
if (rows.isNotEmpty) {
|
||||
return _getPhotoFromRow(rows[0]);
|
||||
} else {
|
||||
throw ("No matching photo found");
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> updatePhoto(
|
||||
int generatedId, int uploadedId, String remotePath, int updateTimestamp,
|
||||
[String thumbnailPath]) async {
|
||||
|
|
|
@ -57,9 +57,22 @@ class FolderSharingService {
|
|||
} catch (e) {
|
||||
// Folder has never been synced
|
||||
}
|
||||
var photos = await getDiff(folder.id, lastSyncTimestamp, _diffLimit);
|
||||
await PhotoDB.instance.insertPhotos(photos);
|
||||
if (photos.length == _diffLimit) {
|
||||
var diff = await getDiff(folder.id, lastSyncTimestamp, _diffLimit);
|
||||
for (Photo photo in diff) {
|
||||
try {
|
||||
var existingPhoto =
|
||||
await PhotoDB.instance.getMatchingRemotePhoto(photo.uploadedFileId);
|
||||
await PhotoDB.instance.updatePhoto(
|
||||
existingPhoto.generatedId,
|
||||
photo.uploadedFileId,
|
||||
photo.remotePath,
|
||||
photo.updateTimestamp,
|
||||
photo.thumbnailPath);
|
||||
} catch (e) {
|
||||
await PhotoDB.instance.insertPhoto(photo);
|
||||
}
|
||||
}
|
||||
if (diff.length == _diffLimit) {
|
||||
await syncDiff(folder);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue