mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-25 02:48:54 +01:00
Share files added to a shared album
This commit is contained in:
parent
d7a41161ed
commit
f1cffb0571
4 changed files with 71 additions and 4 deletions
|
@ -1,14 +1,19 @@
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
|
import 'package:nc_photos/debug_util.dart';
|
||||||
import 'package:nc_photos/entity/album.dart';
|
import 'package:nc_photos/entity/album.dart';
|
||||||
import 'package:nc_photos/entity/album/item.dart';
|
import 'package:nc_photos/entity/album/item.dart';
|
||||||
import 'package:nc_photos/entity/album/provider.dart';
|
import 'package:nc_photos/entity/album/provider.dart';
|
||||||
|
import 'package:nc_photos/entity/file.dart';
|
||||||
|
import 'package:nc_photos/entity/share.dart';
|
||||||
|
import 'package:nc_photos/use_case/create_share.dart';
|
||||||
|
import 'package:nc_photos/use_case/list_share.dart';
|
||||||
import 'package:nc_photos/use_case/preprocess_album.dart';
|
import 'package:nc_photos/use_case/preprocess_album.dart';
|
||||||
import 'package:nc_photos/use_case/update_album.dart';
|
import 'package:nc_photos/use_case/update_album.dart';
|
||||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||||
|
|
||||||
class AddToAlbum {
|
class AddToAlbum {
|
||||||
AddToAlbum(this.albumRepo);
|
const AddToAlbum(this.albumRepo, this.shareRepo);
|
||||||
|
|
||||||
/// Add a list of AlbumItems to [album]
|
/// Add a list of AlbumItems to [album]
|
||||||
Future<Album> call(
|
Future<Album> call(
|
||||||
|
@ -34,10 +39,61 @@ class AddToAlbum {
|
||||||
newItems,
|
newItems,
|
||||||
);
|
);
|
||||||
await UpdateAlbum(albumRepo)(account, newAlbum);
|
await UpdateAlbum(albumRepo)(account, newAlbum);
|
||||||
|
|
||||||
|
final newFiles =
|
||||||
|
items.whereType<AlbumFileItem>().map((e) => e.file).toList();
|
||||||
|
if (newFiles.isNotEmpty) {
|
||||||
|
await _shareFiles(account, newAlbum, newFiles);
|
||||||
|
}
|
||||||
|
|
||||||
return newAlbum;
|
return newAlbum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _shareFiles(
|
||||||
|
Account account, Album album, List<File> files) async {
|
||||||
|
try {
|
||||||
|
final albumShares =
|
||||||
|
(await ListShare(shareRepo)(account, album.albumFile!))
|
||||||
|
.where((element) => element.shareType == ShareType.user)
|
||||||
|
.map((e) => e.shareWith!)
|
||||||
|
.toSet();
|
||||||
|
if (albumShares.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (final f in files) {
|
||||||
|
try {
|
||||||
|
final fileShares = (await ListShare(shareRepo)(account, f))
|
||||||
|
.where((element) => element.shareType == ShareType.user)
|
||||||
|
.map((e) => e.shareWith!)
|
||||||
|
.toSet();
|
||||||
|
final diffShares = albumShares.difference(fileShares);
|
||||||
|
for (final s in diffShares) {
|
||||||
|
try {
|
||||||
|
await CreateUserShare(shareRepo)(account, f, s);
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout(
|
||||||
|
"[_shareFiles] Failed while CreateUserShare: ${logFilename(f.path)}",
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout(
|
||||||
|
"[_shareFiles] Failed while listing shares: ${logFilename(f.path)}",
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout(
|
||||||
|
"[_shareFiles] Failed while listing album shares: ${logFilename(album.albumFile?.path)}",
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final AlbumRepo albumRepo;
|
final AlbumRepo albumRepo;
|
||||||
|
final ShareRepo shareRepo;
|
||||||
|
|
||||||
static final _log = Logger("use_case.add_to_album.AddToAlbum");
|
static final _log = Logger("use_case.add_to_album.AddToAlbum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import 'package:nc_photos/entity/album/provider.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||||
|
import 'package:nc_photos/entity/share.dart';
|
||||||
|
import 'package:nc_photos/entity/share/data_source.dart';
|
||||||
import 'package:nc_photos/event/event.dart';
|
import 'package:nc_photos/event/event.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/iterable_extension.dart';
|
import 'package:nc_photos/iterable_extension.dart';
|
||||||
|
@ -421,7 +423,9 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
.map((e) => AlbumFileItem(file: e.file))
|
.map((e) => AlbumFileItem(file: e.file))
|
||||||
.toList();
|
.toList();
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
await AddToAlbum(albumRepo)(widget.account, value, selected);
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
|
await AddToAlbum(albumRepo, shareRepo)(
|
||||||
|
widget.account, value, selected);
|
||||||
setState(() {
|
setState(() {
|
||||||
clearSelectedItems();
|
clearSelectedItems();
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,8 @@ import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||||
import 'package:nc_photos/entity/person.dart';
|
import 'package:nc_photos/entity/person.dart';
|
||||||
|
import 'package:nc_photos/entity/share.dart';
|
||||||
|
import 'package:nc_photos/entity/share/data_source.dart';
|
||||||
import 'package:nc_photos/event/event.dart';
|
import 'package:nc_photos/event/event.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/iterable_extension.dart';
|
import 'package:nc_photos/iterable_extension.dart';
|
||||||
|
@ -371,7 +373,9 @@ class _PersonBrowserState extends State<PersonBrowser>
|
||||||
.map((e) => AlbumFileItem(file: e.file))
|
.map((e) => AlbumFileItem(file: e.file))
|
||||||
.toList();
|
.toList();
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
await AddToAlbum(albumRepo)(widget.account, value, selected);
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
|
await AddToAlbum(albumRepo, shareRepo)(
|
||||||
|
widget.account, value, selected);
|
||||||
setState(() {
|
setState(() {
|
||||||
clearSelectedItems();
|
clearSelectedItems();
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,8 @@ import 'package:nc_photos/entity/album/item.dart';
|
||||||
import 'package:nc_photos/entity/album/provider.dart';
|
import 'package:nc_photos/entity/album/provider.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
|
import 'package:nc_photos/entity/share.dart';
|
||||||
|
import 'package:nc_photos/entity/share/data_source.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/iterable_extension.dart';
|
import 'package:nc_photos/iterable_extension.dart';
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
|
@ -487,6 +489,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
assert(album.provider is AlbumStaticProvider);
|
assert(album.provider is AlbumStaticProvider);
|
||||||
try {
|
try {
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
final newItem = AlbumFileItem(file: widget.file);
|
final newItem = AlbumFileItem(file: widget.file);
|
||||||
if (AlbumStaticProvider.of(album)
|
if (AlbumStaticProvider.of(album)
|
||||||
.items
|
.items
|
||||||
|
@ -501,7 +504,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
));
|
));
|
||||||
return Future.error(ArgumentError("File already in album"));
|
return Future.error(ArgumentError("File already in album"));
|
||||||
}
|
}
|
||||||
await AddToAlbum(albumRepo)(
|
await AddToAlbum(albumRepo, shareRepo)(
|
||||||
widget.account, album, [AlbumFileItem(file: widget.file)]);
|
widget.account, album, [AlbumFileItem(file: widget.file)]);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
_log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);
|
_log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);
|
||||||
|
|
Loading…
Reference in a new issue