mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-24 16:04:43 +01:00
Regression: album cover is gone after unsetting one for a dynamic album
This commit is contained in:
parent
02107c7150
commit
c62af9941b
9 changed files with 47 additions and 15 deletions
|
@ -76,6 +76,9 @@ class CollectionItemsController {
|
||||||
return _dataStreamController.stream;
|
return _dataStreamController.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Peek the stream and return the current value
|
||||||
|
CollectionItemStreamData peekStream() => _dataStreamController.stream.value;
|
||||||
|
|
||||||
/// Add list of [files] to [collection]
|
/// Add list of [files] to [collection]
|
||||||
Future<void> addFiles(List<FileDescriptor> files) async {
|
Future<void> addFiles(List<FileDescriptor> files) async {
|
||||||
final isInited = _isDataStreamInited;
|
final isInited = _isDataStreamInited;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:copy_with/copy_with.dart';
|
import 'package:copy_with/copy_with.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
|
@ -163,6 +164,9 @@ class CollectionsController {
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final c = await _mutex.protect(() async {
|
final c = await _mutex.protect(() async {
|
||||||
|
final found = _dataStreamController.value.data.firstWhereOrNull(
|
||||||
|
(ev) => ev.collection.compareIdentity(collection));
|
||||||
|
final item = found?.controller.peekStream();
|
||||||
return await EditCollection(_c)(
|
return await EditCollection(_c)(
|
||||||
account,
|
account,
|
||||||
collection,
|
collection,
|
||||||
|
@ -170,6 +174,7 @@ class CollectionsController {
|
||||||
items: items,
|
items: items,
|
||||||
itemSort: itemSort,
|
itemSort: itemSort,
|
||||||
cover: cover,
|
cover: cover,
|
||||||
|
knownItems: (item?.items.isEmpty ?? true) ? null : item!.items,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
_updateCollection(c, items);
|
_updateCollection(c, items);
|
||||||
|
|
|
@ -77,26 +77,25 @@ class AlbumAutoCoverProvider extends AlbumCoverProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FileDescriptor? getCoverByItems(List<AlbumItem> items) {
|
||||||
|
return items
|
||||||
|
.whereType<AlbumFileItem>()
|
||||||
|
.map((e) => e.file)
|
||||||
|
.where((element) =>
|
||||||
|
file_util.isSupportedFormat(element) &&
|
||||||
|
(element.hasPreview ?? false))
|
||||||
|
.sorted(compareFileDateTimeDescending)
|
||||||
|
.firstOrNull;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => _$toString();
|
String toString() => _$toString();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileDescriptor? getCover(Album album) {
|
FileDescriptor? getCover(Album album) {
|
||||||
if (coverFile == null) {
|
if (coverFile == null) {
|
||||||
try {
|
// use the latest file as cover
|
||||||
// use the latest file as cover
|
return getCoverByItems(AlbumStaticProvider.of(album).items);
|
||||||
return AlbumStaticProvider.of(album)
|
|
||||||
.items
|
|
||||||
.whereType<AlbumFileItem>()
|
|
||||||
.map((e) => e.file)
|
|
||||||
.where((element) =>
|
|
||||||
file_util.isSupportedFormat(element) &&
|
|
||||||
(element.hasPreview ?? false))
|
|
||||||
.sorted(compareFileDateTimeDescending)
|
|
||||||
.first;
|
|
||||||
} catch (_) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return coverFile;
|
return coverFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ abstract class CollectionAdapter {
|
||||||
List<CollectionItem>? items,
|
List<CollectionItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<CollectionItem>? knownItems,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Remove [items] from this collection and return the removed count
|
/// Remove [items] from this collection and return the removed count
|
||||||
|
|
|
@ -79,6 +79,7 @@ class CollectionAlbumAdapter implements CollectionAdapter {
|
||||||
List<CollectionItem>? items,
|
List<CollectionItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<CollectionItem>? knownItems,
|
||||||
}) async {
|
}) async {
|
||||||
assert(name != null || items != null || itemSort != null || cover != null);
|
assert(name != null || items != null || itemSort != null || cover != null);
|
||||||
final newItems = items?.run((items) => items
|
final newItems = items?.run((items) => items
|
||||||
|
@ -106,6 +107,10 @@ class CollectionAlbumAdapter implements CollectionAdapter {
|
||||||
items: newItems,
|
items: newItems,
|
||||||
itemSort: itemSort,
|
itemSort: itemSort,
|
||||||
cover: cover,
|
cover: cover,
|
||||||
|
knownItems: knownItems
|
||||||
|
?.whereType<AlbumAdaptedCollectionItem>()
|
||||||
|
.map((e) => e.albumItem)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
return collection.copyWith(
|
return collection.copyWith(
|
||||||
name: name,
|
name: name,
|
||||||
|
|
|
@ -77,6 +77,7 @@ class CollectionNcAlbumAdapter implements CollectionAdapter {
|
||||||
List<CollectionItem>? items,
|
List<CollectionItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<CollectionItem>? knownItems,
|
||||||
}) async {
|
}) async {
|
||||||
assert(name != null);
|
assert(name != null);
|
||||||
if (items != null || itemSort != null || cover != null) {
|
if (items != null || itemSort != null || cover != null) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ mixin CollectionReadOnlyAdapter implements CollectionAdapter {
|
||||||
List<CollectionItem>? items,
|
List<CollectionItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<CollectionItem>? knownItems,
|
||||||
}) {
|
}) {
|
||||||
throw UnsupportedError("Operation not supported");
|
throw UnsupportedError("Operation not supported");
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class EditAlbum {
|
||||||
List<AlbumItem>? items,
|
List<AlbumItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<AlbumItem>? knownItems,
|
||||||
}) async {
|
}) async {
|
||||||
_log.info(
|
_log.info(
|
||||||
"[call] Edit album ${album.name}, name: $name, items: $items, itemSort: $itemSort, cover: $cover");
|
"[call] Edit album ${album.name}, name: $name, items: $items, itemSort: $itemSort, cover: $cover");
|
||||||
|
@ -49,8 +50,9 @@ class EditAlbum {
|
||||||
}
|
}
|
||||||
if (cover != null) {
|
if (cover != null) {
|
||||||
if (cover.obj == null) {
|
if (cover.obj == null) {
|
||||||
|
final coverFile = _getCoverFile(knownItems);
|
||||||
newAlbum = newAlbum.copyWith(
|
newAlbum = newAlbum.copyWith(
|
||||||
coverProvider: const AlbumAutoCoverProvider(),
|
coverProvider: AlbumAutoCoverProvider(coverFile: coverFile),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
newAlbum = newAlbum.copyWith(
|
newAlbum = newAlbum.copyWith(
|
||||||
|
@ -65,5 +67,13 @@ class EditAlbum {
|
||||||
return newAlbum;
|
return newAlbum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDescriptor? _getCoverFile(List<AlbumItem>? items) {
|
||||||
|
if (items?.isEmpty ?? true) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return AlbumAutoCoverProvider.getCoverByItems(items!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final DiContainer _c;
|
final DiContainer _c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,11 @@ class EditCollection {
|
||||||
/// - Sort [items] (set [items] and/or [itemSort])
|
/// - Sort [items] (set [items] and/or [itemSort])
|
||||||
/// - Set album [cover]
|
/// - Set album [cover]
|
||||||
///
|
///
|
||||||
|
/// Optionally you may provide a list of known collection items. If
|
||||||
|
/// [knownItems] is not null, it may be used as a hint for the implementors
|
||||||
|
/// when updating the underlying collection (e.g., setting the latest item as
|
||||||
|
/// cover image)
|
||||||
|
///
|
||||||
/// \* To add files to a collection, use [AddFileToCollection] instead
|
/// \* To add files to a collection, use [AddFileToCollection] instead
|
||||||
Future<Collection> call(
|
Future<Collection> call(
|
||||||
Account account,
|
Account account,
|
||||||
|
@ -27,12 +32,14 @@ class EditCollection {
|
||||||
List<CollectionItem>? items,
|
List<CollectionItem>? items,
|
||||||
CollectionItemSort? itemSort,
|
CollectionItemSort? itemSort,
|
||||||
OrNull<FileDescriptor>? cover,
|
OrNull<FileDescriptor>? cover,
|
||||||
|
List<CollectionItem>? knownItems,
|
||||||
}) =>
|
}) =>
|
||||||
CollectionAdapter.of(_c, account, collection).edit(
|
CollectionAdapter.of(_c, account, collection).edit(
|
||||||
name: name,
|
name: name,
|
||||||
items: items,
|
items: items,
|
||||||
itemSort: itemSort,
|
itemSort: itemSort,
|
||||||
cover: cover,
|
cover: cover,
|
||||||
|
knownItems: knownItems,
|
||||||
);
|
);
|
||||||
|
|
||||||
final DiContainer _c;
|
final DiContainer _c;
|
||||||
|
|
Loading…
Add table
Reference in a new issue