Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] replace system trash ID with local ID

Priyanshu Dangare81ff976daa02
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index 36149d4394..0ad18b6b78 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -25,6 +25,7 @@ import 'package:photos/module/download/file.dart';
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
import "package:photos/services/free_space/deletion_batch_runner.dart";
+import "package:photos/services/native_service.dart";
import "package:photos/services/sync/local_sync_service.dart";
import 'package:photos/services/sync/remote_sync_service.dart';
import 'package:photos/services/sync/sync_service.dart';
@@ -337,7 +338,7 @@ Future<bool> deleteFromEnteTrash(
}
}
-Future<bool> emptyTrash(BuildContext context) async {
+Future<bool> emptyTrash(BuildContext context, bool isOnEnteTrash) async {
final actionResult = await showChoiceActionSheet(
context,
title: context.strings.emptyTrashQuestion,
@@ -346,7 +347,11 @@ Future<bool> emptyTrash(BuildContext context) async {
isCritical: true,
firstButtonOnTap: () async {
try {
- await trashSyncService.emptyTrash();
+ if (isOnEnteTrash) {
+ await trashSyncService.emptyTrash();
+ } else {
+ await _emptyDeviceTrash(context);
+ }
} catch (e, s) {
_logger.info("failed empty trash", e, s);
rethrow;
@@ -1404,6 +1409,7 @@ Future<(Set<String>, Object?)> _deleteFromDeviceTrash(
for (final batch in fileIDs.chunks(batchSize)) {
final result = await PhotoManager.editor.deleteWithIds(batch);
deletedIDs.addAll(result);
+ if (result.length != batch.length) break;
}
return (deletedIDs, null);
} catch (e, s) {
@@ -1415,3 +1421,21 @@ Future<(Set<String>, Object?)> _deleteFromDeviceTrash(
}
}
}
+
+Future<void> _emptyDeviceTrash(BuildContext context) async {
+ final trash = (await NativeService.getTrash())
+ .map((f) => f.localID.toString())
+ .toList();
+ final deletedIDs = <String>{};
+ try {
+ for (final batch in trash.chunks(batchSize)) {
+ final result = await PhotoManager.editor.deleteWithIds(batch);
+ deletedIDs.addAll(result);
+ if (result.length != batch.length) break;
+ }
+ } finally {
+ if (deletedIDs.isNotEmpty) {
+ Bus.instance.fire(ForceReloadTrashPageEvent());
+ }
+ }
+}