π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
2/n feed
Neeraj Guptac34097abb81e
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dartindex faa89fca70..6778022c2e 100644--- a/mobile/apps/photos/lib/db/social_db.dart+++ b/mobile/apps/photos/lib/db/social_db.dart@@ -12,7 +12,7 @@ import 'package:sqflite/sqflite.dart';class SocialDB {static final Logger _logger = Logger("SocialDB");- static const _databaseName = "ente.social.db";+ static const _databaseName = "ente.social2.db";static const _databaseVersion = 1;static const _commentsTable = 'comments';@@ -207,6 +207,25 @@ class SocialDB {return _rowToComment(rows.first);}+ Future<Map<String, Comment>> getCommentsByIds(+ Iterable<String> ids,+ ) async {+ final idList = ids.toList();+ if (idList.isEmpty) return {};++ final placeholders = List.filled(idList.length, '?').join(',');+ final db = await database;+ final rows = await db.query(+ _commentsTable,+ where: 'id IN ($placeholders) AND is_deleted = 0',+ whereArgs: idList,+ );++ return {+ for (final row in rows) (row['id'] as String): _rowToComment(row),+ };+ }+Future<List<Comment>> getCommentsForFilePaginated(int fileID, {required int collectionID,diff --git a/mobile/apps/photos/lib/models/social/feed_data_provider.dart b/mobile/apps/photos/lib/models/social/feed_data_provider.dartindex cc8c329eac..6aed54ed01 100644--- a/mobile/apps/photos/lib/models/social/feed_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart@@ -62,7 +62,7 @@ class FeedDataProvider {// Aggregate comment likes by commentfeedItems.addAll(- _aggregateReactionsByComment(+ await _aggregateReactionsByComment(commentLikeReactions,FeedItemType.commentLike,),@@ -70,7 +70,10 @@ class FeedDataProvider {// Aggregate reply likes by replyfeedItems.addAll(- _aggregateReactionsByComment(replyLikeReactions, FeedItemType.replyLike),+ await _aggregateReactionsByComment(+ replyLikeReactions,+ FeedItemType.replyLike,+ ),);// Filter out items where the associated file doesn't exist@@ -120,12 +123,24 @@ class FeedDataProvider {// Sort by created_at DESC to get most recent firstreactions.sort((a, b) => b.createdAt.compareTo(a.createdAt));+ // Dedupe actors by userID, keeping order (most recent first)+ final seenUserIDs = <int>{};+ final uniqueUserIDs = <int>[];+ final uniqueAnonIDs = <String?>[];+ for (final r in reactions) {+ if (!seenUserIDs.contains(r.userID)) {+ seenUserIDs.add(r.userID);+ uniqueUserIDs.add(r.userID);+ uniqueAnonIDs.add(r.anonUserID);+ }+ }+return FeedItem(type: type,collectionID: reactions.first.collectionID,fileID: reactions.first.fileID,- actorUserIDs: reactions.map((r) => r.userID).toList(),- actorAnonIDs: reactions.map((r) => r.anonUserID).toList(),+ actorUserIDs: uniqueUserIDs,+ actorAnonIDs: uniqueAnonIDs,createdAt: reactions.first.createdAt,);}).toList();@@ -146,12 +161,24 @@ class FeedDataProvider {// Sort by created_at DESC to get most recent firstcomments.sort((a, b) => b.createdAt.compareTo(a.createdAt));+ // Dedupe actors by userID, keeping order (most recent first)+ final seenUserIDs = <int>{};+ final uniqueUserIDs = <int>[];+ final uniqueAnonIDs = <String?>[];+ for (final c in comments) {+ if (!seenUserIDs.contains(c.userID)) {+ seenUserIDs.add(c.userID);+ uniqueUserIDs.add(c.userID);+ uniqueAnonIDs.add(c.anonUserID);+ }+ }+return FeedItem(type: FeedItemType.comment,collectionID: comments.first.collectionID,fileID: comments.first.fileID,- actorUserIDs: comments.map((c) => c.userID).toList(),- actorAnonIDs: comments.map((c) => c.anonUserID).toList(),+ actorUserIDs: uniqueUserIDs,+ actorAnonIDs: uniqueAnonIDs,createdAt: comments.first.createdAt,);}).toList();@@ -172,46 +199,87 @@ class FeedDataProvider {// Sort by created_at DESC to get most recent firstreplies.sort((a, b) => b.createdAt.compareTo(a.createdAt));+ // Dedupe actors by userID, keeping order (most recent first)+ final seenUserIDs = <int>{};+ final uniqueUserIDs = <int>[];+ final uniqueAnonIDs = <String?>[];+ for (final r in replies) {+ if (!seenUserIDs.contains(r.userID)) {+ seenUserIDs.add(r.userID);+ uniqueUserIDs.add(r.userID);+ uniqueAnonIDs.add(r.anonUserID);+ }+ }+return FeedItem(type: FeedItemType.reply,collectionID: replies.first.collectionID,fileID: replies.first.fileID,commentID: replies.first.parentCommentID,- actorUserIDs: replies.map((r) => r.userID).toList(),- actorAnonIDs: replies.map((r) => r.anonUserID).toList(),+ actorUserIDs: uniqueUserIDs,+ actorAnonIDs: uniqueAnonIDs,createdAt: replies.first.createdAt,);}).toList();}/// Aggregates reactions by comment ID.- List<FeedItem> _aggregateReactionsByComment(+ Future<List<FeedItem>> _aggregateReactionsByComment(List<Reaction> reactions,FeedItemType type,- ) {+ ) async {+ if (reactions.isEmpty) return [];+final groupedByComment = <String, List<Reaction>>{};+ final commentIDs = <String>{};for (final reaction in reactions) {if (reaction.commentID == null) continue;final key = '${reaction.collectionID}_${reaction.commentID}';+ commentIDs.add(reaction.commentID!);groupedByComment.putIfAbsent(key, () => []).add(reaction);}- return groupedByComment.entries.map((entry) {- final reactions = entry.value;- // Sort by created_at DESC to get most recent first- reactions.sort((a, b) => b.createdAt.compareTo(a.createdAt));-- return FeedItem(- type: type,- collectionID: reactions.first.collectionID,- fileID: reactions.first.fileID,- commentID: reactions.first.commentID,- actorUserIDs: reactions.map((r) => r.userID).toList(),- actorAnonIDs: reactions.map((r) => r.anonUserID).toList(),- createdAt: reactions.first.createdAt,- );- }).toList();+ if (groupedByComment.isEmpty) return [];++ final commentsByID = await _db.getCommentsByIds(commentIDs);++ return groupedByComment.entries+ .map((entry) {+ final reactions = entry.value;+ // Sort by created_at DESC to get most recent first+ reactions.sort((a, b) => b.createdAt.compareTo(a.createdAt));++ // Dedupe actors by userID, keeping order (most recent first)+ final seenUserIDs = <int>{};+ final uniqueUserIDs = <int>[];+ final uniqueAnonIDs = <String?>[];+ for (final r in reactions) {+ if (!seenUserIDs.contains(r.userID)) {+ seenUserIDs.add(r.userID);+ uniqueUserIDs.add(r.userID);+ uniqueAnonIDs.add(r.anonUserID);+ }+ }++ final commentID = reactions.first.commentID;+ final comment = commentID != null ? commentsByID[commentID] : null;+ if (comment == null) {+ return null;+ }++ return FeedItem(+ type: type,+ collectionID: reactions.first.collectionID,+ fileID: comment.fileID,+ commentID: commentID,+ actorUserIDs: uniqueUserIDs,+ actorAnonIDs: uniqueAnonIDs,+ createdAt: reactions.first.createdAt,+ );+ })+ .whereType<FeedItem>()+ .toList();}/// Filters out feed items where the associated file doesn't exist in FilesDB.diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartindex 91a93152be..6dd66594b2 100644--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -22,9 +22,13 @@ class FileCommentsScreen extends StatefulWidget {final int collectionID;final int fileID;+ /// Optional comment ID to scroll to and highlight.+ final String? highlightCommentID;+const FileCommentsScreen({required this.collectionID,required this.fileID,+ this.highlightCommentID,super.key,});@@ -43,6 +47,8 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {bool _hasMoreComments = true;int _offset = 0;final Map<int, User> _userCache = {};+ String? _highlightedCommentID;+ bool _hasScrolledToHighlight = false;List<CollectionCommentInfo> _sharedCollections = [];late int _selectedCollectionID;@@ -62,6 +68,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {_scrollController = ScrollController()..addListener(_onScroll);_currentUserID = Configuration.instance.getUserID()!;_selectedCollectionID = widget.collectionID;+ _highlightedCommentID = widget.highlightCommentID;_loadSharedCollections();}@@ -146,6 +153,9 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {_isLoading = false;});+ // Scroll to highlighted comment if specified+ _scrollToHighlightedComment();+// Sync in background and refresh if there are changesunawaited(_syncAndRefresh());}@@ -209,6 +219,38 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {}}+ void _scrollToHighlightedComment() {+ if (_highlightedCommentID == null || _hasScrolledToHighlight) return;++ final index = _comments.indexWhere((c) => c.id == _highlightedCommentID);+ if (index == -1) return;++ _hasScrolledToHighlight = true;++ // Use post-frame callback to ensure layout is complete+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (!mounted || !_scrollController.hasClients) return;++ // Estimate scroll position (since ListView is reversed, index 0 is at bottom)+ // Each comment is roughly 100-150px, we'll use 120px as estimate+ const estimatedItemHeight = 120.0;+ final scrollPosition = index * estimatedItemHeight;++ _scrollController.animateTo(+ scrollPosition,+ duration: const Duration(milliseconds: 300),+ curve: Curves.easeOut,+ );++ // Clear highlight after a delay+ Future.delayed(const Duration(seconds: 2), () {+ if (mounted) {+ setState(() => _highlightedCommentID = null);+ }+ });+ });+ }+void _onCollectionSelected(int collectionID) {setState(() {_selectedCollectionID = collectionID;@@ -382,6 +424,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {isOwnComment: comment.userID == _currentUserID,currentUserID: _currentUserID,collectionID: _selectedCollectionID,+ isHighlighted: comment.id == _highlightedCommentID,onFetchParent: comment.isReply? () => _getParentComment(comment.parentCommentID!): null,diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dartindex 0a206e1b41..9aa2013478 100644--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart@@ -2,12 +2,17 @@ import "dart:async";import "package:flutter/material.dart";import "package:photos/core/configuration.dart";+import "package:photos/db/files_db.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/social/feed_data_provider.dart";import "package:photos/models/social/feed_item.dart";+import "package:photos/models/social/social_data_provider.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/buttons/icon_button_widget.dart";+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";+import "package:photos/utils/navigation_util.dart";/// Screen that displays the user's activity feed.///@@ -150,8 +155,56 @@ class _FeedScreenState extends State<FeedScreen> {);}- void _onFeedItemTap(FeedItem item) {- // TODO: Navigate to the photo or comment- // For now, we'll leave this as a placeholder for future implementation+ Future<void> _onFeedItemTap(FeedItem item) async {+ var fileID = item.fileID;++ if (fileID == null && item.commentID != null) {+ final comment =+ await SocialDataProvider.instance.getCommentById(item.commentID!);+ fileID = comment?.fileID;+ }++ if (fileID == null) return;++ // Load the file from DB+ final file = await FilesDB.instance.getUploadedFile(+ fileID,+ item.collectionID,+ );+ if (file == null || !mounted) return;++ // Navigate based on feed item type+ if (item.type == FeedItemType.comment ||+ item.type == FeedItemType.reply ||+ item.type == FeedItemType.commentLike ||+ item.type == FeedItemType.replyLike) {+ // Open comments screen for comment-related items+ // For commentLike/replyLike, highlight the specific comment+ unawaited(+ routeToPage(+ context,+ FileCommentsScreen(+ collectionID: item.collectionID,+ fileID: fileID,+ highlightCommentID: item.commentID,+ ),+ ),+ );+ } else {+ // Open photo viewer for photoLike+ unawaited(+ routeToPage(+ context,+ DetailPage(+ DetailPageConfiguration(+ [file],+ 0,+ "feed_item",+ ),+ ),+ forceCustomPageRoute: true,+ ),+ );+ }}}diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dartindex 62e38a0c7d..ea2502888a 100644--- a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart@@ -33,6 +33,9 @@ class CommentBubbleWidget extends StatefulWidget {final User Function(Comment) userResolver;final VoidCallback? onCommentDeleted;+ /// Whether this comment should be visually highlighted.+ final bool isHighlighted;+const CommentBubbleWidget({required this.comment,required this.user,@@ -44,6 +47,7 @@ class CommentBubbleWidget extends StatefulWidget {required this.onReplyTap,required this.userResolver,this.onCommentDeleted,+ this.isHighlighted = false,super.key,});@@ -149,6 +153,7 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>await SocialDataProvider.instance.toggleReaction(userID: widget.currentUserID,collectionID: widget.collectionID,+ fileID: widget.comment.fileID,commentID: widget.comment.id,);@@ -191,7 +196,9 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>@overrideWidget build(BuildContext context) {- return CompositedTransformTarget(+ final colorScheme = getEnteColorScheme(context);++ Widget content = CompositedTransformTarget(link: _layerLink,child: OverlayPortal(controller: _overlayController,@@ -208,6 +215,20 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>),),);++ // Add highlight effect if needed+ if (widget.isHighlighted) {+ content = AnimatedContainer(+ duration: const Duration(milliseconds: 500),+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(12),+ ),+ child: content,+ );+ }++ return content;}Widget _buildOverlayContent(BuildContext context) {