Remove shared album from collection when deleting

This commit is contained in:
Ming Ming 2021-11-29 00:07:05 +08:00
parent ba7e621588
commit 667d0395ec
4 changed files with 52 additions and 17 deletions

View file

@ -205,15 +205,19 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
// no data in this bloc, ignore // no data in this bloc, ignore
return; return;
} }
if (_isAccountOfInterest(ev.account) && if (_isAccountOfInterest(ev.account)) {
ev.destination if (ev.destination
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account)) ||
ev.file.path
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) { .startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) {
// moving from/to album dir
_refreshThrottler.trigger( _refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3), maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10, maxPendingCount: 10,
); );
} }
} }
}
void _onAlbumCreatedEvent(AlbumCreatedEvent ev) { void _onAlbumCreatedEvent(AlbumCreatedEvent ev) {
if (state is ListAlbumBlocInit) { if (state is ListAlbumBlocInit) {

View file

@ -270,16 +270,17 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
// no data in this bloc, ignore // no data in this bloc, ignore
return; return;
} }
// from pending dir to album dir if (_isAccountOfInterest(ev.account)) {
if (_isAccountOfInterest(ev.account) && if (ev.destination.startsWith(remote_storage_util
ev.file.path.startsWith( .getRemotePendingSharedAlbumsDir(ev.account)) &&
remote_storage_util.getRemotePendingSharedAlbumsDir(ev.account)) && ev.file.path.startsWith(remote_storage_util
ev.destination .getRemotePendingSharedAlbumsDir(ev.account))) {
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) { // moving from/to pending dir
add(_ListSharingBlocPendingSharedAlbumMoved( add(_ListSharingBlocPendingSharedAlbumMoved(
ev.account, ev.file, ev.destination)); ev.account, ev.file, ev.destination));
} }
} }
}
Future<List<ListSharingItem>> _query(ListSharingBlocQuery ev) async { Future<List<ListSharingItem>> _query(ListSharingBlocQuery ev) async {
final fileRepo = FileRepo(FileCachedDataSource(AppDb())); final fileRepo = FileRepo(FileCachedDataSource(AppDb()));

View file

@ -0,0 +1,23 @@
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/use_case/move.dart';
/// Unimport a shared album from the library
class UnimportSharedAlbum {
const UnimportSharedAlbum(this.fileRepo);
Future<void> call(Account account, Album album) async {
final destination =
"${remote_storage_util.getRemotePendingSharedAlbumsDir(account)}/${album.albumFile!.filename}";
await Move(fileRepo)(
account,
album.albumFile!,
destination,
shouldCreateMissingDir: true,
);
}
final FileRepo fileRepo;
}

View file

@ -22,6 +22,7 @@ import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart'; import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/remove_album.dart'; import 'package:nc_photos/use_case/remove_album.dart';
import 'package:nc_photos/use_case/unimport_shared_album.dart';
import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util; import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
import 'package:nc_photos/widget/album_importer.dart'; import 'package:nc_photos/widget/album_importer.dart';
import 'package:nc_photos/widget/album_search_delegate.dart'; import 'package:nc_photos/widget/album_search_delegate.dart';
@ -405,8 +406,14 @@ class _HomeAlbumsState extends State<HomeAlbums>
final failures = <Album>[]; final failures = <Album>[];
for (final a in selectedAlbums) { for (final a in selectedAlbums) {
try { try {
if (a.albumFile?.isOwned(widget.account.username) == true) {
// delete owned albums
await RemoveAlbum(fileRepo, albumRepo, shareRepo, Pref())( await RemoveAlbum(fileRepo, albumRepo, shareRepo, Pref())(
widget.account, a); widget.account, a);
} else {
// remove shared albums from collection
await UnimportSharedAlbum(fileRepo)(widget.account, a);
}
} catch (e, stackTrace) { } catch (e, stackTrace) {
_log.shout( _log.shout(
"[_onSelectionDeletePressed] Failed while removing album: '${a.name}'", "[_onSelectionDeletePressed] Failed while removing album: '${a.name}'",