Merge pull request #644 from ente-io/leave_delete_state_refresh

This commit is contained in:
Vishnu Mohandas 2022-11-15 16:00:51 +05:30 committed by GitHub
commit 20f8af450f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -318,17 +318,30 @@ class CollectionsService {
await _enteDio.delete(
"/collections/v2/${collection.id}",
);
await _filesDB.deleteCollection(collection.id);
final deletedCollection = collection.copyWith(isDeleted: true);
_collectionIDToCollections[collection.id] = deletedCollection;
unawaited(_db.insert([deletedCollection]));
unawaited(LocalSyncService.instance.syncAll());
await _handleCollectionDeletion(collection);
} catch (e) {
_logger.severe('failed to trash collection', e);
rethrow;
}
}
Future<void> _handleCollectionDeletion(Collection collection) async {
await _filesDB.deleteCollection(collection.id);
final deletedCollection = collection.copyWith(isDeleted: true);
_collectionIDToCollections[collection.id] = deletedCollection;
Bus.instance.fire(
CollectionUpdatedEvent(
collection.id,
<File>[],
"delete_collection",
type: EventType.deletedFromRemote,
),
);
sync().ignore();
unawaited(_db.insert([deletedCollection]));
unawaited(LocalSyncService.instance.syncAll());
}
Uint8List getCollectionKey(int collectionID) {
if (!_cachedKeys.containsKey(collectionID)) {
final collection = _collectionIDToCollections[collectionID];
@ -400,8 +413,7 @@ class CollectionsService {
await _enteDio.post(
"/collections/leave/${collection.id}",
);
// trigger sync to fetch the latest name from server
sync().ignore();
await _handleCollectionDeletion(collection);
} catch (e, s) {
_logger.severe("failed to leave collection", e, s);
rethrow;
@ -998,7 +1010,7 @@ class CollectionsService {
}
Future _updateDB(List<Collection> collections, {int attempt = 1}) async {
if(collections.isEmpty) {
if (collections.isEmpty) {
return;
}
try {