mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-12 20:47:42 +01:00
Update collection items when file updated in files controller
This commit is contained in:
parent
1c999f6fab
commit
c588ab9c6d
8 changed files with 96 additions and 26 deletions
|
@ -327,18 +327,25 @@ class CollectionItemsController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await _mutex.protect(() async {
|
await _mutex.protect(() async {
|
||||||
final newItems = _dataStreamController.value.items.where((e) {
|
final newItems = _dataStreamController.value.items
|
||||||
if (e is CollectionFileItem) {
|
.map((e) {
|
||||||
return ev.dataMap.containsKey(e.file.fdId);
|
if (e is CollectionFileItem) {
|
||||||
} else {
|
final file = ev.dataMap[e.file.fdId];
|
||||||
return true;
|
if (file == null) {
|
||||||
}
|
// removed
|
||||||
}).toList();
|
return null;
|
||||||
if (newItems.length != _dataStreamController.value.items.length) {
|
} else {
|
||||||
_dataStreamController.addWithValue((value) => value.copyWith(
|
return e.copyWith(file: file);
|
||||||
items: newItems,
|
}
|
||||||
));
|
} else {
|
||||||
}
|
return e;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.whereNotNull()
|
||||||
|
.toList();
|
||||||
|
_dataStreamController.addWithValue((value) => value.copyWith(
|
||||||
|
items: newItems,
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:copy_with/copy_with.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
@ -73,6 +74,7 @@ abstract class AlbumItem with EquatableMixin {
|
||||||
static final _log = _$AlbumItemNpLog.log;
|
static final _log = _$AlbumItemNpLog.log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@genCopyWith
|
||||||
@toString
|
@toString
|
||||||
class AlbumFileItem extends AlbumItem {
|
class AlbumFileItem extends AlbumItem {
|
||||||
AlbumFileItem({
|
AlbumFileItem({
|
||||||
|
@ -110,20 +112,6 @@ class AlbumFileItem extends AlbumItem {
|
||||||
addedBy == other.addedBy &&
|
addedBy == other.addedBy &&
|
||||||
addedAt == other.addedAt;
|
addedAt == other.addedAt;
|
||||||
|
|
||||||
AlbumFileItem copyWith({
|
|
||||||
CiString? addedBy,
|
|
||||||
DateTime? addedAt,
|
|
||||||
FileDescriptor? file,
|
|
||||||
CiString? ownerId,
|
|
||||||
}) {
|
|
||||||
return AlbumFileItem(
|
|
||||||
addedBy: addedBy ?? this.addedBy,
|
|
||||||
addedAt: addedAt ?? this.addedAt,
|
|
||||||
file: file ?? this.file,
|
|
||||||
ownerId: ownerId ?? this.ownerId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
...super.props,
|
...super.props,
|
||||||
|
|
|
@ -2,6 +2,47 @@
|
||||||
|
|
||||||
part of 'item.dart';
|
part of 'item.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// CopyWithLintRuleGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
// ignore_for_file: library_private_types_in_public_api, duplicate_ignore
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// CopyWithGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
abstract class $AlbumFileItemCopyWithWorker {
|
||||||
|
AlbumFileItem call(
|
||||||
|
{CiString? addedBy,
|
||||||
|
DateTime? addedAt,
|
||||||
|
FileDescriptor? file,
|
||||||
|
CiString? ownerId});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _$AlbumFileItemCopyWithWorkerImpl
|
||||||
|
implements $AlbumFileItemCopyWithWorker {
|
||||||
|
_$AlbumFileItemCopyWithWorkerImpl(this.that);
|
||||||
|
|
||||||
|
@override
|
||||||
|
AlbumFileItem call(
|
||||||
|
{dynamic addedBy, dynamic addedAt, dynamic file, dynamic ownerId}) {
|
||||||
|
return AlbumFileItem(
|
||||||
|
addedBy: addedBy as CiString? ?? that.addedBy,
|
||||||
|
addedAt: addedAt as DateTime? ?? that.addedAt,
|
||||||
|
file: file as FileDescriptor? ?? that.file,
|
||||||
|
ownerId: ownerId as CiString? ?? that.ownerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final AlbumFileItem that;
|
||||||
|
}
|
||||||
|
|
||||||
|
extension $AlbumFileItemCopyWith on AlbumFileItem {
|
||||||
|
$AlbumFileItemCopyWithWorker get copyWith => _$copyWith;
|
||||||
|
$AlbumFileItemCopyWithWorker get _$copyWith =>
|
||||||
|
_$AlbumFileItemCopyWithWorkerImpl(this);
|
||||||
|
}
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// NpLogGenerator
|
// NpLogGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
|
@ -8,6 +8,10 @@ abstract class CollectionItem {
|
||||||
abstract class CollectionFileItem implements CollectionItem {
|
abstract class CollectionFileItem implements CollectionItem {
|
||||||
const CollectionFileItem();
|
const CollectionFileItem();
|
||||||
|
|
||||||
|
CollectionFileItem copyWith({
|
||||||
|
FileDescriptor? file,
|
||||||
|
});
|
||||||
|
|
||||||
FileDescriptor get file;
|
FileDescriptor get file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,15 @@ class CollectionFileItemAlbumAdapter extends CollectionFileItem
|
||||||
with AlbumAdaptedCollectionItem {
|
with AlbumAdaptedCollectionItem {
|
||||||
const CollectionFileItemAlbumAdapter(this.item);
|
const CollectionFileItemAlbumAdapter(this.item);
|
||||||
|
|
||||||
|
@override
|
||||||
|
CollectionFileItemAlbumAdapter copyWith({
|
||||||
|
FileDescriptor? file,
|
||||||
|
}) {
|
||||||
|
return CollectionFileItemAlbumAdapter(item.copyWith(
|
||||||
|
file: file,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => _$toString();
|
String toString() => _$toString();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,13 @@ part 'basic_item.g.dart';
|
||||||
class BasicCollectionFileItem implements CollectionFileItem {
|
class BasicCollectionFileItem implements CollectionFileItem {
|
||||||
const BasicCollectionFileItem(this.file);
|
const BasicCollectionFileItem(this.file);
|
||||||
|
|
||||||
|
@override
|
||||||
|
BasicCollectionFileItem copyWith({
|
||||||
|
FileDescriptor? file,
|
||||||
|
}) {
|
||||||
|
return BasicCollectionFileItem(file ?? this.file);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => _$toString();
|
String toString() => _$toString();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,13 @@ part 'nc_album_item_adapter.g.dart';
|
||||||
class CollectionFileItemNcAlbumItemAdapter extends CollectionFileItem {
|
class CollectionFileItemNcAlbumItemAdapter extends CollectionFileItem {
|
||||||
const CollectionFileItemNcAlbumItemAdapter(this.item, [this.localFile]);
|
const CollectionFileItemNcAlbumItemAdapter(this.item, [this.localFile]);
|
||||||
|
|
||||||
|
@override
|
||||||
|
CollectionFileItemNcAlbumItemAdapter copyWith({
|
||||||
|
FileDescriptor? file,
|
||||||
|
}) {
|
||||||
|
return CollectionFileItemNcAlbumItemAdapter(item, file ?? this.file);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => _$toString();
|
String toString() => _$toString();
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,13 @@ abstract class NewCollectionItem implements CollectionItem {}
|
||||||
class NewCollectionFileItem implements CollectionFileItem, NewCollectionItem {
|
class NewCollectionFileItem implements CollectionFileItem, NewCollectionItem {
|
||||||
const NewCollectionFileItem(this.file);
|
const NewCollectionFileItem(this.file);
|
||||||
|
|
||||||
|
@override
|
||||||
|
NewCollectionFileItem copyWith({
|
||||||
|
FileDescriptor? file,
|
||||||
|
}) {
|
||||||
|
return NewCollectionFileItem(file ?? this.file);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => _$toString();
|
String toString() => _$toString();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue