From 29077216048ce042fe289045fd595a75b3202510 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 15 Nov 2022 15:47:01 +0530 Subject: [PATCH 1/2] Fix state refresh bug during delete album --- lib/services/collections_service.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 1b012a4fa..d4d5f6695 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -321,6 +321,15 @@ class CollectionsService { await _filesDB.deleteCollection(collection.id); final deletedCollection = collection.copyWith(isDeleted: true); _collectionIDToCollections[collection.id] = deletedCollection; + Bus.instance.fire( + CollectionUpdatedEvent( + collection.id, + [], + "delete_Collection", + type: EventType.deletedFromRemote, + ), + ); + sync().ignore(); unawaited(_db.insert([deletedCollection])); unawaited(LocalSyncService.instance.syncAll()); } catch (e) { @@ -998,7 +1007,7 @@ class CollectionsService { } Future _updateDB(List collections, {int attempt = 1}) async { - if(collections.isEmpty) { + if (collections.isEmpty) { return; } try { From 734afbfbb175351218930bc2476132ee8f16ae01 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 15 Nov 2022 15:50:26 +0530 Subject: [PATCH 2/2] Fix state refresh issue on leave album --- lib/services/collections_service.dart | 35 +++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index d4d5f6695..3c266fc40 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -318,26 +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; - Bus.instance.fire( - CollectionUpdatedEvent( - collection.id, - [], - "delete_Collection", - type: EventType.deletedFromRemote, - ), - ); - sync().ignore(); - unawaited(_db.insert([deletedCollection])); - unawaited(LocalSyncService.instance.syncAll()); + await _handleCollectionDeletion(collection); } catch (e) { _logger.severe('failed to trash collection', e); rethrow; } } + Future _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, + [], + "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]; @@ -409,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;