mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 09:16:19 +01:00
f01c64a155
This help reduce the file size
50 lines
1.7 KiB
Dart
50 lines
1.7 KiB
Dart
import 'package:logging/logging.dart';
|
|
import 'package:nc_photos/account.dart';
|
|
import 'package:nc_photos/entity/album.dart';
|
|
import 'package:nc_photos/entity/album/item.dart';
|
|
import 'package:nc_photos/entity/album/sort_provider.dart';
|
|
import 'package:nc_photos/use_case/update_album.dart';
|
|
import 'package:nc_photos/use_case/update_album_time.dart';
|
|
import 'package:nc_photos/use_case/update_auto_album_cover.dart';
|
|
|
|
class UpdateAlbumWithActualItems {
|
|
UpdateAlbumWithActualItems(this.albumRepo);
|
|
|
|
/// Update, if necessary, [album] after resynced/populated with actual items
|
|
///
|
|
/// If [albumRepo] is null, the modified album will not be saved
|
|
Future<Album> call(
|
|
Account account, Album album, List<AlbumItem> items) async {
|
|
final sortedItems =
|
|
const AlbumTimeSortProvider(isAscending: false).sort(items);
|
|
|
|
bool shouldUpdate = false;
|
|
final albumUpdatedCover =
|
|
UpdateAutoAlbumCover().updateWithSortedItems(album, sortedItems);
|
|
if (!identical(albumUpdatedCover, album)) {
|
|
_log.info("[call] Update album cover");
|
|
shouldUpdate = true;
|
|
}
|
|
album = albumUpdatedCover;
|
|
|
|
final albumUpdatedTime =
|
|
UpdateAlbumTime().updateWithSortedItems(album, sortedItems);
|
|
if (!identical(albumUpdatedTime, album)) {
|
|
_log.info(
|
|
"[call] Update album time: ${album.provider.latestItemTime} -> ${albumUpdatedTime.provider.latestItemTime}");
|
|
shouldUpdate = true;
|
|
}
|
|
album = albumUpdatedTime;
|
|
|
|
if (albumRepo != null && shouldUpdate) {
|
|
_log.info("[call] Persist album");
|
|
await UpdateAlbum(albumRepo!)(account, album);
|
|
}
|
|
return album;
|
|
}
|
|
|
|
final AlbumRepo? albumRepo;
|
|
|
|
static final _log = Logger(
|
|
"use_case.update_album_with_actual_items.UpdateAlbumWithActualItems");
|
|
}
|