No longer propagate property updates to album

This commit is contained in:
Ming Ming 2021-06-14 21:52:29 +08:00
parent f4faa1ed1f
commit 30ec7dab7a
5 changed files with 4 additions and 69 deletions

View file

@ -89,15 +89,12 @@ class ListAlbumBlocInconsistent extends ListAlbumBlocState {
class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
ListAlbumBloc() : super(ListAlbumBlocInit()) {
_filePropertyUpdatedListener =
AppEventListener<FilePropertyUpdatedEvent>(_onFilePropertyUpdatedEvent);
_albumUpdatedListener =
AppEventListener<AlbumUpdatedEvent>(_onAlbumUpdatedEvent);
_fileRemovedListener =
AppEventListener<FileRemovedEvent>(_onFileRemovedEvent);
_albumCreatedListener =
AppEventListener<AlbumCreatedEvent>(_onAlbumCreatedEvent);
_filePropertyUpdatedListener.begin();
_albumUpdatedListener.begin();
_fileRemovedListener.begin();
_albumCreatedListener.begin();
@ -115,7 +112,6 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
@override
close() {
_filePropertyUpdatedListener.end();
_albumUpdatedListener.end();
_fileRemovedListener.end();
_albumCreatedListener.end();
@ -160,18 +156,6 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
yield ListAlbumBlocInconsistent(state.account, state.albums);
}
void _onFilePropertyUpdatedEvent(FilePropertyUpdatedEvent ev) {
if (!ev.hasAnyProperties([FilePropertyUpdatedEvent.propMetadata])) {
// not interested
return;
}
if (state is ListAlbumBlocInit) {
// no data in this bloc, ignore
return;
}
add(_ListAlbumBlocExternalEvent());
}
void _onAlbumUpdatedEvent(AlbumUpdatedEvent ev) {
if (state is ListAlbumBlocInit) {
// no data in this bloc, ignore
@ -224,7 +208,6 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
}
}
AppEventListener<FilePropertyUpdatedEvent> _filePropertyUpdatedListener;
AppEventListener<AlbumUpdatedEvent> _albumUpdatedListener;
AppEventListener<FileRemovedEvent> _fileRemovedListener;
AppEventListener<AlbumCreatedEvent> _albumCreatedListener;

View file

@ -1,7 +1,6 @@
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/connectivity_util.dart' as connectivity_util;
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/exif.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
@ -52,8 +51,7 @@ class UpdateMissingMetadata {
exif: exif,
);
final updateOp = UpdateProperty(FileRepo(FileCachedDataSource()),
AlbumRepo(AlbumCachedDataSource()));
final updateOp = UpdateProperty(FileRepo(FileCachedDataSource()));
await updateOp(
account,
file,

View file

@ -2,15 +2,12 @@ import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/use_case/list_album.dart';
import 'package:nc_photos/use_case/update_album.dart';
class UpdateProperty {
UpdateProperty(this.fileRepo, this.albumRepo);
UpdateProperty(this.fileRepo);
Future<void> call(
Account account,
@ -34,12 +31,6 @@ class UpdateProperty {
metadata: metadata,
isArchived: isArchived,
);
await _cleanUpAlbums(
account,
file,
metadata: metadata,
isArchived: isArchived,
);
int properties = 0;
if (metadata != null) {
@ -54,41 +45,7 @@ class UpdateProperty {
.fire(FilePropertyUpdatedEvent(account, file, properties));
}
Future<void> _cleanUpAlbums(
Account account,
File file, {
OrNull<Metadata> metadata,
OrNull<bool> isArchived,
}) async {
final albums = await ListAlbum(fileRepo, albumRepo)(account);
for (final a in albums) {
try {
if (a.items.any((element) =>
element is AlbumFileItem && element.file.path == file.path)) {
final newItems = a.items.map((e) {
if (e is AlbumFileItem && e.file.path == file.path) {
return AlbumFileItem(
file: e.file.copyWith(
metadata: metadata,
isArchived: isArchived,
),
);
} else {
return e;
}
}).toList();
await UpdateAlbum(albumRepo)(account, a.copyWith(items: newItems));
}
} catch (e, stacktrace) {
_log.shout(
"[_cleanUpAlbums] Failed while updating album", e, stacktrace);
// continue to next album
}
}
}
final FileRepo fileRepo;
final AlbumRepo albumRepo;
static final _log = Logger("use_case.update_property.UpdateProperty");
}

View file

@ -7,7 +7,6 @@ import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api_util.dart' as api_util;
import 'package:nc_photos/bloc/scan_dir.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
@ -216,11 +215,10 @@ class _ArchiveViewerState extends State<ArchiveViewer>
clearSelectedItems();
});
final fileRepo = FileRepo(FileCachedDataSource());
final albumRepo = AlbumRepo(AlbumCachedDataSource());
final failures = <File>[];
for (final f in selectedFiles) {
try {
await UpdateProperty(fileRepo, albumRepo)
await UpdateProperty(fileRepo)
.updateIsArchived(widget.account, f, false);
} catch (e, stacktrace) {
_log.shout(

View file

@ -408,11 +408,10 @@ class _HomePhotosState extends State<HomePhotos>
clearSelectedItems();
});
final fileRepo = FileRepo(FileCachedDataSource());
final albumRepo = AlbumRepo(AlbumCachedDataSource());
final failures = <File>[];
for (final f in selectedFiles) {
try {
await UpdateProperty(fileRepo, albumRepo)
await UpdateProperty(fileRepo)
.updateIsArchived(widget.account, f, true);
} catch (e, stacktrace) {
_log.shout(