Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix bug in deleting from collaborative album

laurenspriemc713e1c22b67
diff --git a/mobile/lib/services/collections_service.dart b/mobile/lib/services/collections_service.dart
index 3f00218e32..301655490a 100644
--- a/mobile/lib/services/collections_service.dart
+++ b/mobile/lib/services/collections_service.dart
@@ -388,6 +388,16 @@ class CollectionsService {
.toList();
}
+ List<int> getAllOwnedCollectionIDs() {
+ final int userID = _config.getUserID()!;
+ return _collectionIDToCollections.values
+ .where(
+ (c) => !c.isDeleted && c.isOwner(userID),
+ )
+ .map((e) => e.id)
+ .toList();
+ }
+
SharedCollections getSharedCollections() {
final List<Collection> outgoing = [];
final List<Collection> incoming = [];
diff --git a/mobile/lib/services/sync/trash_sync_service.dart b/mobile/lib/services/sync/trash_sync_service.dart
index 53c94f16c7..b3cf1db6a9 100644
--- a/mobile/lib/services/sync/trash_sync_service.dart
+++ b/mobile/lib/services/sync/trash_sync_service.dart
@@ -7,6 +7,7 @@ import "package:ente_crypto/ente_crypto.dart";
import 'package:logging/logging.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/core/event_bus.dart';
+import "package:photos/db/files_db.dart";
import 'package:photos/db/trash_db.dart';
import 'package:photos/events/collection_updated_event.dart';
import 'package:photos/events/force_reload_trash_page_event.dart';
@@ -17,6 +18,7 @@ import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/trash_file.dart';
import 'package:photos/models/ignored_file.dart';
import "package:photos/models/metadata/file_magic.dart";
+import "package:photos/services/collections_service.dart";
import 'package:photos/services/ignored_files_service.dart';
import "package:photos/utils/file_key.dart";
import 'package:shared_preferences/shared_preferences.dart';
@@ -108,10 +110,34 @@ class TrashSyncService {
Future<void> trashFilesOnServer(List<TrashRequest> trashRequestItems) async {
final includedFileIDs = <int>{};
final uniqueItems = <TrashRequest>[];
+ final ownedCollectionIDs =
+ CollectionsService.instance.getAllOwnedCollectionIDs();
for (final item in trashRequestItems) {
if (!includedFileIDs.contains(item.fileID)) {
- uniqueItems.add(item);
- includedFileIDs.add(item.fileID);
+ // Check if the collectionID in the request is owned by the user
+ if (ownedCollectionIDs.contains(item.collectionID)) {
+ uniqueItems.add(item);
+ includedFileIDs.add(item.fileID);
+ } else {
+ // If not owned, use a different owned collectionID
+ final fileCollectionIDs =
+ await FilesDB.instance.getAllCollectionIDsOfFile(item.fileID);
+ bool foundAnotherOwnedCollection = false;
+ for (final collectionID in fileCollectionIDs) {
+ if (ownedCollectionIDs.contains(collectionID)) {
+ final newItem = TrashRequest(item.fileID, collectionID);
+ uniqueItems.add(newItem);
+ includedFileIDs.add(item.fileID);
+ foundAnotherOwnedCollection = true;
+ break;
+ }
+ }
+ if (!foundAnotherOwnedCollection) {
+ _logger.severe(
+ "File ${item.fileID} is not owned by the user and has no other owned collection",
+ );
+ }
+ }
}
}
final requestData = <String, dynamic>{};