mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Can only remove owned items from album
This commit is contained in:
parent
31baba7a8a
commit
0eef1a88cc
2 changed files with 50 additions and 12 deletions
|
@ -284,10 +284,11 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
PopupMenuButton<_SelectionMenuOption>(
|
||||
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: _SelectionMenuOption.removeFromAlbum,
|
||||
child: Text(L10n.global().removeFromAlbumTooltip),
|
||||
),
|
||||
if (_canRemoveSelection)
|
||||
PopupMenuItem(
|
||||
value: _SelectionMenuOption.removeFromAlbum,
|
||||
child: Text(L10n.global().removeFromAlbumTooltip),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: _SelectionMenuOption.download,
|
||||
child: Text(L10n.global().downloadTooltip),
|
||||
|
@ -424,8 +425,14 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
|
||||
Future<void> _onSelectionRemovePressed() async {
|
||||
final selectedIndexes =
|
||||
selectedListItems.map((e) => (e as _ListItem).index).toList();
|
||||
final selectedItems = _sortedItems.takeIndex(selectedIndexes).toList();
|
||||
selectedListItems.whereType<_ListItem>().map((e) => e.index).toList();
|
||||
final selectedItems = _sortedItems
|
||||
.takeIndex(selectedIndexes)
|
||||
// can only remove owned files
|
||||
.where((element) =>
|
||||
_album!.albumFile!.isOwned(widget.account.username) == true ||
|
||||
element.addedBy == widget.account.username)
|
||||
.toList();
|
||||
setState(() {
|
||||
clearSelectedItems();
|
||||
});
|
||||
|
@ -437,8 +444,8 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb(), Pref())(
|
||||
widget.account, _album!, selectedItems);
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().removeSelectedFromAlbumSuccessNotification(
|
||||
selectedIndexes.length)),
|
||||
content: Text(L10n.global()
|
||||
.removeSelectedFromAlbumSuccessNotification(selectedItems.length)),
|
||||
duration: k.snackBarDurationNormal,
|
||||
));
|
||||
} catch (e, stackTrace) {
|
||||
|
@ -772,6 +779,17 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
widget.account, album, items);
|
||||
}
|
||||
|
||||
bool get _canRemoveSelection {
|
||||
if (_album!.albumFile!.isOwned(widget.account.username) == true) {
|
||||
return true;
|
||||
}
|
||||
final selectedIndexes =
|
||||
selectedListItems.whereType<_ListItem>().map((e) => e.index).toList();
|
||||
final selectedItemsIt = _sortedItems.takeIndex(selectedIndexes);
|
||||
return selectedItemsIt
|
||||
.any((item) => item.addedBy == widget.account.username);
|
||||
}
|
||||
|
||||
static List<AlbumItem> _getAlbumItemsOf(Album a) =>
|
||||
AlbumStaticProvider.of(a).items;
|
||||
|
||||
|
|
|
@ -123,10 +123,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
if (widget.album != null &&
|
||||
widget.album!.albumFile?.isOwned(widget.account.username) ==
|
||||
true &&
|
||||
widget.album!.provider is AlbumStaticProvider)
|
||||
if (_canRemoveFromAlbum)
|
||||
_DetailPaneButton(
|
||||
icon: Icons.remove_outlined,
|
||||
label: L10n.global().removeFromAlbumTooltip,
|
||||
|
@ -460,6 +457,27 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
return product;
|
||||
}
|
||||
|
||||
bool _checkCanRemoveFromAlbum() {
|
||||
if (widget.album == null ||
|
||||
widget.album!.provider is! AlbumStaticProvider) {
|
||||
return false;
|
||||
}
|
||||
if (widget.album!.albumFile?.isOwned(widget.account.username) == true) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
final thisItem = AlbumStaticProvider.of(widget.album!)
|
||||
.items
|
||||
.whereType<AlbumFileItem>()
|
||||
.firstWhere(
|
||||
(element) => element.file.compareServerIdentity(widget.file));
|
||||
if (thisItem.addedBy == widget.account.username) {
|
||||
return true;
|
||||
}
|
||||
} catch (_) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
late DateTime _dateTime;
|
||||
// EXIF data
|
||||
String? _model;
|
||||
|
@ -469,6 +487,8 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
int? _isoSpeedRatings;
|
||||
Tuple2<double, double>? _gps;
|
||||
|
||||
late final bool _canRemoveFromAlbum = _checkCanRemoveFromAlbum();
|
||||
|
||||
static final _log =
|
||||
Logger("widget.viewer_detail_pane._ViewerDetailPaneState");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue