nc-photos/app/lib/use_case/delete_local.dart

35 lines
1 KiB
Dart
Raw Normal View History

2022-05-05 20:34:30 +02:00
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/local_file.dart';
import 'package:nc_photos/event/event.dart';
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2022-05-05 20:34:30 +02:00
2022-12-16 16:01:04 +01:00
part 'delete_local.g.dart';
@npLog
2022-05-05 20:34:30 +02:00
class DeleteLocal {
DeleteLocal(this._c) : assert(require(_c));
static bool require(DiContainer c) =>
DiContainer.has(c, DiType.localFileRepo);
Future<void> call(
List<LocalFile> files, {
LocalFileOnFailureListener? onFailure,
}) async {
final deleted = List.of(files);
await _c.localFileRepo.deleteFiles(files, onFailure: (f, e, stackTrace) {
deleted.removeWhere((d) => d.compareIdentity(f));
onFailure?.call(f, e, stackTrace);
});
if (deleted.isNotEmpty) {
_log.info("[call] Deleted ${deleted.length} files successfully");
KiwiContainer().resolve<EventBus>().fire(LocalFileDeletedEvent(deleted));
}
}
final DiContainer _c;
}