diff --git a/lib/entity/album/item.dart b/lib/entity/album/item.dart index 387dc827..b5006fad 100644 --- a/lib/entity/album/item.dart +++ b/lib/entity/album/item.dart @@ -8,11 +8,13 @@ import 'package:nc_photos/or_null.dart'; import 'package:nc_photos/type.dart'; List makeDistinctAlbumItems(List items) => - items.distinctIf( - (a, b) => - a is AlbumFileItem && - b is AlbumFileItem && - a.file.path == b.file.path, (a) { + items.distinctIf((a, b) { + if (a is! AlbumFileItem || b is! AlbumFileItem) { + return false; + } else { + return a.file.compareServerIdentity(b.file); + } + }, (a) { if (a is AlbumFileItem) { return a.file.path.hashCode; } else { diff --git a/lib/entity/file.dart b/lib/entity/file.dart index d78a8e4d..1e46089e 100644 --- a/lib/entity/file.dart +++ b/lib/entity/file.dart @@ -469,6 +469,18 @@ extension FileExtension on File { String get filename => path_util.basename(path); + /// Compare the server identity of two Files + /// + /// Return true if two Files point to the same file on server. Be careful that + /// this does NOT mean that the two Files are identical + bool compareServerIdentity(File other) { + if (fileId != null && other.fileId != null) { + return fileId == other.fileId; + } else { + return path == other.path; + } + } + static final _log = Logger("entity.file.FileExtension"); } diff --git a/lib/widget/viewer_detail_pane.dart b/lib/widget/viewer_detail_pane.dart index c73ca8c4..82d24161 100644 --- a/lib/widget/viewer_detail_pane.dart +++ b/lib/widget/viewer_detail_pane.dart @@ -491,7 +491,8 @@ class _ViewerDetailPaneState extends State { if (AlbumStaticProvider.of(album) .items .whereType() - .containsIf(newItem, (a, b) => a.file.path == b.file.path)) { + .containsIf( + newItem, (a, b) => a.file.compareServerIdentity(b.file))) { // already added, do nothing _log.info("[_addToAlbum] File already in album: ${widget.file.path}"); SnackBarManager().showSnackBar(SnackBar(