From 6ad4a71f233938bd84bbf95973877876b1cd2959 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:57:39 +0530 Subject: [PATCH] refactor --- lib/models/file/extensions/file_props.dart | 4 ++++ lib/ui/viewer/file/zoomable_live_image.dart | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/models/file/extensions/file_props.dart b/lib/models/file/extensions/file_props.dart index 41ac9813a..9881ac6d6 100644 --- a/lib/models/file/extensions/file_props.dart +++ b/lib/models/file/extensions/file_props.dart @@ -7,4 +7,8 @@ extension FilePropsExtn on EnteFile { bool get isMotionPhoto => pubMagicMetadata?.mvi != null; bool get isLiveOrMotionPhoto => isLivePhoto || isMotionPhoto; + + bool isOwner(int userID) => (ownerID == null) || (ownerID! == userID); + + bool canEditMetaInfo(int userID) => isUploaded && isOwner(userID); } diff --git a/lib/ui/viewer/file/zoomable_live_image.dart b/lib/ui/viewer/file/zoomable_live_image.dart index 699a26d4e..9d6f69a10 100644 --- a/lib/ui/viewer/file/zoomable_live_image.dart +++ b/lib/ui/viewer/file/zoomable_live_image.dart @@ -182,10 +182,12 @@ class _ZoomableLiveImageState extends State final motionPhoto = MotionPhotos(imageFile.path); final index = await motionPhoto.getMotionVideoIndex(); if (index != null) { - if (widget.enteFile.pubMagicMetadata?.mvi == null && - (widget.enteFile.ownerID ?? 0) == Configuration.instance.getUserID()!) { + // Update the metadata if it is not updated + if (!_enteFile.isMotionPhoto && + _enteFile + .canEditMetaInfo(Configuration.instance.getUserID()!)) { FileMagicService.instance.updatePublicMagicMetadata( - [widget.enteFile], + [_enteFile], {motionVideoIndexKey: index.start}, ).ignore(); }