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'; class DeleteLocal { DeleteLocal(this._c) : assert(require(_c)); static bool require(DiContainer c) => DiContainer.has(c, DiType.localFileRepo); Future call( List 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().fire(LocalFileDeletedEvent(deleted)); } } final DiContainer _c; static final _log = Logger("use_case.delete_local.DeleteLocal"); }