Fix not updating bestDateTime when updating file property

This commit is contained in:
Ming Ming 2022-10-29 19:05:23 +08:00
parent 054d6bbae5
commit 037fbd845d
3 changed files with 23 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/ci_string.dart';
import 'package:nc_photos/entity/exif.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/json_util.dart' as json_util;
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/string_extension.dart';
@ -568,11 +569,11 @@ class File with EquatableMixin implements FileDescriptor {
}
extension FileExtension on File {
DateTime get bestDateTime =>
overrideDateTime ??
metadata?.exif?.dateTimeOriginal ??
lastModified ??
DateTime.now().toUtc();
DateTime get bestDateTime => file_util.getBestDateTime(
overrideDateTime: overrideDateTime,
dateTimeOriginal: metadata?.exif?.dateTimeOriginal,
lastModified: lastModified,
);
bool isOwned(CiString userId) => ownerId == null || ownerId == userId;
}

View file

@ -469,6 +469,17 @@ class FileSqliteDbDataSource implements FileDataSource {
: sql.Value(overrideDateTime.obj),
isFavorite:
favorite == null ? const sql.Value.absent() : sql.Value(favorite),
bestDateTime: overrideDateTime == null && metadata == null
? const sql.Value.absent()
: sql.Value(file_util.getBestDateTime(
overrideDateTime: overrideDateTime == null
? f.overrideDateTime
: overrideDateTime.obj,
dateTimeOriginal: metadata == null
? f.metadata?.exif?.dateTimeOriginal
: metadata.obj?.exif?.dateTimeOriginal,
lastModified: f.lastModified,
)),
);
await (db.update(db.accountFiles)
..where((t) => t.rowId.equals(rowIds.accountFileRowId)))

View file

@ -96,6 +96,12 @@ bool isMissingMetadata(File file) =>
isSupportedImageFormat(file) &&
(file.metadata == null || file.location == null);
DateTime getBestDateTime({
DateTime? overrideDateTime,
DateTime? dateTimeOriginal,
DateTime? lastModified,
}) => overrideDateTime ?? dateTimeOriginal ?? lastModified ?? DateTime.now().toUtc();
final supportedFormatMimes = [
"image/jpeg",
"image/png",