Merge pull request #644 from ente-io/leave_delete_state_refresh
This commit is contained in:
commit
20f8af450f
|
@ -318,17 +318,30 @@ class CollectionsService {
|
||||||
await _enteDio.delete(
|
await _enteDio.delete(
|
||||||
"/collections/v2/${collection.id}",
|
"/collections/v2/${collection.id}",
|
||||||
);
|
);
|
||||||
await _filesDB.deleteCollection(collection.id);
|
await _handleCollectionDeletion(collection);
|
||||||
final deletedCollection = collection.copyWith(isDeleted: true);
|
|
||||||
_collectionIDToCollections[collection.id] = deletedCollection;
|
|
||||||
unawaited(_db.insert([deletedCollection]));
|
|
||||||
unawaited(LocalSyncService.instance.syncAll());
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.severe('failed to trash collection', e);
|
_logger.severe('failed to trash collection', e);
|
||||||
rethrow;
|
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) {
|
Uint8List getCollectionKey(int collectionID) {
|
||||||
if (!_cachedKeys.containsKey(collectionID)) {
|
if (!_cachedKeys.containsKey(collectionID)) {
|
||||||
final collection = _collectionIDToCollections[collectionID];
|
final collection = _collectionIDToCollections[collectionID];
|
||||||
|
@ -400,8 +413,7 @@ class CollectionsService {
|
||||||
await _enteDio.post(
|
await _enteDio.post(
|
||||||
"/collections/leave/${collection.id}",
|
"/collections/leave/${collection.id}",
|
||||||
);
|
);
|
||||||
// trigger sync to fetch the latest name from server
|
await _handleCollectionDeletion(collection);
|
||||||
sync().ignore();
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
_logger.severe("failed to leave collection", e, s);
|
_logger.severe("failed to leave collection", e, s);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -998,7 +1010,7 @@ class CollectionsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _updateDB(List<Collection> collections, {int attempt = 1}) async {
|
Future _updateDB(List<Collection> collections, {int attempt = 1}) async {
|
||||||
if(collections.isEmpty) {
|
if (collections.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue