π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Base notification flow
laurenspriemd63d88fd8be8
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 2f11551f18..b74e780d90 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -2373,6 +2373,14 @@"ritualEmojiUseAction": "Use","ritualSearchEmpty": "Build a ritual to keep your photo habit going.","feed": "Feed",+ "newCommentNotificationTitle": "You got a comment",+ "@newCommentNotificationTitle": {+ "description": "Notification title when someone comments or replies on a shared photo."+ },+ "newLikeNotificationTitle": "You got a like",+ "@newLikeNotificationTitle": {+ "description": "Notification title when someone likes a shared photo or comment."+ },"likedYourPhoto": "Liked a photo","commentedOnYourPhoto": "Commented on a photo","repliedToYourComment": "Replied to a comment",diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dartindex 55d640bd8a..726a6fe81b 100644--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart@@ -1078,9 +1078,6 @@ class RemoteSyncService {if (!_shouldShowSocialNotifications()) {return;}- if (!flagService.internalUser) {- return;- }if (!flagService.isSocialEnabled) {return;}@@ -1138,6 +1135,8 @@ class RemoteSyncService {type: FeedItemType.comment,collectionID: comment.collectionID,fileID: comment.fileID,+ commentID: comment.id,+ commentText: comment.data,createdAt: comment.createdAt,),);@@ -1152,6 +1151,8 @@ class RemoteSyncService {type: FeedItemType.reply,collectionID: reply.collectionID,fileID: reply.fileID,+ commentID: reply.id,+ commentText: reply.data,createdAt: reply.createdAt,),);@@ -1166,6 +1167,7 @@ class RemoteSyncService {type: FeedItemType.commentLike,collectionID: reaction.collectionID,fileID: reaction.fileID,+ commentID: reaction.commentID,createdAt: reaction.createdAt,),);@@ -1180,6 +1182,7 @@ class RemoteSyncService {type: FeedItemType.replyLike,collectionID: reaction.collectionID,fileID: reaction.fileID,+ commentID: reaction.commentID,createdAt: reaction.createdAt,),);@@ -1190,18 +1193,15 @@ class RemoteSyncService {}final s = await LanguageService.locals;- final message = _getSocialNotificationMessage(latest!.type, s);- final collection = _collectionsService.getCollectionByID(- latest!.collectionID,- );- final title = collection?.displayName ?? "ente";+ final title = _getSocialNotificationTitle(latest!.type, s);+ final message = _getSocialNotificationBody(latest!, s);await NotificationService.instance.showNotification(title,message,channelID: "social_activity",channelName: "Activity",- payload: "ente://feed",+ payload: _buildSocialNotificationPayload(latest!),);await _prefs.setInt(kLastSocialActivityNotificationTime,@@ -1216,7 +1216,33 @@ class RemoteSyncService {!AppLifecycleService.instance.isForeground;}- String _getSocialNotificationMessage(+ String _getSocialNotificationTitle(FeedItemType type, AppLocalizations s) {+ switch (type) {+ case FeedItemType.comment:+ case FeedItemType.reply:+ return s.newCommentNotificationTitle;+ case FeedItemType.photoLike:+ case FeedItemType.commentLike:+ case FeedItemType.replyLike:+ return s.newLikeNotificationTitle;+ }+ }++ String _getSocialNotificationBody(+ _SocialActivityCandidate candidate,+ AppLocalizations s,+ ) {+ if (candidate.type == FeedItemType.comment ||+ candidate.type == FeedItemType.reply) {+ final snippet = _sanitizeCommentSnippet(candidate.commentText ?? "");+ if (snippet.isNotEmpty) {+ return snippet;+ }+ }+ return _getSocialNotificationDetail(candidate.type, s);+ }++ String _getSocialNotificationDetail(FeedItemType type,AppLocalizations s,) {@@ -1233,12 +1259,44 @@ class RemoteSyncService {return s.likedYourReply;}}++ String _buildSocialNotificationPayload(_SocialActivityCandidate candidate) {+ final params = <String, String>{+ 'type': candidate.type.name,+ 'collectionID': candidate.collectionID.toString(),+ };+ if (candidate.fileID != null) {+ params['fileID'] = candidate.fileID.toString();+ }+ if (candidate.commentID != null) {+ params['commentID'] = candidate.commentID!;+ }+ return Uri(+ scheme: 'ente',+ host: 'feed',+ queryParameters: params,+ ).toString();+ }++ String _sanitizeCommentSnippet(String text) {+ final trimmed = text.trim();+ if (trimmed.isEmpty) return '';+ final collapsed = trimmed.replaceAll(RegExp(r'\s+'), ' ');+ const maxLength = 140;+ if (collapsed.length <= maxLength) {+ return collapsed;+ }+ final truncated = collapsed.substring(0, maxLength - 3).trimRight();+ return '$truncated...';+ }}class _SocialActivityCandidate {final FeedItemType type;final int collectionID;final int? fileID;+ final String? commentID;+ final String? commentText;final int createdAt;_SocialActivityCandidate({@@ -1246,5 +1304,7 @@ class _SocialActivityCandidate {required this.collectionID,required this.createdAt,this.fileID,+ this.commentID,+ this.commentText,});}diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dartindex 36c4dae590..7c1ef1242e 100644--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart@@ -2,6 +2,7 @@ import "dart:async";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/material.dart";+import "package:logging/logging.dart";import "package:photos/core/configuration.dart";import "package:photos/db/files_db.dart";import "package:photos/generated/l10n.dart";@@ -15,11 +16,67 @@ import "package:photos/ui/social/comments_screen.dart";import "package:photos/ui/social/widgets/feed_item_widget.dart";import "package:photos/ui/viewer/file/detail_page.dart";+final _logger = Logger("FeedScreen");++class FeedNavigationTarget {+ final FeedItemType type;+ final int collectionID;+ final int? fileID;+ final String? commentID;++ const FeedNavigationTarget({+ required this.type,+ required this.collectionID,+ this.fileID,+ this.commentID,+ });++ static FeedNavigationTarget? fromUri(Uri uri) {+ final typeRaw = uri.queryParameters['type'];+ final collectionRaw = uri.queryParameters['collectionID'];+ if (typeRaw == null || collectionRaw == null) {+ _logger.warning("Invalid feed URI: missing type or collectionID in $uri");+ return null;+ }+ final collectionID = int.tryParse(collectionRaw);+ if (collectionID == null) {+ _logger+ .warning("Invalid feed URI: invalid collectionID '$collectionRaw'");+ return null;+ }+ FeedItemType type;+ try {+ type = FeedItemType.values.byName(typeRaw);+ } catch (_) {+ _logger.warning("Invalid feed URI: unknown type '$typeRaw'");+ return null;+ }+ final fileIDRaw = uri.queryParameters['fileID'];+ final fileID = fileIDRaw != null && fileIDRaw.isNotEmpty+ ? int.tryParse(fileIDRaw)+ : null;+ final commentIDRaw = uri.queryParameters['commentID'];+ final commentID =+ commentIDRaw != null && commentIDRaw.isNotEmpty ? commentIDRaw : null;+ return FeedNavigationTarget(+ type: type,+ collectionID: collectionID,+ fileID: fileID,+ commentID: commentID,+ );+ }+}+/// Screen that displays the user's activity feed.////// Shows likes, comments, and replies on the user's photos and comments.class FeedScreen extends StatefulWidget {- const FeedScreen({super.key});+ final FeedNavigationTarget? initialTarget;++ const FeedScreen({+ super.key,+ this.initialTarget,+ });@overrideState<FeedScreen> createState() => _FeedScreenState();@@ -29,6 +86,9 @@ class _FeedScreenState extends State<FeedScreen> {List<FeedItem> _feedItems = [];bool _isLoading = true;late final int _currentUserID;+ FeedNavigationTarget? _pendingNavigationTarget;+ bool _didHandleNavigationTarget = false;+ bool _isOpeningNavigationTarget = false;/// Map of collectionID -> (anonUserID -> displayName)Map<int, Map<String, String>> _anonDisplayNamesByCollection = {};@@ -37,6 +97,7 @@ class _FeedScreenState extends State<FeedScreen> {void initState() {super.initState();_currentUserID = Configuration.instance.getUserID() ?? 0;+ _pendingNavigationTarget = widget.initialTarget;_loadFeedItems();}@@ -56,6 +117,7 @@ class _FeedScreenState extends State<FeedScreen> {_isLoading = false;});}+ _tryOpenNavigationTarget();// Sync in background and refreshunawaited(_syncAndRefresh());@@ -97,6 +159,7 @@ class _FeedScreenState extends State<FeedScreen> {_anonDisplayNamesByCollection = freshAnonNames;});}+ _tryOpenNavigationTarget();} catch (_) {// Ignore sync errors, local data is already displayed}@@ -106,6 +169,90 @@ class _FeedScreenState extends State<FeedScreen> {await _syncAndRefresh();}+ void _tryOpenNavigationTarget() {+ if (_didHandleNavigationTarget || _isOpeningNavigationTarget) {+ return;+ }+ final target = _pendingNavigationTarget;+ if (target == null) return;+ _isOpeningNavigationTarget = true;+ WidgetsBinding.instance.addPostFrameCallback((_) async {+ if (!mounted) {+ _isOpeningNavigationTarget = false;+ return;+ }+ final opened = await _openNavigationTarget(target);+ if (opened && mounted) {+ _didHandleNavigationTarget = true;+ }+ _isOpeningNavigationTarget = false;+ });+ }++ Future<bool> _openNavigationTarget(FeedNavigationTarget target) async {+ if (!mounted) return false;+ if (target.type == FeedItemType.photoLike) {+ final fileID = target.fileID;+ if (fileID == null) return false;+ final file = await FilesDB.instance.getUploadedFile(+ fileID,+ target.collectionID,+ );+ if (file == null || !mounted) return false;+ unawaited(+ routeToPage(+ context,+ DetailPage(+ DetailPageConfiguration(+ [file],+ 0,+ "feed_item",+ ),+ ),+ forceCustomPageRoute: true,+ ),+ );+ return true;+ }++ var fileID = target.fileID;+ if (fileID == null && target.commentID != null) {+ final comment =+ await SocialDataProvider.instance.getCommentById(target.commentID!);+ fileID = comment?.fileID;+ }+ if (fileID == null) return false;+ final file = await FilesDB.instance.getUploadedFile(+ fileID,+ target.collectionID,+ );+ if (file == null || !mounted) return false;+ final capturedFileID = fileID;+ final highlightID = target.commentID;+ unawaited(+ routeToPage(+ context,+ DetailPage(+ DetailPageConfiguration(+ [file],+ 0,+ "feed_comment",+ onPageReady: (detailContext) {+ showFileCommentsBottomSheet(+ detailContext,+ collectionID: target.collectionID,+ fileID: capturedFileID,+ highlightCommentID: highlightID,+ );+ },+ ),+ ),+ forceCustomPageRoute: true,+ ),+ );+ return true;+ }+@overrideWidget build(BuildContext context) {final textTheme = getEnteTextTheme(context);diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dartindex 58c77e7011..81920621c9 100644--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart@@ -1051,8 +1051,14 @@ class _HomeWidgetState extends State<HomeWidget> {if (!Configuration.instance.isLoggedIn()) {return;}+ final target = FeedNavigationTarget.fromUri(uri);// ignore: unawaited_futures- routeToPage(context, const FeedScreen());+ routeToPage(+ context,+ FeedScreen(+ initialTarget: target,+ ),+ );return;}if (payload.toLowerCase().contains("onthisday")) {