π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix feed showing "Liked your photo" for non-owned files
ashilkn30fb870dd4c0
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex d1f9b39980..b9e128540f 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -2405,6 +2405,7 @@"description": "Notification title when someone likes a shared photo or comment."},"likedYourPhoto": "Liked your photo",+ "likedAPhoto": "Liked a photo","likedYourVideo": "Liked your video","commentedOnYourPhoto": "Commented on your photo","commentedOnAPhoto": "Commented on a photo",@@ -2412,8 +2413,10 @@"commentedOnAVideo": "Commented on a video","repliedToYourComment": "Replied to your comment","repliedToAComment": "Replied to a comment",- "likedYourComment": "Liked a comment",- "likedYourReply": "Liked a reply",+ "likedYourComment": "Liked your comment",+ "likedAComment": "Liked a comment",+ "likedYourReply": "Liked your reply",+ "likedAReply": "Liked a reply","and1Other": "and 1 other","andXOthers": "and {count} others","@andXOthers": {diff --git a/mobile/apps/photos/lib/models/social/feed_data_provider.dart b/mobile/apps/photos/lib/models/social/feed_data_provider.dartindex 593538c063..03035ba501 100644--- a/mobile/apps/photos/lib/models/social/feed_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart@@ -2,6 +2,7 @@ import "package:logging/logging.dart";import "package:photos/core/configuration.dart";import "package:photos/db/files_db.dart";import "package:photos/db/social_db.dart";+import "package:photos/models/file/file.dart";import "package:photos/models/social/comment.dart";import "package:photos/models/social/feed_item.dart";import "package:photos/models/social/reaction.dart";@@ -51,22 +52,46 @@ class FeedDataProvider {final commentLikeReactions = results[3] as List<Reaction>;final replyLikeReactions = results[4] as List<Reaction>;+ // Collect all fileIDs for batch loading to resolve ownership+ final fileIDs = <int>{};+ for (final r in photoLikeReactions) {+ if (r.fileID != null) fileIDs.add(r.fileID!);+ }+ for (final c in fileComments) {+ if (c.fileID != null) fileIDs.add(c.fileID!);+ }+ final filesByID = fileIDs.isNotEmpty+ ? await FilesDB.instance.getFileIDToFileFromIDs(fileIDs.toList())+ : <int, EnteFile>{};+// Aggregate photo likes by filefeedItems.addAll(- _aggregateReactionsByFile(photoLikeReactions, FeedItemType.photoLike),+ _aggregateReactionsByFile(+ photoLikeReactions,+ FeedItemType.photoLike,+ filesByID: filesByID,+ userID: userID,+ ),);// Aggregate comments by file- feedItems.addAll(_aggregateCommentsByFile(fileComments));+ feedItems.addAll(+ _aggregateCommentsByFile(+ fileComments,+ filesByID: filesByID,+ userID: userID,+ ),+ );// Aggregate replies by parent comment- feedItems.addAll(_aggregateRepliesByParent(replies));+ feedItems.addAll(_aggregateRepliesByParent(replies, userID: userID));// Aggregate comment likes by commentfeedItems.addAll(await _aggregateReactionsByComment(commentLikeReactions,FeedItemType.commentLike,+ userID: userID,),);@@ -75,6 +100,7 @@ class FeedDataProvider {await _aggregateReactionsByComment(replyLikeReactions,FeedItemType.replyLike,+ userID: userID,),);@@ -113,8 +139,10 @@ class FeedDataProvider {/// Aggregates reactions on files by (collectionID, fileID).List<FeedItem> _aggregateReactionsByFile(List<Reaction> reactions,- FeedItemType type,- ) {+ FeedItemType type, {+ required Map<int, EnteFile> filesByID,+ required int userID,+ }) {final groupedByFile = <String, List<Reaction>>{};for (final reaction in reactions) {@@ -140,19 +168,26 @@ class FeedDataProvider {}}+ final fileID = reactions.first.fileID;return FeedItem(type: type,collectionID: reactions.first.collectionID,- fileID: reactions.first.fileID,+ fileID: fileID,actorUserIDs: uniqueUserIDs,actorAnonIDs: uniqueAnonIDs,createdAt: reactions.first.createdAt,+ isOwnedByCurrentUser:+ fileID != null && filesByID[fileID]?.ownerID == userID,);}).toList();}/// Aggregates comments on files by (collectionID, fileID).- List<FeedItem> _aggregateCommentsByFile(List<Comment> comments) {+ List<FeedItem> _aggregateCommentsByFile(+ List<Comment> comments, {+ required Map<int, EnteFile> filesByID,+ required int userID,+ }) {final groupedByFile = <String, List<Comment>>{};for (final comment in comments) {@@ -178,20 +213,26 @@ class FeedDataProvider {}}+ final fileID = comments.first.fileID;return FeedItem(type: FeedItemType.comment,collectionID: comments.first.collectionID,- fileID: comments.first.fileID,+ fileID: fileID,commentID: comments.first.id,actorUserIDs: uniqueUserIDs,actorAnonIDs: uniqueAnonIDs,createdAt: comments.first.createdAt,+ isOwnedByCurrentUser:+ fileID != null && filesByID[fileID]?.ownerID == userID,);}).toList();}/// Aggregates replies by parent comment ID.- List<FeedItem> _aggregateRepliesByParent(List<Comment> replies) {+ List<FeedItem> _aggregateRepliesByParent(+ List<Comment> replies, {+ required int userID,+ }) {final groupedByParent = <String, List<Comment>>{};for (final reply in replies) {@@ -225,6 +266,7 @@ class FeedDataProvider {actorUserIDs: uniqueUserIDs,actorAnonIDs: uniqueAnonIDs,createdAt: replies.first.createdAt,+ isOwnedByCurrentUser: replies.first.parentCommentUserID == userID,);}).toList();}@@ -232,8 +274,9 @@ class FeedDataProvider {/// Aggregates reactions by comment ID.Future<List<FeedItem>> _aggregateReactionsByComment(List<Reaction> reactions,- FeedItemType type,- ) async {+ FeedItemType type, {+ required int userID,+ }) async {if (reactions.isEmpty) return [];final groupedByComment = <String, List<Reaction>>{};@@ -282,6 +325,7 @@ class FeedDataProvider {actorUserIDs: uniqueUserIDs,actorAnonIDs: uniqueAnonIDs,createdAt: reactions.first.createdAt,+ isOwnedByCurrentUser: comment.userID == userID,);}).whereType<FeedItem>()diff --git a/mobile/apps/photos/lib/models/social/feed_item.dart b/mobile/apps/photos/lib/models/social/feed_item.dartindex 3425cfdda0..99dfcf6c0b 100644--- a/mobile/apps/photos/lib/models/social/feed_item.dart+++ b/mobile/apps/photos/lib/models/social/feed_item.dart@@ -37,6 +37,13 @@ class FeedItem {/// Timestamp of the most recent activity (microseconds since epoch).final int createdAt;+ /// Whether the target of this action is owned by the current user.+ ///+ /// For photoLike/comment: whether the user owns the file.+ /// For reply: whether the user wrote the parent comment.+ /// For commentLike/replyLike: whether the user wrote the liked comment/reply.+ final bool isOwnedByCurrentUser;+const FeedItem({required this.type,required this.collectionID,@@ -45,6 +52,7 @@ class FeedItem {required this.actorUserIDs,required this.actorAnonIDs,required this.createdAt,+ required this.isOwnedByCurrentUser,});/// Number of users who performed this action.diff --git a/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dartindex b924d45baf..1b8d2ade7b 100644--- a/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart@@ -449,17 +449,18 @@ class _FeedTextContent extends StatelessWidget {String _getActionDescription(BuildContext context) {final l10n = AppLocalizations.of(context);+ final isOwn = feedItem.isOwnedByCurrentUser;switch (feedItem.type) {case FeedItemType.photoLike:- return l10n.likedYourPhoto;+ return isOwn ? l10n.likedYourPhoto : l10n.likedAPhoto;case FeedItemType.comment:- return l10n.commentedOnYourPhoto;+ return isOwn ? l10n.commentedOnYourPhoto : l10n.commentedOnAPhoto;case FeedItemType.reply:- return l10n.repliedToYourComment;+ return isOwn ? l10n.repliedToYourComment : l10n.repliedToAComment;case FeedItemType.commentLike:- return l10n.likedYourComment;+ return isOwn ? l10n.likedYourComment : l10n.likedAComment;case FeedItemType.replyLike:- return l10n.likedYourReply;+ return isOwn ? l10n.likedYourReply : l10n.likedAReply;}}diff --git a/mobile/apps/photos/lib/ui/social/widgets/feed_preview_item_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/feed_preview_item_widget.dartindex 3902c3a4ca..bdceda432c 100644--- a/mobile/apps/photos/lib/ui/social/widgets/feed_preview_item_widget.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_preview_item_widget.dart@@ -313,17 +313,18 @@ class _PreviewTextContent extends StatelessWidget {String _getActionDescription(BuildContext context) {final l10n = AppLocalizations.of(context);+ final isOwn = feedItem.isOwnedByCurrentUser;switch (feedItem.type) {case FeedItemType.photoLike:- return l10n.likedYourPhoto;+ return isOwn ? l10n.likedYourPhoto : l10n.likedAPhoto;case FeedItemType.comment:- return l10n.commentedOnYourPhoto;+ return isOwn ? l10n.commentedOnYourPhoto : l10n.commentedOnAPhoto;case FeedItemType.reply:- return l10n.repliedToYourComment;+ return isOwn ? l10n.repliedToYourComment : l10n.repliedToAComment;case FeedItemType.commentLike:- return l10n.likedYourComment;+ return isOwn ? l10n.likedYourComment : l10n.likedAComment;case FeedItemType.replyLike:- return l10n.likedYourReply;+ return isOwn ? l10n.likedYourReply : l10n.likedAReply;}}