Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat(photos): update memory lane share flow

AmanRajSinghMourya5462e110792c
diff --git a/mobile/apps/photos/lib/models/ml/face/box.dart b/mobile/apps/photos/lib/models/ml/face/box.dart
index 3c0e7e124d..eac8de2646 100644
--- a/mobile/apps/photos/lib/models/ml/face/box.dart
+++ b/mobile/apps/photos/lib/models/ml/face/box.dart
@@ -12,7 +12,7 @@ class FaceBox {
final double width;
final double height;
- FaceBox({
+ const FaceBox({
required this.x,
required this.y,
required this.width,
diff --git a/mobile/apps/photos/lib/models/ml/face/detection.dart b/mobile/apps/photos/lib/models/ml/face/detection.dart
index 766e326fae..dc57defbec 100644
--- a/mobile/apps/photos/lib/models/ml/face/detection.dart
+++ b/mobile/apps/photos/lib/models/ml/face/detection.dart
@@ -23,7 +23,7 @@ class Detection {
// empty box
Detection.empty()
- : box = FaceBox(
+ : box = const FaceBox(
x: 0,
y: 0,
width: 0,
diff --git a/mobile/apps/photos/lib/services/memory_share_service.dart b/mobile/apps/photos/lib/services/memory_share_service.dart
index 604a98b3f9..64bea3112d 100644
--- a/mobile/apps/photos/lib/services/memory_share_service.dart
+++ b/mobile/apps/photos/lib/services/memory_share_service.dart
@@ -1,20 +1,25 @@
import 'dart:convert';
+import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:dio/dio.dart';
import 'package:ente_crypto/ente_crypto.dart';
-import "package:logging/logging.dart";
+import 'package:logging/logging.dart';
import 'package:photos/core/network/network.dart';
-import "package:photos/db/files_db.dart";
+import 'package:photos/db/files_db.dart';
import 'package:photos/db/memory_shares_db.dart';
-import "package:photos/gateways/entity/models/type.dart";
+import 'package:photos/db/ml/db.dart';
+import 'package:photos/gateways/entity/models/type.dart';
import 'package:photos/models/api/memory_share/memory_share.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/memories/memory.dart';
-import "package:photos/models/metadata/file_magic.dart";
+import 'package:photos/models/memory_lane/memory_lane_models.dart';
+import 'package:photos/models/metadata/file_magic.dart';
+import 'package:photos/models/ml/face/face.dart';
import 'package:photos/service_locator.dart' show entityService;
+import 'package:photos/utils/face_crop_util.dart';
import 'package:photos/utils/file_key.dart';
class MemoryShareService {
@@ -115,6 +120,77 @@ class MemoryShareService {
}
}
+ Future<(String, int)> _createMemoryLaneLink({
+ required List<_MemoryLaneShareItem> laneItems,
+ required Map<String, dynamic> metadata,
+ String? memoryHash,
+ }) async {
+ List<_MemoryLaneShareItem> uploadedItems = const [];
+ try {
+ uploadedItems =
+ laneItems.where((item) => item.file.uploadedFileID != null).toList();
+ final resolvedMemoryHash = memoryHash ?? _getMemoryLaneHash(metadata);
+ final secretPayload = await _prepareShareSecret();
+ final shareKey = secretPayload.shareKey;
+ final metadataBytes =
+ Uint8List.fromList(utf8.encode(jsonEncode(metadata)));
+ final compressedMetadataBytes = Uint8List.fromList(
+ GZipCodec().encode(metadataBytes),
+ );
+ final encryptedMetadata = CryptoUtil.encryptSync(
+ compressedMetadataBytes,
+ shareKey,
+ );
+
+ final fileItems = <Map<String, dynamic>>[];
+ for (var i = 0; i < uploadedItems.length; i++) {
+ final item = uploadedItems[i];
+ final file = item.file;
+ final fileKey = getFileKey(file);
+ final reEncryptedKey = CryptoUtil.encryptSync(fileKey, shareKey);
+ fileItems.add({
+ 'fileID': file.uploadedFileID,
+ 'position': i,
+ 'encryptedKey': CryptoUtil.bin2base64(reEncryptedKey.encryptedData!),
+ 'keyDecryptionNonce': CryptoUtil.bin2base64(reEncryptedKey.nonce!),
+ });
+ }
+
+ final requestData = {
+ 'type': MemoryShareType.lane.name,
+ 'metadataCipher':
+ CryptoUtil.bin2base64(encryptedMetadata.encryptedData!),
+ 'metadataNonce': CryptoUtil.bin2base64(encryptedMetadata.nonce!),
+ ...secretPayload.metadata(),
+ 'memoryHash': resolvedMemoryHash,
+ 'files': fileItems,
+ };
+
+ final response = await _enteDio.post('/memory-share', data: requestData);
+ final memoryShare = MemoryShare.fromJson(response.data['memoryShare']);
+
+ final shareUrl = "${memoryShare.url}#${secretPayload.secret}";
+ final uniqueUploadedFileCount = uploadedItems
+ .map((item) => item.file.uploadedFileID)
+ .whereType<int>()
+ .toSet()
+ .length;
+ final localShare = memoryShare.copyWith(
+ url: shareUrl,
+ memoryHash: resolvedMemoryHash,
+ previewUploadedFileID: uploadedItems.first.file.uploadedFileID,
+ fileCount: uniqueUploadedFileCount,
+ );
+ await _db.upsert(localShare);
+ _updateMemoryShareCache(localShare);
+
+ return (shareUrl, memoryShare.id);
+ } catch (e, s) {
+ _logger.severe("Failed to create memory lane link", e, s);
+ rethrow;
+ }
+ }
+
Future<List<MemoryShare>> listMemoryShares() async {
try {
final response = await _enteDio.get('/memory-share');
@@ -247,7 +323,10 @@ class MemoryShareService {
shareKey,
CryptoUtil.base642bin(metadataNonce),
);
- final parsed = jsonDecode(utf8.decode(decryptedMetadata));
+ final parsed = _decodeMemoryShareMetadata(
+ decryptedMetadata,
+ share.type,
+ );
if (parsed is! Map<String, dynamic>) {
return null;
}
@@ -523,6 +602,59 @@ class MemoryShareService {
}
}
+ Future<(String, int)> getOrCreateMemoryLaneLink({
+ required List<MemoryLaneEntry> entries,
+ required String title,
+ String? personId,
+ String? personName,
+ String? birthDate,
+ }) async {
+ try {
+ if (entries.isEmpty) {
+ throw Exception("No uploaded files to share");
+ }
+ final uniqueFileIDs =
+ entries.map((entry) => entry.fileId).toSet().toList();
+ final filesByID =
+ await FilesDB.instance.getFileIDToFileFromIDs(uniqueFileIDs);
+ final laneItems = <_MemoryLaneShareItem>[];
+ for (final entry in entries) {
+ final file = filesByID[entry.fileId];
+ if (file == null || file.uploadedFileID == null) {
+ continue;
+ }
+ laneItems.add(_MemoryLaneShareItem(file: file, entry: entry));
+ }
+ if (laneItems.isEmpty) {
+ throw Exception("No uploaded files to share");
+ }
+ final facesByFileID = await _loadLaneFacesByFileID(laneItems);
+ final metadata = _buildMemoryLaneMetadata(
+ laneItems,
+ title: title,
+ personId: personId,
+ personName: personName,
+ birthDate: birthDate,
+ facesByFileID: facesByFileID,
+ );
+ final memoryHash = _getMemoryLaneHash(metadata);
+ final existingShare = await _findMemoryShareByHash(memoryHash);
+ if (existingShare != null &&
+ existingShare.type == MemoryShareType.lane &&
+ Uri.parse(existingShare.url).fragment.isNotEmpty) {
+ return (existingShare.url, existingShare.id);
+ }
+ return _createMemoryLaneLink(
+ laneItems: laneItems,
+ metadata: metadata,
+ memoryHash: memoryHash,
+ );
+ } catch (e, s) {
+ _logger.severe("Failed to create memory lane share link data", e, s);
+ rethrow;
+ }
+ }
+
Future<MemoryShare?> _findMemoryShareByHash(String memoryHash) async {
final cachedShare = _memoryShareByHashCache[memoryHash];
if (cachedShare != null && !cachedShare.isDeleted) {
@@ -584,11 +716,133 @@ class MemoryShareService {
if (uploadedFileIDs.isEmpty) {
throw Exception("No uploaded files to share");
}
- final uniqueSortedFileIDs = uploadedFileIDs.toSet().toList()..sort();
- final hashInput =
- "${uploadedFileIDs.length}:${uniqueSortedFileIDs.length}:${uniqueSortedFileIDs.join(',')}";
+ final hashInput = "${uploadedFileIDs.length}:${uploadedFileIDs.join(',')}";
+ return sha256.convert(utf8.encode(hashInput)).toString();
+ }
+
+ String _getMemoryLaneHash(Map<String, dynamic> metadata) {
+ final frames = metadata['frames'];
+ final stableFrames = <Map<String, dynamic>>[];
+ if (frames is List) {
+ for (final frame in frames) {
+ stableFrames.add({
+ 'fileID': frame['fileID'],
+ 'position': frame['position'],
+ 'faceID': frame['faceID'],
+ });
+ }
+ }
+
+ final hashMetadata = <String, dynamic>{
+ if (metadata['personID'] != null) 'personID': metadata['personID'],
+ if (metadata['personName'] != null) 'personName': metadata['personName'],
+ if (metadata['birthDate'] != null) 'birthDate': metadata['birthDate'],
+ 'frames': stableFrames,
+ };
+ final hashInput = jsonEncode(hashMetadata);
return sha256.convert(utf8.encode(hashInput)).toString();
}
+
+ Map<String, dynamic> _buildMemoryLaneMetadata(
+ List<_MemoryLaneShareItem> laneItems, {
+ required String title,
+ String? personId,
+ String? personName,
+ String? birthDate,
+ Map<int, List<Face>>? facesByFileID,
+ }) {
+ if (laneItems.isEmpty) {
+ throw Exception("No uploaded files to share");
+ }
+ final normalizedPersonId = personId?.trim();
+ final normalizedPersonName = personName?.trim();
+ final normalizedBirthDate = birthDate?.trim();
+ final captionType =
+ (normalizedBirthDate != null && normalizedBirthDate.isNotEmpty)
+ ? 'age'
+ : 'yearsAgo';
+
+ return {
+ 'name': title,
+ 'kind': MemoryShareType.lane.name,
+ 'captionType': captionType,
+ if (normalizedPersonId != null && normalizedPersonId.isNotEmpty)
+ 'personID': normalizedPersonId,
+ if (normalizedPersonName != null && normalizedPersonName.isNotEmpty)
+ 'personName': normalizedPersonName,
+ if (normalizedBirthDate != null && normalizedBirthDate.isNotEmpty)
+ 'birthDate': normalizedBirthDate,
+ 'frames': [
+ for (var i = 0; i < laneItems.length; i++)
+ {
+ 'fileID': laneItems[i].file.uploadedFileID,
+ 'position': i,
+ ..._buildLaneFaceMetadata(
+ laneItems[i].entry,
+ faces: facesByFileID?[laneItems[i].entry.fileId],
+ ),
+ },
+ ],
+ };
+ }
+
+ Future<Map<int, List<Face>>> _loadLaneFacesByFileID(
+ List<_MemoryLaneShareItem> laneItems,
+ ) async {
+ final uniqueFileIDs = laneItems.map((item) => item.entry.fileId).toSet();
+ final faceEntries = await Future.wait(
+ uniqueFileIDs.map((fileID) async {
+ try {
+ final faces = await MLDataDB.instance.getFacesForGivenFileID(fileID);
+ return MapEntry(fileID, faces ?? const <Face>[]);
+ } catch (e, s) {
+ _logger.warning(
+ "Failed to load lane faces for fileID=$fileID, falling back to faceID parsing",
+ e,
+ s,
+ );
+ return MapEntry(fileID, const <Face>[]);
+ }
+ }),
+ );
+ return Map<int, List<Face>>.fromEntries(faceEntries);
+ }
+
+ Map<String, dynamic> _buildLaneFaceMetadata(
+ MemoryLaneEntry entry, {
+ List<Face>? faces,
+ }) {
+ final faceBox = resolveLaneFaceBox(entry.faceId, faces: faces);
+ final crop = computePaddedFaceCropBox(faceBox);
+ return {
+ 'faceID': entry.faceId,
+ 'faceBox': faceBox.toJson(),
+ 'crop': crop.toJson(),
+ 'creationTime': entry.creationTimeMicros,
+ 'year': entry.year,
+ };
+ }
+
+ dynamic _decodeMemoryShareMetadata(
+ Uint8List decryptedMetadata,
+ MemoryShareType shareType,
+ ) {
+ if (shareType == MemoryShareType.lane) {
+ final decompressed = GZipCodec().decode(decryptedMetadata);
+ return jsonDecode(utf8.decode(decompressed));
+ }
+ return jsonDecode(utf8.decode(decryptedMetadata));
+ }
+}
+
+class _MemoryLaneShareItem {
+ final EnteFile file;
+ final MemoryLaneEntry entry;
+
+ const _MemoryLaneShareItem({
+ required this.file,
+ required this.entry,
+ });
}
class _MemoryShareSecretPayload {
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 36b479f3a6..e905cc62b7 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -570,6 +570,9 @@ class BottomIcons extends StatelessWidget {
final inheritedData = FullScreenMemoryData.of(context)!;
final fullScreenState =
context.findAncestorStateOfType<_FullScreenMemoryState>();
+ final memoryTitle =
+ context.findAncestorWidgetOfExactType<FullScreenMemory>()?.title ??
+ AppLocalizations.of(context).memories;
return ValueListenableBuilder(
valueListenable: inheritedData.indexNotifier,
@@ -630,7 +633,11 @@ class BottomIcons extends StatelessWidget {
),
onPressed: () async {
fullScreenState?._toggleAnimation(pause: true);
- await _showMemoryShareSheet(context, inheritedData);
+ await _showMemoryShareSheet(
+ context,
+ inheritedData,
+ memoryTitle,
+ );
fullScreenState?._toggleAnimation(pause: false);
},
),
@@ -828,6 +835,7 @@ class _MemoriesZoomWidgetState extends State<MemoriesZoomWidget>
Future<void> _showMemoryShareSheet(
BuildContext context,
FullScreenMemoryData inheritedData,
+ String memoryTitle,
) async {
final l10n = AppLocalizations.of(context);
final canShowMemoryShareLinkOption = flagService.enableMemoryShareLink &&
@@ -877,7 +885,7 @@ Future<void> _showMemoryShareSheet(
}
if (shouldShareLink) {
- await _showMemoryLinkDetailsSheet(context, inheritedData);
+ await _showMemoryLinkDetailsSheet(context, inheritedData, memoryTitle);
return;
}
@@ -889,10 +897,12 @@ Future<void> _showMemoryShareSheet(
Future<void> _showMemoryLinkDetailsSheet(
BuildContext context,
FullScreenMemoryData inheritedData,
+ String memoryTitle,
) async {
final shareLinkData = await _getOrCreateMemoryLink(
context,
inheritedData,
+ memoryTitle,
);
if (!context.mounted || shareLinkData == null) {
return;
@@ -924,7 +934,7 @@ Future<void> _showMemoryLinkDetailsSheet(
child: Stack(
children: [
Padding(
- padding: const EdgeInsets.fromLTRB(12, 16, 44, 16),
+ padding: const EdgeInsets.fromLTRB(12, 16, 12, 16),
child: SelectableText(shareUrl, style: textTheme.small),
),
Positioned(
@@ -1015,15 +1025,17 @@ Future<void> _showMemoryLinkDetailsSheet(
Future<(String, int)?> _getOrCreateMemoryLink(
BuildContext context,
FullScreenMemoryData inheritedData,
+ String memoryTitle,
) async {
final l10n = AppLocalizations.of(context);
final dialog = createProgressDialog(context, l10n.creatingLink);
await dialog.show();
try {
+ final normalizedTitle = memoryTitle.trim();
final shareLinkData =
await MemoryShareService.instance.getOrCreateMemoryLink(
memories: inheritedData.memories,
- title: l10n.memories,
+ title: normalizedTitle.isNotEmpty ? normalizedTitle : l10n.memories,
);
await dialog.hide();
return shareLinkData;
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
index 532361d7a9..b42ed27271 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
@@ -1,10 +1,10 @@
import "dart:async";
import "dart:math" as math;
-import "dart:typed_data";
import "dart:ui" as ui;
import "package:collection/collection.dart";
import "package:flutter/material.dart";
+import "package:flutter/services.dart";
import "package:intl/intl.dart";
import "package:logging/logging.dart";
import "package:photos/db/files_db.dart";
@@ -17,10 +17,17 @@ import "package:photos/models/ml/face/face.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/memory_lane/memory_lane_service.dart";
+import "package:photos/services/memory_share_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/effects.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/components/alert_bottom_sheet.dart";
+import "package:photos/ui/components/base_bottom_sheet.dart";
+import "package:photos/ui/components/buttons/button_widget_v2.dart";
+import "package:photos/ui/notification/toast.dart";
+import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/face/face_thumbnail_cache.dart";
+import "package:photos/utils/share_util.dart";
class MemoryLanePage extends StatefulWidget {
final PersonEntity person;
@@ -57,7 +64,6 @@ class _MemoryLanePageState extends State<MemoryLanePage>
// Wait for this many frames (or the available total) before auto-starting playback.
static const int _initialFrameTarget = 120;
static const int _frameBuildConcurrency = 6;
- static const double _appBarSideWidth = kToolbarHeight;
final Logger _logger = Logger("MemoryLanePage");
late final AnimationController _cardTransitionController;
@@ -89,6 +95,8 @@ class _MemoryLanePageState extends State<MemoryLanePage>
_CaptionType _currentCaptionType = _CaptionType.yearsAgo;
int _maxCaptionDigits = 1;
bool get _featureEnabled => flagService.facesTimeline;
+ bool get _showShareAction =>
+ _featureEnabled && flagService.enableMemoryShareLink && !isOfflineMode;
@override
void initState() {
@@ -580,7 +588,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
final title = l10n.facesTimelineAppBarTitle;
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- final titleStyle = textTheme.h2Bold.copyWith(
+ final titleStyle = textTheme.h3Bold.copyWith(
letterSpacing: -2,
);
return DecoratedBox(
@@ -594,29 +602,47 @@ class _MemoryLanePageState extends State<MemoryLanePage>
surfaceTintColor: Colors.transparent,
elevation: 0,
scrolledUnderElevation: 0,
+ centerTitle: false,
foregroundColor: colorScheme.textBase,
automaticallyImplyLeading: false,
- title: Row(
- children: [
- const SizedBox(
- width: _appBarSideWidth,
- height: kToolbarHeight,
- child: BackButton(),
- ),
- Expanded(
- child: Center(
- child: Text(
- title,
- style: titleStyle,
- textAlign: TextAlign.center,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
+ titleSpacing: 24,
+ title: Text(
+ title,
+ style: titleStyle,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ actions: [
+ Padding(
+ padding: const EdgeInsets.only(right: 16),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (_showShareAction)
+ _buildAppBarActionButton(
+ context: context,
+ icon: Icons.share,
+ tooltip: l10n.shareLink,
+ onTap: () async {
+ _pausePlayback();
+ await _showMemoryLaneLinkDetailsSheet(context);
+ },
+ ),
+ if (_showShareAction) const SizedBox(width: 12),
+ _buildAppBarActionButton(
+ context: context,
+ icon: Icons.close,
+ tooltip: MaterialLocalizations.of(
+ context,
+ ).closeButtonTooltip,
+ onTap: () async {
+ await Navigator.of(context).maybePop();
+ },
),
- ),
+ ],
),
- const SizedBox(width: _appBarSideWidth),
- ],
- ),
+ ),
+ ],
),
body: Stack(
children: [
@@ -1017,6 +1043,202 @@ class _MemoryLanePageState extends State<MemoryLanePage>
);
}
+ Widget _buildAppBarActionButton({
+ required BuildContext context,
+ required IconData icon,
+ required String tooltip,
+ required Future<void> Function() onTap,
+ }) {
+ final colorScheme = getEnteColorScheme(context);
+ return Tooltip(
+ message: tooltip,
+ child: GestureDetector(
+ onTap: () async {
+ await onTap();
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: colorScheme.fillFaint,
+ ),
+ padding: const EdgeInsets.all(8),
+ child: Icon(
+ icon,
+ size: 20,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _showMemoryLaneLinkDetailsSheet(BuildContext context) async {
+ final shareLinkData = await _getOrCreateMemoryLaneLinkData(context);
+ if (!context.mounted || shareLinkData == null) {
+ return;
+ }
+ final l10n = context.l10n;
+ final shareUrl = shareLinkData.$1;
+ final int shareId = shareLinkData.$2;
+ await showBaseBottomSheet<void>(
+ context,
+ title: l10n.shareLink,
+ padding: const EdgeInsets.all(16),
+ child: Builder(
+ builder: (context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ l10n.memoryShareLinkDescription,
+ style: textTheme.smallMuted,
+ ),
+ const SizedBox(height: 14),
+ Container(
+ width: double.infinity,
+ decoration: BoxDecoration(
+ color: colorScheme.fillDark,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Stack(
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(12, 16, 44, 16),
+ child: SelectableText(shareUrl, style: textTheme.small),
+ ),
+ Positioned(
+ right: 0,
+ top: 0,
+ child: IconButton(
+ tooltip: l10n.copyLink,
+ iconSize: 20,
+ visualDensity: VisualDensity.compact,
+ onPressed: () async {
+ await Clipboard.setData(
+ ClipboardData(text: shareUrl),
+ );
+ if (context.mounted) {
+ showShortToast(
+ context,
+ l10n.linkCopiedToClipboard,
+ );
+ }
+ },
+ icon: Icon(
+ Icons.copy_rounded,
+ color: colorScheme.textBase,
+ size: 20,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 24),
+ ButtonWidgetV2(
+ buttonType: ButtonTypeV2.primary,
+ labelText: l10n.shareLink,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ await shareText(shareUrl, context: context);
+ },
+ ),
+ const SizedBox(height: 16),
+ Center(
+ child: ButtonWidgetV2(
+ buttonType: ButtonTypeV2.critical,
+ labelText: l10n.deleteLink,
+ onTap: () async {
+ final shouldDelete = await showAlertBottomSheet<bool>(
+ context,
+ title: l10n.deleteLinkQuestion,
+ message: l10n.deleteMemoryLinkMessage,
+ assetPath: "assets/warning-grey.png",
+ buttons: [
+ ButtonWidgetV2(
+ buttonType: ButtonTypeV2.critical,
+ labelText: l10n.deleteLink,
+ onTap: () async {
+ try {
+ await MemoryShareService.instance
+ .deleteMemoryShare(
+ shareId,
+ );
+ if (context.mounted) {
+ showShortToast(
+ context,
+ l10n.linkDeletedSuccessfully,
+ );
+ Navigator.of(context).pop(true);
+ }
+ } catch (_) {
+ if (context.mounted) {
+ showShortToast(
+ context,
+ l10n.somethingWentWrong,
+ );
+ Navigator.of(context).pop(false);
+ }
+ }
+ },
+ ),
+ ],
+ );
+ if (shouldDelete != true) {
+ return;
+ }
+ if (context.mounted) {
+ Navigator.of(context).pop();
+ }
+ },
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ Future<(String, int)?> _getOrCreateMemoryLaneLinkData(
+ BuildContext context,
+ ) async {
+ final l10n = context.l10n;
+ final dialog = createProgressDialog(context, l10n.creatingLink);
+ await dialog.show();
+ try {
+ final timeline = await MemoryLaneService.instance.getTimeline(
+ widget.person.remoteID,
+ );
+ if (timeline == null || !timeline.isReady || timeline.entries.isEmpty) {
+ await dialog.hide();
+ if (context.mounted) {
+ showShortToast(context, l10n.somethingWentWrong);
+ }
+ return null;
+ }
+ final shareLinkData =
+ await MemoryShareService.instance.getOrCreateMemoryLaneLink(
+ entries: timeline.entries,
+ title: l10n.facesTimelineAppBarTitle,
+ personId: widget.person.remoteID,
+ personName: widget.person.data.name,
+ birthDate: widget.person.data.birthDate,
+ );
+ await dialog.hide();
+ return shareLinkData;
+ } catch (e) {
+ await dialog.hide();
+ if (context.mounted) {
+ await showGenericErrorBottomSheet(context: context, error: e);
+ }
+ return null;
+ }
+ }
+
void _togglePlayback() {
if (_frames.isEmpty) {
return;
diff --git a/mobile/apps/photos/lib/utils/face_crop_util.dart b/mobile/apps/photos/lib/utils/face_crop_util.dart
new file mode 100644
index 0000000000..2c3cf010d1
--- /dev/null
+++ b/mobile/apps/photos/lib/utils/face_crop_util.dart
@@ -0,0 +1,78 @@
+import 'dart:math' show min;
+
+import 'package:photos/models/ml/face/box.dart';
+import 'package:photos/models/ml/face/face.dart';
+
+const double _regularPadding = 0.4;
+const double _minimumPadding = 0.1;
+
+FaceBox resolveLaneFaceBox(
+ String faceID, {
+ List<Face>? faces,
+}) {
+ if (faces != null) {
+ for (final face in faces) {
+ if (face.faceID == faceID) {
+ return face.detection.box;
+ }
+ }
+ }
+ return parseFaceBoxFromFaceID(faceID);
+}
+
+FaceBox parseFaceBoxFromFaceID(String faceID) {
+ try {
+ final parts = faceID.split('_');
+ if (parts.length < 5) {
+ return const FaceBox(x: 0, y: 0, width: 1, height: 1);
+ }
+
+ final xMin = int.parse(parts[1]) / 100000.0;
+ final yMin = int.parse(parts[2]) / 100000.0;
+ final xMax = int.parse(parts[3]) / 100000.0;
+ final yMax = int.parse(parts[4]) / 100000.0;
+ final width = (xMax - xMin).clamp(0.00001, 1.0);
+ final height = (yMax - yMin).clamp(0.00001, 1.0);
+ final x = xMin.clamp(0.0, 1.0);
+ final y = yMin.clamp(0.0, 1.0);
+
+ return FaceBox(
+ x: x,
+ y: y,
+ width: width,
+ height: height,
+ );
+ } catch (_) {
+ return const FaceBox(x: 0, y: 0, width: 1, height: 1);
+ }
+}
+
+FaceBox computePaddedFaceCropBox(FaceBox faceBox) {
+ if (faceBox.width <= 0 || faceBox.height <= 0) {
+ return const FaceBox(x: 0, y: 0, width: 1, height: 1);
+ }
+
+ final xCrop = faceBox.x - faceBox.width * _regularPadding;
+ final xOvershoot = min(0.0, xCrop).abs() / faceBox.width;
+ final widthCrop =
+ faceBox.width * (1 + 2 * _regularPadding) -
+ 2 * min(xOvershoot, _regularPadding - _minimumPadding) * faceBox.width;
+
+ final yCrop = faceBox.y - faceBox.height * _regularPadding;
+ final yOvershoot = min(0.0, yCrop).abs() / faceBox.height;
+ final heightCrop =
+ faceBox.height * (1 + 2 * _regularPadding) -
+ 2 * min(yOvershoot, _regularPadding - _minimumPadding) * faceBox.height;
+
+ final xCropSafe = xCrop.clamp(0.0, 1.0);
+ final yCropSafe = yCrop.clamp(0.0, 1.0);
+ final widthCropSafe = widthCrop.clamp(0.0, 1.0 - xCropSafe);
+ final heightCropSafe = heightCrop.clamp(0.0, 1.0 - yCropSafe);
+
+ return FaceBox(
+ x: xCropSafe,
+ y: yCropSafe,
+ width: widthCropSafe,
+ height: heightCropSafe,
+ );
+}
diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
index ecf86ac3d0..228a9c7ee8 100644
--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
@@ -16,7 +16,6 @@ class FlagService {
static const int _commentsFlag = 1 << 1;
static const int _backupOptionsFlag = 1 << 2;
static const int _videoStreamingFlag = 1 << 3;
- static const int _memoryShareLinkFlag = 1 << 4;
final SharedPreferences _prefs;
final Dio _enteDio;
@@ -103,8 +102,7 @@ class FlagService {
bool get isSocialEnabled =>
internalUser || _isServerFlagEnabled(_commentsFlag);
- bool get enableMemoryShareLink =>
- internalUser || _isServerFlagEnabled(_memoryShareLinkFlag);
+ bool get enableMemoryShareLink => internalUser;
bool get useRustForML => internalUser;