π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
photos: update memory share flow and memory link strings [dart-only]
AmanRajSinghMouryacc9d0870f18c
diff --git a/mobile/apps/photos/lib/services/memory_share_service.dart b/mobile/apps/photos/lib/services/memory_share_service.dartindex 62ad007d22..503db197d8 100644--- a/mobile/apps/photos/lib/services/memory_share_service.dart+++ b/mobile/apps/photos/lib/services/memory_share_service.dart@@ -42,9 +42,9 @@ class MemoryShareService {required String title,String? memoryId,}) async {+ List<EnteFile> uploadedFiles = const [];try {- final uploadedFiles =- files.where((f) => f.uploadedFileID != null).toList();+ uploadedFiles = files.where((f) => f.uploadedFileID != null).toList();if (uploadedFiles.isEmpty) {throw Exception("No uploaded files to share");@@ -107,7 +107,29 @@ class MemoryShareService {return shareUrl;} catch (e, s) {- _logger.severe("Failed to create memory share", 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);+ }rethrow;}}@@ -517,6 +539,51 @@ class MemoryShareService {}}+ Future<(String, int?)> createMemoryShareLinkData({+ required List<Memory> memories,+ required String title,+ String? memoryId,+ }) async {+ try {+ final shareUrl = await shareMemories(+ memories: memories,+ title: title,+ memoryId: memoryId,+ );+ 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 {+ 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) {+ return share;+ }+ }+ return null;+ } catch (e, s) {+ _logger.severe("Failed to find memory share by URL", e, s);+ rethrow;+ }+ }+Future<String> shareMemories({required List<Memory> memories,required String title,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.dartindex ac3c42080b..ead6d677f5 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@@ -7,12 +7,14 @@ import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/cupertino.dart";import "package:flutter/material.dart";import "package:flutter/services.dart";+import "package:hugeicons/hugeicons.dart";import "package:photos/core/configuration.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/details_sheet_event.dart";import "package:photos/events/pause_video_event.dart";import "package:photos/events/reset_zoom_of_photo_view_event.dart";import "package:photos/events/resume_video_event.dart";+import "package:photos/generated/l10n.dart";import "package:photos/models/file/file_type.dart";import "package:photos/models/memories/memory.dart";import "package:photos/service_locator.dart";@@ -22,6 +24,11 @@ import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/theme/text_style.dart";import "package:photos/ui/actions/file/file_actions.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/components/menu_item_widget/menu_item_widget_new.dart";+import "package:photos/ui/components/settings/settings_grouped_card.dart";import "package:photos/ui/home/memories/custom_listener.dart";import "package:photos/ui/home/memories/memory_progress_indicator.dart";import "package:photos/ui/notification/toast.dart";@@ -434,26 +441,6 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {),),const Spacer(),- GestureDetector(- onTap: () async {- final fullScreenState =- context.findAncestorStateOfType<- _FullScreenMemoryState>();- fullScreenState?._toggleAnimation(pause: true);- await _shareMemoryAsLink(- context,- inheritedData,- widget.title,- );- fullScreenState?._toggleAnimation(pause: false);- },- child: const Icon(- Icons.link,- color: Colors.white,- size: 20,- ),- ),- const SizedBox(width: 8),],),],@@ -659,12 +646,14 @@ class BottomIcons extends StatelessWidget {),onPressed: () async {fullScreenState?._toggleAnimation(pause: true);- await share(context, [currentFile]);+ await _showMemoryShareSheet(+ context,+ inheritedData,+ );fullScreenState?._toggleAnimation(pause: false);},),);-return Container(alignment: Alignment.bottomCenter,padding: const EdgeInsets.fromLTRB(12, 0, 12, 16),@@ -870,33 +859,227 @@ class _MemoriesZoomWidgetState extends State<MemoriesZoomWidget>}}-Future<void> _shareMemoryAsLink(+Future<void> _showMemoryShareSheet(BuildContext context,FullScreenMemoryData inheritedData,- String title,) async {- final memories = inheritedData.memories;-- final dialog = createProgressDialog(context, "Creating share link...");- await dialog.show();+ final l10n = AppLocalizations.of(context);+ final shouldShareLink = await showBaseBottomSheet<bool>(+ context,+ backgroundColor: getEnteColorScheme(context).backgroundColour,+ padding: const EdgeInsets.all(16),+ title: l10n.shareMemory,+ child: Builder(+ builder: (context) {+ final colorScheme = getEnteColorScheme(context);+ return SettingsGroupedCard(+ children: [+ MenuItemWidgetNew(+ title: l10n.shareALinkToThisMemory,+ trailingWidget: HugeIcon(+ icon: HugeIcons.strokeRoundedLink02,+ color: colorScheme.textBase,+ size: 20,+ ),+ borderRadius: 0,+ onTap: () async {+ Navigator.of(context).pop(true);+ },+ ),+ MenuItemWidgetNew(+ title: l10n.shareThisPhoto,+ trailingWidget: HugeIcon(+ icon: HugeIcons.strokeRoundedShare04,+ color: colorScheme.textBase,+ size: 20,+ ),+ borderRadius: 0,+ onTap: () async {+ Navigator.of(context).pop(false);+ },+ ),+ ],+ );+ },+ ),+ );+ if (!context.mounted || shouldShareLink == null) {+ return;+ }- try {- final shareUrl = await MemoryShareService.instance.shareMemories(- memories: memories,- title: title,+ if (shouldShareLink) {+ await _showMemoryLinkDetailsSheet(+ context,+ inheritedData,);+ return;+ }- await dialog.hide();+ final currentFile =+ inheritedData.memories[inheritedData.indexNotifier.value].file;+ await share(context, [currentFile]);+}- await Clipboard.setData(ClipboardData(text: shareUrl));+Future<void> _showMemoryLinkDetailsSheet(+ BuildContext context,+ FullScreenMemoryData inheritedData,+) async {+ final shareLinkData = await _createMemoryShareLinkData(+ context,+ inheritedData,+ );+ if (!context.mounted || shareLinkData == null) {+ return;+ }+ final shareUrl = shareLinkData.$1;+ final shareId = shareLinkData.$2;++ final l10n = AppLocalizations.of(context);+ 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: HugeIcon(+ icon: HugeIcons.strokeRoundedCopy01,+ 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 {+ if (shareId == null) {+ showShortToast(context, l10n.somethingWentWrong);+ return;+ }+ 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 (e) {+ if (context.mounted) {+ showShortToast(context, l10n.somethingWentWrong);+ Navigator.of(context).pop(false);+ }+ }+ },+ ),+ ],+ );+ if (shouldDelete != true) {+ return;+ }+ if (context.mounted) {+ Navigator.of(context).pop();+ }+ },+ ),+ ),+ ],+ );+ },+ ),+ );+}- if (context.mounted) {- showShortToast(context, "Link copied to clipboard");- }+Future<(String, int?)?> _createMemoryShareLinkData(+ BuildContext context,+ FullScreenMemoryData inheritedData,+) async {+ final l10n = AppLocalizations.of(context);+ final dialog = createProgressDialog(context, l10n.creatingLink);+ await dialog.show();+ try {+ final shareLinkData =+ await MemoryShareService.instance.createMemoryShareLinkData(+ memories: inheritedData.memories,+ title: l10n.memories,+ );+ await dialog.hide();+ return shareLinkData;} catch (e) {await dialog.hide();if (context.mounted) {- await showGenericErrorDialog(context: context, error: e);+ await showGenericErrorBottomSheet(context: context, error: e);}+ return null;}}diff --git a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dartindex 79c3c35791..08b0745e6d 100644--- a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart+++ b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart@@ -14,14 +14,10 @@ import "package:photos/events/local_photos_updated_event.dart";import "package:photos/events/tab_changed_event.dart";import "package:photos/events/user_logged_out_event.dart";import "package:photos/generated/l10n.dart";-import "package:photos/models/api/collection/user.dart";-import "package:photos/models/api/memory_share/memory_share.dart";-import "package:photos/models/collection/collection.dart";import "package:photos/models/collection/collection_items.dart";import "package:photos/models/search/generic_search_result.dart";import "package:photos/service_locator.dart";import "package:photos/services/collections_service.dart";-import "package:photos/services/memory_share_service.dart";import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/collections/album/row_item.dart";@@ -33,13 +29,10 @@ import "package:photos/ui/social/widgets/feed_preview_widget.dart";import "package:photos/ui/tabs/section_title.dart";import "package:photos/ui/tabs/shared/all_quick_links_page.dart";import "package:photos/ui/tabs/shared/empty_state.dart";-import "package:photos/ui/tabs/shared/memory_link_item.dart";import "package:photos/ui/tabs/shared/quick_link_album_item.dart";import "package:photos/ui/viewer/gallery/collect_photos_card_widget.dart";import "package:photos/ui/viewer/gallery/collection_page.dart";-import "package:photos/ui/viewer/gallery/shared_public_collection_page.dart";import "package:photos/ui/viewer/search_tab/contacts_section.dart";-import "package:photos/utils/dialog_util.dart";class SharedCollectionsTab extends StatefulWidget {const SharedCollectionsTab({super.key});@@ -212,8 +205,8 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>collections.quickLinks.isNotEmpty ||collections.outgoing.isNotEmpty;if (!hasSharedCollections) {- return SafeArea(- child: _buildMemoryLinksOrEmptyState(),+ return const SafeArea(+ child: SharedEmptyStateWidget(),);}return SafeArea(@@ -235,174 +228,6 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>);}- Widget _buildMemoryLinksOrEmptyState() {- return FutureBuilder<List<MemoryShare>>(- future: _loadMemoryQuickLinks(),- builder: (context, snapshot) {- if (snapshot.connectionState != ConnectionState.done &&- !snapshot.hasData) {- return const EnteLoadingWidget();- }- final memoryLinks = snapshot.data ?? const [];- if (memoryLinks.isEmpty) {- return const Center(- child: SharedEmptyStateWidget(),- );- }- return SingleChildScrollView(- physics: const BouncingScrollPhysics(),- child: Container(- margin: const EdgeInsets.only(bottom: 50),- child: Column(- children: [- SectionOptions(- SectionTitle(- title: AppLocalizations.of(context).memories,- ),- ),- const SizedBox(height: 2),- ListView.separated(- shrinkWrap: true,- padding: const EdgeInsets.only(- bottom: 12,- left: 12,- right: 12,- ),- physics: const NeverScrollableScrollPhysics(),- itemBuilder: (context, index) {- final memoryLink = memoryLinks[index];- final memoryTitle = MemoryShareService.instance- .getMemoryShareTitle(memoryLink) ??- AppLocalizations.of(context).memories;- return GestureDetector(- onTap: () async {- await _openMemoryQuickLink(memoryLink, memoryTitle);- },- child: MemoryLinkAlbumItem(- title: memoryTitle,- fileCount: memoryLink.fileCount,- previewUploadedFileID: memoryLink.previewUploadedFileID,- ),- );- },- separatorBuilder: (context, index) {- return const SizedBox(height: 4);- },- itemCount: memoryLinks.length,- ),- ],- ),- ),- );- },- );- }-- Future<List<MemoryShare>> _loadMemoryQuickLinks() async {- List<MemoryShare> memoryLinks = const [];- try {- memoryLinks = await MemoryShareService.instance.getLocalMemoryShares();- } catch (e, s) {- _logger.warning("failed to load memory links for shared tab", e, s);- }- return memoryLinks;- }-- Future<void> _openMemoryQuickLink(- MemoryShare memoryLink,- String memoryTitle,- ) async {- try {- final files = await MemoryShareService.instance- .getPublicMemoryFiles(memoryLink.url);- if (!mounted) {- return;- }- final id = -(memoryLink.url.hashCode.abs() + 1);- final collection = Collection(- id,- User(email: ""),- "",- null,- memoryTitle,- null,- null,- CollectionType.album,- CollectionAttributes(),- const [],- const [],- DateTime.now().microsecondsSinceEpoch,- );- collection.setName(memoryTitle);- await routeToPage(- context,- SharedPublicCollectionPage(- CollectionWithThumbnail(collection, null),- files: files,- ),- );- } catch (e, s) {- _logger.severe("failed to open memory quick link", e, s);- if (mounted) {- await showGenericErrorDialog(context: context, error: e);- }- }- }-- Widget _buildMemoryLinksSection({- required bool hasQuickLinks,- }) {- return FutureBuilder<List<MemoryShare>>(- future: _loadMemoryQuickLinks(),- builder: (context, snapshot) {- final memoryLinks = snapshot.data ?? const [];- if (memoryLinks.isEmpty) {- return const SizedBox.shrink();- }- return Column(- children: [- SectionOptions(- SectionTitle(- title: AppLocalizations.of(context).memories,- ),- ),- const SizedBox(height: 2),- ListView.separated(- shrinkWrap: true,- padding: EdgeInsets.only(- bottom: 12,- left: 12,- right: 12,- top: hasQuickLinks ? 0 : 12,- ),- physics: const NeverScrollableScrollPhysics(),- itemBuilder: (context, index) {- final memoryLink = memoryLinks[index];- final memoryTitle = MemoryShareService.instance- .getMemoryShareTitle(memoryLink) ??- AppLocalizations.of(context).memories;- return GestureDetector(- onTap: () async {- await _openMemoryQuickLink(memoryLink, memoryTitle);- },- child: MemoryLinkAlbumItem(- title: memoryTitle,- fileCount: memoryLink.fileCount,- previewUploadedFileID: memoryLink.previewUploadedFileID,- ),- );- },- separatorBuilder: (context, index) {- return const SizedBox(height: 4);- },- itemCount: memoryLinks.length,- ),- ],- );- },- );- }-Widget _getSharedCollectionsGallery(SharedCollections collections) {const maxQuickLinks = 4;final numberOfQuickLinks = collections.quickLinks.length;@@ -670,7 +495,6 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>],): const SizedBox.shrink(),- _buildMemoryLinksSection(hasQuickLinks: numberOfQuickLinks > 0),const SizedBox(height: 2),ValueListenableBuilder(valueListenable: _canLoadDeferredWidgets,