mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 14:56:20 +01:00
Better way to compare if 2 Files are the same file on server
This commit is contained in:
parent
743f9b79e1
commit
d7a41161ed
3 changed files with 21 additions and 6 deletions
|
@ -8,11 +8,13 @@ import 'package:nc_photos/or_null.dart';
|
||||||
import 'package:nc_photos/type.dart';
|
import 'package:nc_photos/type.dart';
|
||||||
|
|
||||||
List<AlbumItem> makeDistinctAlbumItems(List<AlbumItem> items) =>
|
List<AlbumItem> makeDistinctAlbumItems(List<AlbumItem> items) =>
|
||||||
items.distinctIf(
|
items.distinctIf((a, b) {
|
||||||
(a, b) =>
|
if (a is! AlbumFileItem || b is! AlbumFileItem) {
|
||||||
a is AlbumFileItem &&
|
return false;
|
||||||
b is AlbumFileItem &&
|
} else {
|
||||||
a.file.path == b.file.path, (a) {
|
return a.file.compareServerIdentity(b.file);
|
||||||
|
}
|
||||||
|
}, (a) {
|
||||||
if (a is AlbumFileItem) {
|
if (a is AlbumFileItem) {
|
||||||
return a.file.path.hashCode;
|
return a.file.path.hashCode;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -469,6 +469,18 @@ extension FileExtension on File {
|
||||||
|
|
||||||
String get filename => path_util.basename(path);
|
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");
|
static final _log = Logger("entity.file.FileExtension");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -491,7 +491,8 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
if (AlbumStaticProvider.of(album)
|
if (AlbumStaticProvider.of(album)
|
||||||
.items
|
.items
|
||||||
.whereType<AlbumFileItem>()
|
.whereType<AlbumFileItem>()
|
||||||
.containsIf(newItem, (a, b) => a.file.path == b.file.path)) {
|
.containsIf(
|
||||||
|
newItem, (a, b) => a.file.compareServerIdentity(b.file))) {
|
||||||
// already added, do nothing
|
// already added, do nothing
|
||||||
_log.info("[_addToAlbum] File already in album: ${widget.file.path}");
|
_log.info("[_addToAlbum] File already in album: ${widget.file.path}");
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
|
Loading…
Reference in a new issue