feat(mobile): use app without storage permission (#5014)

* feat(mobile): use app without storage permission

* address review feedback
This commit is contained in:
Fynn Petersen-Frey 2023-11-14 21:30:27 +01:00 committed by GitHub
parent 8f3ed8ba8e
commit 5145c33ed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 134 additions and 232 deletions

View file

@ -90,6 +90,9 @@ class SyncService {
Future<bool> syncNewAssetToDb(Asset newAsset) =>
_lock.run(() => _syncNewAssetToDb(newAsset));
Future<bool> removeAllLocalAlbumsAndAssets() =>
_lock.run(_removeAllLocalAlbumsAndAssets);
// private methods:
/// Syncs users from the server to the local database
@ -756,6 +759,23 @@ class SyncService {
await a.assetCountAsync !=
(await _db.eTags.getById(a.eTagKeyAssetCount))?.assetCount;
}
Future<bool> _removeAllLocalAlbumsAndAssets() async {
try {
final assets = await _db.assets.where().localIdIsNotNull().findAll();
final (toDelete, toUpdate) =
_handleAssetRemoval(assets, [], remote: false);
await _db.writeTxn(() async {
await _db.assets.deleteAll(toDelete);
await _db.assets.putAll(toUpdate);
await _db.albums.where().localIdIsNotNull().deleteAll();
});
return true;
} catch (e) {
_log.severe("Failed to remove all local albums and assets: $e");
return false;
}
}
}
/// Returns a triple(toAdd, toUpdate, toRemove)