Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(photos): update memory share link flow and cache [dart-only]

AmanRajSinghMouryaccb68cee1e24
diff --git a/mobile/apps/photos/lib/core/configuration.dart b/mobile/apps/photos/lib/core/configuration.dart
index 486c8f0a26..806caaeb86 100644
--- a/mobile/apps/photos/lib/core/configuration.dart
+++ b/mobile/apps/photos/lib/core/configuration.dart
@@ -19,6 +19,7 @@ import 'package:photos/db/collections_db.dart';
import 'package:photos/db/files_db.dart';
import "package:photos/db/gallery_downloads_db.dart";
import "package:photos/db/memories_db.dart";
+import "package:photos/db/memory_shares_db.dart";
import "package:photos/db/ml/db.dart";
import 'package:photos/db/trash_db.dart';
import 'package:photos/db/upload_locks_db.dart';
@@ -211,9 +212,6 @@ class Configuration {
}
}
- // Reset feed cutoff so it is recreated for the next login session.
- await localSettings.clearSharedPhotoFeedCutoffTime();
-
// Clear preferences and secure storage
await _preferences.clear();
await _secureStorage.deleteAll();
@@ -232,6 +230,7 @@ class Configuration {
await GalleryDownloadsDB.instance.clearTable();
await CollectionsDB.instance.clearTable();
await MemoriesDB.instance.clearTable();
+ await MemorySharesDB.instance.clearTable();
await MLDataDB.instance.clearTable();
await UploadLocksDB.instance.clearTable();
await TrashDB.instance.clearTable();
diff --git a/mobile/apps/photos/lib/db/memory_shares_db.dart b/mobile/apps/photos/lib/db/memory_shares_db.dart
index fc61cda403..8e62dcded1 100644
--- a/mobile/apps/photos/lib/db/memory_shares_db.dart
+++ b/mobile/apps/photos/lib/db/memory_shares_db.dart
@@ -22,6 +22,7 @@ class MemorySharesDB {
static const _columnCreatedAt = 'created_at';
static const _columnUpdatedAt = 'updated_at';
static const _columnUrl = 'url';
+ static const _columnMemoryHash = 'memory_hash';
static const _columnPreviewUploadedFileID = 'preview_uploaded_file_id';
static const _columnFileCount = 'file_count';
@@ -60,6 +61,7 @@ class MemorySharesDB {
$_columnCreatedAt INTEGER NOT NULL,
$_columnUpdatedAt INTEGER,
$_columnUrl TEXT NOT NULL,
+ $_columnMemoryHash TEXT,
$_columnPreviewUploadedFileID INTEGER,
$_columnFileCount INTEGER
)
@@ -96,6 +98,19 @@ class MemorySharesDB {
return _fromRow(rows.first);
}
+ Future<MemoryShare?> getByMemoryHash(String memoryHash) async {
+ final db = await database;
+ final rows = await db.query(
+ _table,
+ where: '$_columnMemoryHash = ? AND $_columnIsDeleted = 0',
+ whereArgs: [memoryHash],
+ orderBy: '$_columnCreatedAt DESC',
+ limit: 1,
+ );
+ if (rows.isEmpty) return null;
+ return _fromRow(rows.first);
+ }
+
Future<void> delete(int id) async {
final db = await database;
await db.delete(
@@ -123,6 +138,7 @@ class MemorySharesDB {
_columnCreatedAt: share.createdAt,
_columnUpdatedAt: share.updatedAt,
_columnUrl: share.url,
+ _columnMemoryHash: share.memoryHash,
_columnPreviewUploadedFileID: share.previewUploadedFileID,
_columnFileCount: share.fileCount,
};
@@ -141,6 +157,7 @@ class MemorySharesDB {
createdAt: row[_columnCreatedAt] as int,
updatedAt: row[_columnUpdatedAt] as int?,
url: row[_columnUrl] as String,
+ memoryHash: row[_columnMemoryHash] as String?,
previewUploadedFileID: row[_columnPreviewUploadedFileID] as int?,
fileCount: row[_columnFileCount] as int?,
);
diff --git a/mobile/apps/photos/lib/models/api/memory_share/memory_share.dart b/mobile/apps/photos/lib/models/api/memory_share/memory_share.dart
index 4d73d4c21e..b5fac3bb37 100644
--- a/mobile/apps/photos/lib/models/api/memory_share/memory_share.dart
+++ b/mobile/apps/photos/lib/models/api/memory_share/memory_share.dart
@@ -24,6 +24,7 @@ class MemoryShare {
final int createdAt;
final int? updatedAt;
final String url;
+ final String? memoryHash;
final int? previewUploadedFileID;
final int? fileCount;
@@ -39,6 +40,7 @@ class MemoryShare {
required this.createdAt,
this.updatedAt,
required this.url,
+ this.memoryHash,
this.previewUploadedFileID,
this.fileCount,
});
@@ -56,6 +58,7 @@ class MemoryShare {
createdAt: json['createdAt'] as int,
updatedAt: json['updatedAt'] as int?,
url: json['url'] as String,
+ memoryHash: json['memoryHash'] as String?,
previewUploadedFileID: json['previewUploadedFileID'] as int?,
fileCount: json['fileCount'] as int?,
);
@@ -73,6 +76,7 @@ class MemoryShare {
int? createdAt,
int? updatedAt,
String? url,
+ String? memoryHash,
int? previewUploadedFileID,
int? fileCount,
}) {
@@ -88,6 +92,7 @@ class MemoryShare {
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
url: url ?? this.url,
+ memoryHash: memoryHash ?? this.memoryHash,
previewUploadedFileID:
previewUploadedFileID ?? this.previewUploadedFileID,
fileCount: fileCount ?? this.fileCount,
@@ -107,6 +112,7 @@ class MemoryShare {
'createdAt': createdAt,
'updatedAt': updatedAt,
'url': url,
+ 'memoryHash': memoryHash,
'previewUploadedFileID': previewUploadedFileID,
'fileCount': fileCount,
};
diff --git a/mobile/apps/photos/lib/services/memory_share_service.dart b/mobile/apps/photos/lib/services/memory_share_service.dart
index 503db197d8..e12d9f1f68 100644
--- a/mobile/apps/photos/lib/services/memory_share_service.dart
+++ b/mobile/apps/photos/lib/services/memory_share_service.dart
@@ -5,7 +5,6 @@ import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:dio/dio.dart';
import 'package:ente_crypto/ente_crypto.dart';
-import "package:flutter/foundation.dart" show kDebugMode;
import "package:logging/logging.dart";
import 'package:photos/core/network/network.dart';
import "package:photos/db/files_db.dart";
@@ -26,21 +25,23 @@ class MemoryShareService {
final Logger _logger = Logger("MemoryShareService");
static const int _shortFragmentSecretLength = 12;
+ static const int _maxMemoryShareFiles = 30;
static final RegExp _base62SecretPattern = RegExp(r'^[0-9A-Za-z]{12}$');
late final Dio _enteDio;
late final MemorySharesDB _db;
+ final Map<String, MemoryShare> _memoryShareByHashCache = {};
Future<void> init() async {
_enteDio = NetworkClient.instance.enteDio;
_db = MemorySharesDB.instance;
+ await _loadMemoryShareHashCache();
}
- /// Creates a memory share and returns the shareable URL with key in fragment.
- Future<String> createMemoryShare({
+ Future<(String, int)> _createMemoryLink({
required List<EnteFile> files,
required String title,
- String? memoryId,
+ String? memoryHash,
}) async {
List<EnteFile> uploadedFiles = const [];
try {
@@ -49,15 +50,12 @@ class MemoryShareService {
if (uploadedFiles.isEmpty) {
throw Exception("No uploaded files to share");
}
+ final resolvedMemoryHash = memoryHash ?? _getMemoryHash(uploadedFiles);
final secretPayload = await _prepareShareSecret();
final shareKey = secretPayload.shareKey;
- final metadataMap = <String, dynamic>{'name': title};
- if (memoryId != null) {
- metadataMap['memoryId'] = memoryId;
- }
- final metadata = jsonEncode(metadataMap);
+ final metadata = jsonEncode({'name': title});
final metadataBytes = utf8.encode(metadata);
final encryptedMetadata = CryptoUtil.encryptSync(
Uint8List.fromList(metadataBytes),
@@ -80,6 +78,7 @@ class MemoryShareService {
CryptoUtil.bin2base64(encryptedMetadata.encryptedData!),
'metadataNonce': CryptoUtil.bin2base64(encryptedMetadata.nonce!),
...secretPayload.metadata(),
+ 'memoryHash': resolvedMemoryHash,
'files': fileItems,
};
@@ -87,49 +86,19 @@ class MemoryShareService {
final memoryShare = MemoryShare.fromJson(response.data['memoryShare']);
final shareUrl = "${memoryShare.url}#${secretPayload.secret}";
- await _db.upsert(
- MemoryShare(
- id: memoryShare.id,
- type: memoryShare.type,
- metadataCipher: memoryShare.metadataCipher,
- metadataNonce: memoryShare.metadataNonce,
- encryptedKey: memoryShare.encryptedKey,
- keyDecryptionNonce: memoryShare.keyDecryptionNonce,
- accessToken: memoryShare.accessToken,
- isDeleted: memoryShare.isDeleted,
- createdAt: memoryShare.createdAt,
- updatedAt: memoryShare.updatedAt,
- url: shareUrl,
- previewUploadedFileID: uploadedFiles.first.uploadedFileID,
- fileCount: uploadedFiles.length,
- ),
+ final localShare = memoryShare.copyWith(
+ url: shareUrl,
+ memoryHash: resolvedMemoryHash,
+ previewUploadedFileID: uploadedFiles.first.uploadedFileID,
+ fileCount: uploadedFiles.length,
);
+ await _db.upsert(localShare);
+ _updateMemoryShareCache(localShare);
- return shareUrl;
+ return (shareUrl, memoryShare.id);
} catch (e, s) {
- if (e is DioException) {
- final ownerIDs = uploadedFiles.map((f) => f.ownerID).toSet().toList();
- final sampleFileIDs = uploadedFiles
- .map((f) => f.uploadedFileID)
- .whereType<int>()
- .take(10)
- .toList();
- final distinctFileIDCount = uploadedFiles
- .map((f) => f.uploadedFileID)
- .whereType<int>()
- .toSet()
- .length;
- _logger.severe(
- "Failed to create memory share "
- "(status: ${e.response?.statusCode}, data: ${e.response?.data}, "
- "uploadedFiles: ${uploadedFiles.length}, ownerIDs: $ownerIDs, "
- "distinctFileIDs: $distinctFileIDCount, sampleFileIDs: $sampleFileIDs)",
- e,
- s,
- );
- } else {
- _logger.severe("Failed to create memory share", e, s);
- }
+ _logger.severe("Failed to create memory share", e, s);
+
rethrow;
}
}
@@ -168,12 +137,13 @@ class MemoryShareService {
for (final share in result) {
final localShare = await _db.getById(share.id);
- await _db.upsert(
- share.copyWith(
- previewUploadedFileID: localShare?.previewUploadedFileID,
- fileCount: localShare?.fileCount,
- ),
+ final mergedShare = share.copyWith(
+ memoryHash: share.memoryHash ?? localShare?.memoryHash,
+ previewUploadedFileID: localShare?.previewUploadedFileID,
+ fileCount: localShare?.fileCount,
);
+ await _db.upsert(mergedShare);
+ _updateMemoryShareCache(mergedShare);
}
return result;
@@ -211,19 +181,9 @@ class MemoryShareService {
files.add(file);
}
}
- if (files.isEmpty && kDebugMode) {
- _logger.info(
- "Public memory files response was empty, using debug dummy files",
- );
- return _buildDebugDummyMemoryFiles();
- }
return files;
} catch (e, s) {
_logger.severe("Failed to fetch public memory files", e, s);
- if (kDebugMode) {
- _logger.info("Using debug dummy files after fetch failure");
- return _buildDebugDummyMemoryFiles();
- }
rethrow;
}
}
@@ -277,12 +237,13 @@ class MemoryShareService {
}
}
- Future<void> deleteMemoryShare(int id) async {
+ Future<void> deleteMemoryShare(int shareID) async {
try {
- await _enteDio.delete('/memory-share/$id');
- await _db.delete(id);
+ await _enteDio.delete('/memory-share/$shareID');
+ await _db.delete(shareID);
+ _removeMemoryShareFromCache(shareID);
} catch (e, s) {
- _logger.severe("Failed to delete memory share $id", e, s);
+ _logger.severe("Failed to delete memory share $shareID", e, s);
rethrow;
}
}
@@ -505,92 +466,95 @@ class MemoryShareService {
return null;
}
- Future<List<EnteFile>> _buildDebugDummyMemoryFiles({
- int limit = 12,
- }) async {
- try {
- final localFiles = await FilesDB.instance.getAllFilesFromDB(
- const {},
- );
- if (localFiles.isEmpty) {
- return [];
- }
- final usableFiles = localFiles
- .where(
- (file) =>
- file.generatedID != null &&
- file.creationTime != null &&
- file.creationTime! > 0,
- )
- .take(limit)
- .toList();
- if (usableFiles.isEmpty) {
- return [];
- }
- return List<EnteFile>.generate(
- usableFiles.length,
- (index) => usableFiles[index].copyWith(
- title: "Dummy Memory File ${index + 1}",
- ),
- );
- } catch (e, s) {
- _logger.warning("Failed to build debug dummy memory files", e, s);
- return [];
- }
- }
-
- Future<(String, int?)> createMemoryShareLinkData({
+ Future<(String, int)> getOrCreateMemoryLink({
required List<Memory> memories,
required String title,
- String? memoryId,
}) async {
try {
- final shareUrl = await shareMemories(
- memories: memories,
+ final files = Memory.filesFromMemories(memories);
+ final filesForShare = files.take(_maxMemoryShareFiles).toList();
+ final memoryHash = _getMemoryHash(filesForShare);
+ final existingShare = await _findMemoryShareByHash(memoryHash);
+ if (existingShare != null &&
+ Uri.parse(existingShare.url).fragment.isNotEmpty) {
+ return (existingShare.url, existingShare.id);
+ }
+ return _createMemoryLink(
+ files: filesForShare,
title: title,
- memoryId: memoryId,
+ memoryHash: memoryHash,
);
- var memoryShare = await findMemoryShareByUrl(shareUrl);
- if (memoryShare == null) {
- await listMemoryShares();
- memoryShare = await findMemoryShareByUrl(shareUrl);
- }
- return (shareUrl, memoryShare?.id);
} catch (e, s) {
_logger.severe("Failed to create memory share link data", e, s);
rethrow;
}
}
- Future<MemoryShare?> findMemoryShareByUrl(String shareUrl) async {
+ Future<MemoryShare?> _findMemoryShareByHash(String memoryHash) async {
+ final cachedShare = _memoryShareByHashCache[memoryHash];
+ if (cachedShare != null && !cachedShare.isDeleted) {
+ return cachedShare;
+ }
+
try {
- final shares = await getLocalMemoryShares();
- final shareUri = Uri.parse(shareUrl);
- final linkWithoutFragment = shareUri.replace(fragment: "").toString();
- for (final share in shares) {
- if (share.url == shareUrl) {
- return share;
- }
- final shareUriWithoutFragment =
- Uri.parse(share.url).replace(fragment: "").toString();
- if (shareUriWithoutFragment == linkWithoutFragment) {
+ final remoteShares = await listMemoryShares();
+ for (final share in remoteShares) {
+ if (!share.isDeleted && share.memoryHash == memoryHash) {
+ _updateMemoryShareCache(share);
return share;
}
}
- return null;
} catch (e, s) {
- _logger.severe("Failed to find memory share by URL", e, s);
- rethrow;
+ _logger.warning(
+ "Failed to refresh memory-share hash cache while resolving memory hash",
+ e,
+ s,
+ );
}
+
+ return null;
}
- Future<String> shareMemories({
- required List<Memory> memories,
- required String title,
- String? memoryId,
- }) async {
- final files = Memory.filesFromMemories(memories);
- return createMemoryShare(files: files, title: title, memoryId: memoryId);
+ Future<void> _loadMemoryShareHashCache() async {
+ _memoryShareByHashCache.clear();
+ final shares = await _db.getAll();
+ for (final share in shares) {
+ _updateMemoryShareCache(share);
+ }
+ }
+
+ void _updateMemoryShareCache(MemoryShare share) {
+ final hash = share.memoryHash;
+ if (hash == null || hash.isEmpty) {
+ return;
+ }
+ if (share.isDeleted) {
+ final existing = _memoryShareByHashCache[hash];
+ if (existing != null && existing.id == share.id) {
+ _memoryShareByHashCache.remove(hash);
+ }
+ return;
+ }
+ final existing = _memoryShareByHashCache[hash];
+ if (existing == null || share.createdAt >= existing.createdAt) {
+ _memoryShareByHashCache[hash] = share;
+ }
+ }
+
+ void _removeMemoryShareFromCache(int shareID) {
+ _memoryShareByHashCache.removeWhere((_, share) => share.id == shareID);
+ }
+
+ String _getMemoryHash(List<EnteFile> files) {
+ final uploadedFileIDs =
+ files.map((file) => file.uploadedFileID).whereType<int>().toList();
+ if (uploadedFileIDs.isEmpty) {
+ throw Exception("No uploaded files to share");
+ }
+ final uniqueSortedFileIDs = uploadedFileIDs.toSet().toList()..sort();
+ final hashInput =
+ "${uploadedFileIDs.length}:${uniqueSortedFileIDs.length}:${uniqueSortedFileIDs.join(',')}";
+ return sha256.convert(utf8.encode(hashInput)).toString();
}
}
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 ead6d677f5..36b479f3a6 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
@@ -163,8 +163,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
final _showTitle = ValueNotifier<bool>(true);
AnimationController? _progressAnimationController;
AnimationController? _zoomAnimationController;
- final ValueNotifier<Duration> durationNotifier =
- ValueNotifier(const Duration(seconds: 5));
+ final ValueNotifier<Duration> durationNotifier = ValueNotifier(
+ const Duration(seconds: 5),
+ );
/// Used to check if any pointer is on the screen.
final hasPointerOnScreenNotifier = ValueNotifier<bool>(false);
@@ -180,24 +181,23 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
Future.delayed(const Duration(seconds: 3), () {
if (mounted) _showTitle.value = false;
});
- hasPointerOnScreenNotifier.addListener(
- _hasPointerListener,
- );
+ hasPointerOnScreenNotifier.addListener(_hasPointerListener);
- _detailSheetEventSubscription =
- Bus.instance.on<DetailsSheetEvent>().listen((event) {
- final inheritedData = FullScreenMemoryData.of(context);
- if (inheritedData == null) return;
- final index = inheritedData.indexNotifier.value;
- final currentFile = inheritedData.memories[index].file;
-
- if (event.isSameFile(
- uploadedFileID: currentFile.uploadedFileID,
- localID: currentFile.localID,
- )) {
- _toggleAnimation(pause: event.opened);
- }
- });
+ _detailSheetEventSubscription = Bus.instance.on<DetailsSheetEvent>().listen(
+ (event) {
+ final inheritedData = FullScreenMemoryData.of(context);
+ if (inheritedData == null) return;
+ final index = inheritedData.indexNotifier.value;
+ final currentFile = inheritedData.memories[index].file;
+
+ if (event.isSameFile(
+ uploadedFileID: currentFile.uploadedFileID,
+ localID: currentFile.localID,
+ )) {
+ _toggleAnimation(pause: event.opened);
+ }
+ },
+ );
}
@override
@@ -317,17 +317,12 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
final showStepProgressIndicator = inheritedData.memories.length < 60;
return Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 4.0,
- ),
+ padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: SafeArea(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
- border: Border.all(
- color: strokeFainterDark,
- width: 1,
- ),
+ border: Border.all(color: strokeFainterDark, width: 1),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
@@ -344,11 +339,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
onTap: () => Navigator.pop(context),
child: const Padding(
padding: EdgeInsets.fromLTRB(4, 8, 8, 8),
- child: Icon(
- Icons.close,
- color: Colors.white,
- size: 20,
- ),
+ child: Icon(Icons.close, color: Colors.white, size: 20),
),
),
builder: (context, value, child) {
@@ -364,8 +355,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
totalSteps: inheritedData.memories.length,
currentIndex: value,
selectedColor: Colors.white,
- unselectedColor:
- Colors.white.withValues(alpha: 0.4),
+ unselectedColor: Colors.white.withValues(
+ alpha: 0.4,
+ ),
duration: duration,
animationController: (controller) {
_progressAnimationController = controller;
@@ -386,9 +378,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
final fullScreenState =
context.findAncestorStateOfType<
_FullScreenMemoryState>();
- fullScreenState?._toggleAnimation(
- pause: true,
- );
+ fullScreenState?._toggleAnimation(pause: true);
Bus.instance.fire(PauseVideoEvent());
await routeToPage(
context,
@@ -398,9 +388,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
),
);
Bus.instance.fire(ResumeVideoEvent());
- fullScreenState?._toggleAnimation(
- pause: false,
- );
+ fullScreenState?._toggleAnimation(pause: false);
},
child: Container(
decoration: BoxDecoration(
@@ -507,8 +495,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
currentFile,
autoPlay: false,
tagPrefix: "memories",
- backgroundDecoration:
- const BoxDecoration(color: Colors.transparent),
+ backgroundDecoration: const BoxDecoration(
+ color: Colors.transparent,
+ ),
isFromMemories: true,
playbackCallback: (shouldEnable, _) {
_toggleAnimation(pause: !shouldEnable);
@@ -620,9 +609,7 @@ class BottomIcons extends StatelessWidget {
onFileRemoved: (file) => {
inheritedData.removeCurrentMemory.call(),
if (inheritedData.memories.isEmpty)
- {
- Navigator.of(context).pop(),
- },
+ {Navigator.of(context).pop()},
},
);
fullScreenState?._toggleAnimation(pause: false);
@@ -631,10 +618,7 @@ class BottomIcons extends StatelessWidget {
]);
if (!isOfflineMode) {
rowChildren.add(
- SizedBox(
- height: 32,
- child: FavoriteWidget(currentFile),
- ),
+ SizedBox(height: 32, child: FavoriteWidget(currentFile)),
);
}
}
@@ -646,10 +630,7 @@ class BottomIcons extends StatelessWidget {
),
onPressed: () async {
fullScreenState?._toggleAnimation(pause: true);
- await _showMemoryShareSheet(
- context,
- inheritedData,
- );
+ await _showMemoryShareSheet(context, inheritedData);
fullScreenState?._toggleAnimation(pause: false);
},
),
@@ -738,10 +719,7 @@ class _MemoryBlur extends StatelessWidget {
switchOutCurve: Curves.easeInExpo,
child: ImageFiltered(
key: ValueKey(inheritedData.indexNotifier.value),
- imageFilter: ImageFilter.blur(
- sigmaX: 100,
- sigmaY: 100,
- ),
+ imageFilter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: ThumbnailWidget(
currentFile,
shouldShowSyncStatus: false,
@@ -789,9 +767,7 @@ class _MemoriesZoomWidgetState extends State<MemoriesZoomWidget>
void _initAnimation() {
_controller = AnimationController(
vsync: this,
- duration: const Duration(
- seconds: 5,
- ),
+ duration: const Duration(seconds: 5),
animationBehavior: AnimationBehavior.preserve,
);
@@ -806,22 +782,12 @@ class _MemoriesZoomWidgetState extends State<MemoriesZoomWidget>
_scaleAnimation = Tween<double>(
begin: startScale,
end: endScale,
- ).animate(
- CurvedAnimation(
- parent: _controller,
- curve: Curves.easeInOut,
- ),
- );
+ ).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
_panAnimation = Tween<Offset>(
begin: Offset(startX, startY),
end: Offset(endX, endY),
- ).animate(
- CurvedAnimation(
- parent: _controller,
- curve: Curves.easeInOut,
- ),
- );
+ ).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
if (widget.scaleController != null) {
widget.scaleController!(_controller);
@@ -864,6 +830,8 @@ Future<void> _showMemoryShareSheet(
FullScreenMemoryData inheritedData,
) async {
final l10n = AppLocalizations.of(context);
+ final canShowMemoryShareLinkOption = flagService.enableMemoryShareLink &&
+ !(isOfflineMode && !Configuration.instance.hasConfiguredAccount());
final shouldShareLink = await showBaseBottomSheet<bool>(
context,
backgroundColor: getEnteColorScheme(context).backgroundColour,
@@ -874,18 +842,19 @@ Future<void> _showMemoryShareSheet(
final colorScheme = getEnteColorScheme(context);
return SettingsGroupedCard(
children: [
- MenuItemWidgetNew(
- title: l10n.shareALinkToThisMemory,
- trailingWidget: HugeIcon(
- icon: HugeIcons.strokeRoundedLink02,
- color: colorScheme.textBase,
- size: 20,
+ if (canShowMemoryShareLinkOption)
+ MenuItemWidgetNew(
+ title: l10n.shareALinkToThisMemory,
+ trailingWidget: HugeIcon(
+ icon: HugeIcons.strokeRoundedLink02,
+ color: colorScheme.textBase,
+ size: 20,
+ ),
+ borderRadius: 0,
+ onTap: () async {
+ Navigator.of(context).pop(true);
+ },
),
- borderRadius: 0,
- onTap: () async {
- Navigator.of(context).pop(true);
- },
- ),
MenuItemWidgetNew(
title: l10n.shareThisPhoto,
trailingWidget: HugeIcon(
@@ -908,10 +877,7 @@ Future<void> _showMemoryShareSheet(
}
if (shouldShareLink) {
- await _showMemoryLinkDetailsSheet(
- context,
- inheritedData,
- );
+ await _showMemoryLinkDetailsSheet(context, inheritedData);
return;
}
@@ -924,7 +890,7 @@ Future<void> _showMemoryLinkDetailsSheet(
BuildContext context,
FullScreenMemoryData inheritedData,
) async {
- final shareLinkData = await _createMemoryShareLinkData(
+ final shareLinkData = await _getOrCreateMemoryLink(
context,
inheritedData,
);
@@ -932,7 +898,7 @@ Future<void> _showMemoryLinkDetailsSheet(
return;
}
final shareUrl = shareLinkData.$1;
- final shareId = shareLinkData.$2;
+ final int shareId = shareLinkData.$2;
final l10n = AppLocalizations.of(context);
await showBaseBottomSheet<void>(
@@ -947,10 +913,7 @@ Future<void> _showMemoryLinkDetailsSheet(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
- Text(
- l10n.memoryShareLinkDescription,
- style: textTheme.smallMuted,
- ),
+ Text(l10n.memoryShareLinkDescription, style: textTheme.smallMuted),
const SizedBox(height: 14),
Container(
width: double.infinity,
@@ -962,10 +925,7 @@ Future<void> _showMemoryLinkDetailsSheet(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 16, 44, 16),
- child: SelectableText(
- shareUrl,
- style: textTheme.small,
- ),
+ child: SelectableText(shareUrl, style: textTheme.small),
),
Positioned(
right: 0,
@@ -975,9 +935,7 @@ Future<void> _showMemoryLinkDetailsSheet(
iconSize: 20,
visualDensity: VisualDensity.compact,
onPressed: () async {
- await Clipboard.setData(
- ClipboardData(text: shareUrl),
- );
+ await Clipboard.setData(ClipboardData(text: shareUrl));
if (context.mounted) {
showShortToast(context, l10n.linkCopiedToClipboard);
}
@@ -998,10 +956,7 @@ Future<void> _showMemoryLinkDetailsSheet(
labelText: l10n.shareLink,
shouldSurfaceExecutionStates: false,
onTap: () async {
- await shareText(
- shareUrl,
- context: context,
- );
+ await shareText(shareUrl, context: context);
},
),
const SizedBox(height: 16),
@@ -1010,10 +965,6 @@ Future<void> _showMemoryLinkDetailsSheet(
buttonType: ButtonTypeV2.critical,
labelText: l10n.deleteLink,
onTap: () async {
- if (shareId == null) {
- showShortToast(context, l10n.somethingWentWrong);
- return;
- }
final shouldDelete = await showAlertBottomSheet<bool>(
context,
title: l10n.deleteLinkQuestion,
@@ -1025,8 +976,9 @@ Future<void> _showMemoryLinkDetailsSheet(
labelText: l10n.deleteLink,
onTap: () async {
try {
- await MemoryShareService.instance
- .deleteMemoryShare(shareId);
+ await MemoryShareService.instance.deleteMemoryShare(
+ shareId,
+ );
if (context.mounted) {
showShortToast(
context,
@@ -1060,7 +1012,7 @@ Future<void> _showMemoryLinkDetailsSheet(
);
}
-Future<(String, int?)?> _createMemoryShareLinkData(
+Future<(String, int)?> _getOrCreateMemoryLink(
BuildContext context,
FullScreenMemoryData inheritedData,
) async {
@@ -1069,7 +1021,7 @@ Future<(String, int?)?> _createMemoryShareLinkData(
await dialog.show();
try {
final shareLinkData =
- await MemoryShareService.instance.createMemoryShareLinkData(
+ await MemoryShareService.instance.getOrCreateMemoryLink(
memories: inheritedData.memories,
title: l10n.memories,
);
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 993bbf2801..2667c8e4fd 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
@@ -13,8 +13,10 @@ import "model.dart";
class FlagService {
static const int _uploadV2Flag = 1 << 0;
+ 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;
@@ -98,6 +100,12 @@ class FlagService {
bool get enableShareePin => true;
+ bool get isSocialEnabled =>
+ internalUser || _isServerFlagEnabled(_commentsFlag);
+
+ bool get enableMemoryShareLink =>
+ internalUser || _isServerFlagEnabled(_memoryShareLinkFlag);
+
bool get useRustForML => internalUser;
bool get useRustForFaceThumbnails => internalUser;