2021-04-10 06:28:12 +02:00
|
|
|
import 'package:event_bus/event_bus.dart';
|
|
|
|
import 'package:kiwi/kiwi.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/entity/album.dart';
|
2021-09-25 18:22:19 +02:00
|
|
|
import 'package:nc_photos/entity/album/item.dart';
|
|
|
|
import 'package:nc_photos/entity/album/provider.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/event/event.dart';
|
|
|
|
|
|
|
|
class UpdateAlbum {
|
|
|
|
UpdateAlbum(this.albumRepo);
|
|
|
|
|
|
|
|
Future<void> call(Account account, Album album) async {
|
2021-09-25 18:22:19 +02:00
|
|
|
final provider = album.provider;
|
|
|
|
if (provider is AlbumStaticProvider) {
|
|
|
|
await albumRepo.update(
|
|
|
|
account,
|
|
|
|
album.copyWith(
|
|
|
|
provider: provider.copyWith(
|
|
|
|
items: _minimizeItems(provider.items),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await albumRepo.update(account, album);
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
KiwiContainer().resolve<EventBus>().fire(AlbumUpdatedEvent(account, album));
|
|
|
|
}
|
|
|
|
|
2021-09-25 18:22:19 +02:00
|
|
|
List<AlbumItem> _minimizeItems(List<AlbumItem> items) {
|
|
|
|
return items.map((e) => e is AlbumFileItem ? e.minimize() : e).toList();
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
final AlbumRepo albumRepo;
|
|
|
|
}
|