π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feed 1/n
Neeraj Guptaf3209827fbe3
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dartindex ac75d5ff99..faa89fca70 100644--- a/mobile/apps/photos/lib/db/social_db.dart+++ b/mobile/apps/photos/lib/db/social_db.dart@@ -446,6 +446,116 @@ class SocialDB {return _rowToAnonProfile(rows.first);}+ // ============ Feed Query Methods ============++ /// Gets all reactions on files (photo likes) excluding the current user's reactions.+ /// Returns reactions sorted by created_at DESC.+ Future<List<Reaction>> getReactionsOnFiles({+ required int excludeUserID,+ int limit = 100,+ int offset = 0,+ }) async {+ final db = await database;+ final rows = await db.query(+ _reactionsTable,+ where:+ 'file_id IS NOT NULL AND comment_id IS NULL AND is_deleted = 0 AND user_id != ?',+ whereArgs: [excludeUserID],+ orderBy: 'created_at DESC',+ limit: limit,+ offset: offset,+ );+ return rows.map(_rowToReaction).toList();+ }++ /// Gets all comments on files excluding the current user's comments.+ /// Returns comments sorted by created_at DESC.+ Future<List<Comment>> getCommentsOnFiles({+ required int excludeUserID,+ int limit = 100,+ int offset = 0,+ }) async {+ final db = await database;+ final rows = await db.query(+ _commentsTable,+ where:+ 'file_id IS NOT NULL AND parent_comment_id IS NULL AND is_deleted = 0 AND user_id != ?',+ whereArgs: [excludeUserID],+ orderBy: 'created_at DESC',+ limit: limit,+ offset: offset,+ );+ return rows.map(_rowToComment).toList();+ }++ /// Gets all replies to comments, excluding the current user's own replies.+ /// Returns replies sorted by created_at DESC.+ Future<List<Comment>> getRepliesToUserComments({+ required int targetUserID,+ int limit = 100,+ int offset = 0,+ }) async {+ final db = await database;+ // Get all replies excluding the current user's own replies+ final rows = await db.query(+ _commentsTable,+ where:+ 'parent_comment_id IS NOT NULL AND is_deleted = 0 AND user_id != ?',+ whereArgs: [targetUserID],+ orderBy: 'created_at DESC',+ limit: limit,+ offset: offset,+ );+ return rows.map(_rowToComment).toList();+ }++ /// Gets all reactions on top-level comments, excluding the current user's reactions.+ /// Returns reactions sorted by created_at DESC.+ Future<List<Reaction>> getReactionsOnUserComments({+ required int targetUserID,+ int limit = 100,+ int offset = 0,+ }) async {+ final db = await database;+ // Get all reactions on comments (not on files) excluding current user's+ // Join to ensure we only get reactions on top-level comments (not replies)+ final rows = await db.rawQuery(+ '''+ SELECT r.* FROM $_reactionsTable r+ INNER JOIN $_commentsTable c ON r.comment_id = c.id+ WHERE r.comment_id IS NOT NULL AND r.is_deleted = 0 AND r.user_id != ?+ AND c.is_deleted = 0 AND c.parent_comment_id IS NULL+ ORDER BY r.created_at DESC+ LIMIT ? OFFSET ?+ ''',+ [targetUserID, limit, offset],+ );+ return rows.map(_rowToReaction).toList();+ }++ /// Gets all reactions on replies, excluding the current user's reactions.+ /// Returns reactions sorted by created_at DESC.+ Future<List<Reaction>> getReactionsOnUserReplies({+ required int targetUserID,+ int limit = 100,+ int offset = 0,+ }) async {+ final db = await database;+ // Get all reactions on replies excluding current user's+ final rows = await db.rawQuery(+ '''+ SELECT r.* FROM $_reactionsTable r+ INNER JOIN $_commentsTable c ON r.comment_id = c.id+ WHERE r.comment_id IS NOT NULL AND r.is_deleted = 0 AND r.user_id != ?+ AND c.is_deleted = 0 AND c.parent_comment_id IS NOT NULL+ ORDER BY r.created_at DESC+ LIMIT ? OFFSET ?+ ''',+ [targetUserID, limit, offset],+ );+ return rows.map(_rowToReaction).toList();+ }+// ============ Cleanup Methods ============Future<void> deleteCollectionData(int collectionID) async {@@ -476,6 +586,115 @@ class SocialDB {await db.delete(_syncTimeTable);}+ Future<int> deleteAllComments() async {+ final db = await database;+ return await db.delete(_commentsTable);+ }++ Future<int> deleteAllReactions() async {+ final db = await database;+ return await db.delete(_reactionsTable);+ }++ // ============ Debug Methods ============++ Future<void> seedExampleData() async {+ final now = DateTime.now().microsecondsSinceEpoch;+ const testCollectionID = 1;+ const testFileID = 100;+ const testUserID = 1;++ // Seed example comments+ final exampleComments = [+ Comment(+ id: 'comment_1',+ collectionID: testCollectionID,+ fileID: testFileID,+ data: 'This is a great photo!',+ parentCommentID: null,+ parentCommentUserID: null,+ isDeleted: false,+ userID: testUserID,+ anonUserID: null,+ createdAt: now - 3600000000,+ updatedAt: now - 3600000000,+ ),+ Comment(+ id: 'comment_2',+ collectionID: testCollectionID,+ fileID: testFileID,+ data: 'I agree, amazing shot!',+ parentCommentID: 'comment_1',+ parentCommentUserID: testUserID,+ isDeleted: false,+ userID: testUserID + 1,+ anonUserID: null,+ createdAt: now - 1800000000,+ updatedAt: now - 1800000000,+ ),+ Comment(+ id: 'comment_3',+ collectionID: testCollectionID,+ fileID: null,+ data: 'Collection-level comment',+ parentCommentID: null,+ parentCommentUserID: null,+ isDeleted: false,+ userID: testUserID,+ anonUserID: null,+ createdAt: now - 900000000,+ updatedAt: now - 900000000,+ ),+ ];++ // Seed example reactions+ final exampleReactions = [+ Reaction(+ id: 'reaction_1',+ collectionID: testCollectionID,+ fileID: testFileID,+ commentID: null,+ data: 'β€οΈ',+ isDeleted: false,+ userID: testUserID,+ anonUserID: null,+ createdAt: now - 7200000000,+ updatedAt: now - 7200000000,+ ),+ Reaction(+ id: 'reaction_2',+ collectionID: testCollectionID,+ fileID: testFileID,+ commentID: null,+ data: 'π',+ isDeleted: false,+ userID: testUserID + 1,+ anonUserID: null,+ createdAt: now - 3600000000,+ updatedAt: now - 3600000000,+ ),+ Reaction(+ id: 'reaction_3',+ collectionID: testCollectionID,+ fileID: null,+ commentID: 'comment_1',+ data: 'π',+ isDeleted: false,+ userID: testUserID + 2,+ anonUserID: null,+ createdAt: now - 1800000000,+ updatedAt: now - 1800000000,+ ),+ ];++ await upsertComments(exampleComments);+ await upsertReactions(exampleReactions);++ _logger.info(+ 'Seeded ${exampleComments.length} comments and ${exampleReactions.length} reactions',+ );+ }+// ============ Row Mappers ============Map<String, dynamic> _commentToRow(Comment comment) {diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 21fe4eebe4..b97e5b894b 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -2174,5 +2174,21 @@"ritualCustomKeyboardLabel": "Custom (keyboard)","ritualEmojiKeyboardHint": "Press to open emoji keyboard","ritualEmojiUseAction": "Use",- "ritualSearchEmpty": "Build a ritual to keep your photo habit going."+ "ritualSearchEmpty": "Build a ritual to keep your photo habit going.",+ "feed": "Feed",+ "likedYourPhoto": "Liked a photo",+ "commentedOnYourPhoto": "Commented on a photo",+ "repliedToYourComment": "Replied to a comment",+ "likedYourComment": "Liked a comment",+ "likedYourReply": "Liked a reply",+ "and1Other": "and 1 other",+ "andXOthers": "and {count} others",+ "@andXOthers": {+ "placeholders": {+ "count": {+ "type": "int"+ }+ }+ },+ "noActivityYet": "No activity yet"}diff --git a/mobile/apps/photos/lib/models/social/feed_data_provider.dart b/mobile/apps/photos/lib/models/social/feed_data_provider.dartnew file mode 100644index 0000000000..cc8c329eac--- /dev/null+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart@@ -0,0 +1,266 @@+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/social/comment.dart";+import "package:photos/models/social/feed_item.dart";+import "package:photos/models/social/reaction.dart";+import "package:photos/services/social_sync_service.dart";++/// Provider for feed data.+///+/// Aggregates social activity (comments, reactions) into feed items+/// for display in the activity feed.+class FeedDataProvider {+ FeedDataProvider._();+ static final instance = FeedDataProvider._();++ final _logger = Logger('FeedDataProvider');+ final _db = SocialDB.instance;++ /// Gets feed items aggregated from local database.+ ///+ /// Feed items are sorted by most recent activity.+ /// Each item represents a unique (type, fileID, commentID) combination.+ /// Items associated with files that no longer exist in the database are filtered out.+ Future<List<FeedItem>> getFeedItems({+ int limit = 50,+ }) async {+ final userID = Configuration.instance.getUserID();+ if (userID == null) {+ _logger.warning('No user ID found, returning empty feed');+ return [];+ }++ final feedItems = <FeedItem>[];++ // Fetch all activity types in parallel+ final results = await Future.wait([+ _db.getReactionsOnFiles(excludeUserID: userID, limit: limit),+ _db.getCommentsOnFiles(excludeUserID: userID, limit: limit),+ _db.getRepliesToUserComments(targetUserID: userID, limit: limit),+ _db.getReactionsOnUserComments(targetUserID: userID, limit: limit),+ _db.getReactionsOnUserReplies(targetUserID: userID, limit: limit),+ ]);++ final photoLikeReactions = results[0] as List<Reaction>;+ final fileComments = results[1] as List<Comment>;+ final replies = results[2] as List<Comment>;+ final commentLikeReactions = results[3] as List<Reaction>;+ final replyLikeReactions = results[4] as List<Reaction>;++ // Aggregate photo likes by file+ feedItems.addAll(+ _aggregateReactionsByFile(photoLikeReactions, FeedItemType.photoLike),+ );++ // Aggregate comments by file+ feedItems.addAll(_aggregateCommentsByFile(fileComments));++ // Aggregate replies by parent comment+ feedItems.addAll(_aggregateRepliesByParent(replies));++ // Aggregate comment likes by comment+ feedItems.addAll(+ _aggregateReactionsByComment(+ commentLikeReactions,+ FeedItemType.commentLike,+ ),+ );++ // Aggregate reply likes by reply+ feedItems.addAll(+ _aggregateReactionsByComment(replyLikeReactions, FeedItemType.replyLike),+ );++ // Filter out items where the associated file doesn't exist+ final validItems = await _filterItemsWithExistingFiles(feedItems);++ // Sort by most recent activity+ validItems.sort((a, b) => b.createdAt.compareTo(a.createdAt));++ // Limit total results+ if (validItems.length > limit) {+ return validItems.sublist(0, limit);+ }++ return validItems;+ }++ /// Gets a single feed item for preview display.+ Future<FeedItem?> getLatestFeedItem() async {+ final items = await getFeedItems(limit: 1);+ return items.isNotEmpty ? items.first : null;+ }++ /// Triggers background sync for all shared collections.+ Future<void> syncAllSharedCollections() async {+ try {+ await SocialSyncService.instance.syncAllSharedCollections();+ } catch (e) {+ _logger.warning('Failed to sync shared collections', e);+ }+ }++ /// Aggregates reactions on files by (collectionID, fileID).+ List<FeedItem> _aggregateReactionsByFile(+ List<Reaction> reactions,+ FeedItemType type,+ ) {+ final groupedByFile = <String, List<Reaction>>{};++ for (final reaction in reactions) {+ if (reaction.fileID == null) continue;+ final key = '${reaction.collectionID}_${reaction.fileID}';+ groupedByFile.putIfAbsent(key, () => []).add(reaction);+ }++ return groupedByFile.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,+ actorUserIDs: reactions.map((r) => r.userID).toList(),+ actorAnonIDs: reactions.map((r) => r.anonUserID).toList(),+ createdAt: reactions.first.createdAt,+ );+ }).toList();+ }++ /// Aggregates comments on files by (collectionID, fileID).+ List<FeedItem> _aggregateCommentsByFile(List<Comment> comments) {+ final groupedByFile = <String, List<Comment>>{};++ for (final comment in comments) {+ if (comment.fileID == null) continue;+ final key = '${comment.collectionID}_${comment.fileID}';+ groupedByFile.putIfAbsent(key, () => []).add(comment);+ }++ return groupedByFile.entries.map((entry) {+ final comments = entry.value;+ // Sort by created_at DESC to get most recent first+ comments.sort((a, b) => b.createdAt.compareTo(a.createdAt));++ 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(),+ createdAt: comments.first.createdAt,+ );+ }).toList();+ }++ /// Aggregates replies by parent comment ID.+ List<FeedItem> _aggregateRepliesByParent(List<Comment> replies) {+ final groupedByParent = <String, List<Comment>>{};++ for (final reply in replies) {+ if (reply.parentCommentID == null) continue;+ final key = '${reply.collectionID}_${reply.parentCommentID}';+ groupedByParent.putIfAbsent(key, () => []).add(reply);+ }++ return groupedByParent.entries.map((entry) {+ final replies = entry.value;+ // Sort by created_at DESC to get most recent first+ replies.sort((a, b) => b.createdAt.compareTo(a.createdAt));++ 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(),+ createdAt: replies.first.createdAt,+ );+ }).toList();+ }++ /// Aggregates reactions by comment ID.+ List<FeedItem> _aggregateReactionsByComment(+ List<Reaction> reactions,+ FeedItemType type,+ ) {+ final groupedByComment = <String, List<Reaction>>{};++ for (final reaction in reactions) {+ if (reaction.commentID == null) continue;+ final key = '${reaction.collectionID}_${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();+ }++ /// Filters out feed items where the associated file doesn't exist in FilesDB.+ ///+ /// This handles cases where a file has been deleted but its social data+ /// (comments/reactions) still exists in the database.+ Future<List<FeedItem>> _filterItemsWithExistingFiles(+ List<FeedItem> items,+ ) async {+ if (items.isEmpty) return items;++ // Collect unique (fileID, collectionID) pairs+ final filesToCheck = <String, (int fileID, int collectionID)>{};+ for (final item in items) {+ if (item.fileID != null) {+ final key = '${item.collectionID}_${item.fileID}';+ filesToCheck[key] = (item.fileID!, item.collectionID);+ }+ }++ if (filesToCheck.isEmpty) return items;++ // Check which files exist in parallel+ final existingFiles = <String>{};+ final checkResults = await Future.wait(+ filesToCheck.entries.map((entry) async {+ final (fileID, collectionID) = entry.value;+ final file = await FilesDB.instance.getUploadedFile(+ fileID,+ collectionID,+ );+ return (key: entry.key, exists: file != null);+ }),+ );++ for (final result in checkResults) {+ if (result.exists) {+ existingFiles.add(result.key);+ }+ }++ // Filter items to only include those with existing files+ return items.where((item) {+ if (item.fileID == null) {+ // Items without fileID (collection-level activity) are kept+ return true;+ }+ final key = '${item.collectionID}_${item.fileID}';+ return existingFiles.contains(key);+ }).toList();+ }+}diff --git a/mobile/apps/photos/lib/models/social/feed_item.dart b/mobile/apps/photos/lib/models/social/feed_item.dartnew file mode 100644index 0000000000..3425cfdda0--- /dev/null+++ b/mobile/apps/photos/lib/models/social/feed_item.dart@@ -0,0 +1,87 @@+/// Types of feed activity items.+enum FeedItemType {+ /// Reaction (like) on a photo/file+ photoLike,++ /// Comment on a photo/file+ comment,++ /// Reply to user's comment+ reply,++ /// Reaction (like) on user's comment+ commentLike,++ /// Reaction (like) on user's reply+ replyLike,+}++/// Represents an activity item in the user's feed.+///+/// Feed items are aggregated by type and target (file or comment),+/// showing multiple actors who performed the same action.+class FeedItem {+ final FeedItemType type;+ final int collectionID;+ final int? fileID;+ final String? commentID;++ /// User IDs of users who performed this action.+ /// First user is the most recent actor.+ final List<int> actorUserIDs;++ /// Anonymous user IDs corresponding to actorUserIDs.+ /// Null entries indicate non-anonymous users.+ final List<String?> actorAnonIDs;++ /// Timestamp of the most recent activity (microseconds since epoch).+ final int createdAt;++ const FeedItem({+ required this.type,+ required this.collectionID,+ this.fileID,+ this.commentID,+ required this.actorUserIDs,+ required this.actorAnonIDs,+ required this.createdAt,+ });++ /// Number of users who performed this action.+ int get actorCount => actorUserIDs.length;++ /// Whether this feed item has multiple actors.+ bool get hasMultipleActors => actorCount > 1;++ /// The primary actor's user ID (most recent).+ int get primaryActorUserID => actorUserIDs.first;++ /// The primary actor's anonymous ID (if anonymous).+ String? get primaryActorAnonID => actorAnonIDs.first;++ /// Number of additional actors beyond the primary.+ int get additionalActorCount => actorCount - 1;++ @override+ String toString() {+ return 'FeedItem(type: $type, collectionID: $collectionID, '+ 'fileID: $fileID, commentID: $commentID, '+ 'actorCount: $actorCount, createdAt: $createdAt)';+ }++ @override+ bool operator ==(Object other) {+ if (identical(this, other)) return true;+ return other is FeedItem &&+ other.type == type &&+ other.collectionID == collectionID &&+ other.fileID == fileID &&+ other.commentID == commentID &&+ other.createdAt == createdAt;+ }++ @override+ int get hashCode {+ return Object.hash(type, collectionID, fileID, commentID, createdAt);+ }+}diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dartindex 09f2f282c7..8ca120b5ad 100644--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart@@ -204,8 +204,7 @@ class SocialDataProvider {return deletedReaction;} else {// User doesn't have a reaction or it's deleted - create/upsert one- final encrypted =- _api.encryptReaction(reactionType, collectionID);+ final encrypted = _api.encryptReaction(reactionType, collectionID);final reactionID = await _api.upsertReaction(collectionID: collectionID,diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dartnew file mode 100644index 0000000000..0a206e1b41--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart@@ -0,0 +1,157 @@+import "dart:async";++import "package:flutter/material.dart";+import "package:photos/core/configuration.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/theme/ente_theme.dart";+import "package:photos/ui/components/buttons/icon_button_widget.dart";+import "package:photos/ui/social/widgets/feed_item_widget.dart";++/// 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});++ @override+ State<FeedScreen> createState() => _FeedScreenState();+}++class _FeedScreenState extends State<FeedScreen> {+ List<FeedItem> _feedItems = [];+ bool _isLoading = true;+ late final int _currentUserID;++ @override+ void initState() {+ super.initState();+ _currentUserID = Configuration.instance.getUserID() ?? 0;+ _loadFeedItems();+ }++ Future<void> _loadFeedItems() async {+ setState(() => _isLoading = true);++ // Load local data first+ final items = await FeedDataProvider.instance.getFeedItems(limit: 50);++ if (mounted) {+ setState(() {+ _feedItems = items;+ _isLoading = false;+ });+ }++ // Sync in background and refresh+ unawaited(_syncAndRefresh());+ }++ Future<void> _syncAndRefresh() async {+ try {+ await FeedDataProvider.instance.syncAllSharedCollections();++ if (!mounted) return;++ // Reload feed items after sync+ final freshItems =+ await FeedDataProvider.instance.getFeedItems(limit: 50);++ if (mounted) {+ setState(() {+ _feedItems = freshItems;+ });+ }+ } catch (_) {+ // Ignore sync errors, local data is already displayed+ }+ }++ Future<void> _onRefresh() async {+ await _syncAndRefresh();+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Scaffold(+ appBar: AppBar(+ automaticallyImplyLeading: false,+ backgroundColor: colorScheme.backgroundBase,+ elevation: 0,+ leading: IconButtonWidget(+ iconButtonType: IconButtonType.secondary,+ icon: Icons.arrow_back,+ onTap: () => Navigator.of(context).pop(),+ ),+ title: Text(+ AppLocalizations.of(context).feed,+ style: textTheme.bodyBold,+ ),+ ),+ body: _isLoading+ ? const Center(child: CircularProgressIndicator())+ : _feedItems.isEmpty+ ? _buildEmptyState(context)+ : RefreshIndicator(+ onRefresh: _onRefresh,+ child: ListView.separated(+ padding: const EdgeInsets.symmetric(horizontal: 15),+ itemCount: _feedItems.length,+ separatorBuilder: (context, index) => Divider(+ height: 1,+ color: colorScheme.strokeFaint,+ ),+ itemBuilder: (context, index) {+ final item = _feedItems[index];+ return FeedItemWidget(+ key: ValueKey(+ '${item.type}_${item.fileID}_${item.commentID}_${item.createdAt}',+ ),+ feedItem: item,+ currentUserID: _currentUserID,+ onTap: () => _onFeedItemTap(item),+ );+ },+ ),+ ),+ );+ }++ Widget _buildEmptyState(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Center(+ child: Padding(+ padding: const EdgeInsets.all(32),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Icon(+ Icons.notifications_none_outlined,+ size: 48,+ color: colorScheme.strokeMuted,+ ),+ const SizedBox(height: 16),+ Text(+ AppLocalizations.of(context).noActivityYet,+ style: textTheme.body.copyWith(+ color: colorScheme.textMuted,+ ),+ textAlign: TextAlign.center,+ ),+ ],+ ),+ ),+ );+ }++ void _onFeedItemTap(FeedItem item) {+ // TODO: Navigate to the photo or comment+ // For now, we'll leave this as a placeholder for future implementation+ }+}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.dartnew file mode 100644index 0000000000..b5e7c8536c--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart@@ -0,0 +1,487 @@+import "package:flutter/material.dart";+import "package:photos/db/files_db.dart";+import "package:photos/extensions/user_extension.dart";+import "package:photos/generated/l10n.dart";+import "package:photos/models/api/collection/user.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/social/feed_item.dart";+import "package:photos/services/collections_service.dart";+import "package:photos/theme/colors.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/theme/text_style.dart";+import "package:photos/ui/sharing/user_avator_widget.dart";+import "package:photos/ui/viewer/file/thumbnail_widget.dart";++/// Widget that displays a single feed item.+///+/// Shows: [Icon] [Stacked Avatars] [User names + action text] [Photo Thumbnail]+class FeedItemWidget extends StatelessWidget {+ final FeedItem feedItem;+ final int currentUserID;+ final VoidCallback? onTap;++ const FeedItemWidget({+ required this.feedItem,+ required this.currentUserID,+ this.onTap,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);++ return GestureDetector(+ onTap: onTap,+ behavior: HitTestBehavior.opaque,+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 18),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ // Feed type icon+ _FeedTypeIcon(type: feedItem.type),+ const SizedBox(width: 10),+ // Stacked avatars+ _StackedAvatars(+ feedItem: feedItem,+ currentUserID: currentUserID,+ ),+ const SizedBox(width: 10),+ // Text content+ Expanded(+ child: _FeedTextContent(+ feedItem: feedItem,+ currentUserID: currentUserID,+ ),+ ),+ const SizedBox(width: 12),+ // Photo thumbnail+ if (feedItem.fileID != null)+ _FeedThumbnail(+ fileID: feedItem.fileID!,+ collectionID: feedItem.collectionID,+ )+ else+ Container(+ width: 66,+ height: 66,+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(7.792),+ ),+ ),+ ],+ ),+ ),+ );+ }+}++/// Displays the feed type icon (heart, comment, reply, etc.)+class _FeedTypeIcon extends StatelessWidget {+ final FeedItemType type;++ const _FeedTypeIcon({required this.type});++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);++ return Container(+ width: 32,+ height: 32,+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated,+ shape: BoxShape.circle,+ ),+ child: Center(+ child: _buildIcon(context),+ ),+ );+ }++ Widget _buildIcon(BuildContext context) {+ switch (type) {+ case FeedItemType.photoLike:+ return const Icon(+ Icons.favorite,+ size: 18,+ color: Color(0xFF00B33C),+ );+ case FeedItemType.comment:+ return Icon(+ Icons.chat_bubble_outline,+ size: 18,+ color: getEnteColorScheme(context).textMuted,+ );+ case FeedItemType.reply:+ return Icon(+ Icons.reply,+ size: 18,+ color: getEnteColorScheme(context).textMuted,+ );+ case FeedItemType.commentLike:+ return Stack(+ clipBehavior: Clip.none,+ children: [+ Icon(+ Icons.chat_bubble_outline,+ size: 18,+ color: getEnteColorScheme(context).textMuted,+ ),+ const Positioned(+ right: -4,+ bottom: -4,+ child: Icon(+ Icons.favorite,+ size: 10,+ color: Color(0xFF00B33C),+ ),+ ),+ ],+ );+ case FeedItemType.replyLike:+ return Stack(+ clipBehavior: Clip.none,+ children: [+ Icon(+ Icons.reply,+ size: 18,+ color: getEnteColorScheme(context).textMuted,+ ),+ const Positioned(+ right: -4,+ bottom: -4,+ child: Icon(+ Icons.favorite,+ size: 10,+ color: Color(0xFF00B33C),+ ),+ ),+ ],+ );+ }+ }+}++/// Displays stacked user avatars (max 2, overlapping).+class _StackedAvatars extends StatelessWidget {+ final FeedItem feedItem;+ final int currentUserID;++ const _StackedAvatars({+ required this.feedItem,+ required this.currentUserID,+ });++ @override+ Widget build(BuildContext context) {+ final actors = _getActors();+ final displayCount = actors.length.clamp(1, 2);++ if (displayCount == 1) {+ return _buildSingleAvatar(actors.first);+ }++ // Stacked avatars with overlap+ return SizedBox(+ width: 28 + 21, // First avatar + second avatar offset+ height: 28,+ child: Stack(+ clipBehavior: Clip.none,+ children: [+ // First (front) avatar+ Positioned(+ left: 0,+ child: Container(+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: Colors.white,+ width: 1.167,+ ),+ ),+ child: UserAvatarWidget(+ actors.first,+ type: AvatarType.lg,+ currentUserID: currentUserID,+ addStroke: false,+ ),+ ),+ ),+ // Second (back) avatar+ Positioned(+ left: 21, // Overlap by 7px (28 - 21 = 7)+ child: UserAvatarWidget(+ actors[1],+ type: AvatarType.lg,+ currentUserID: currentUserID,+ addStroke: false,+ ),+ ),+ ],+ ),+ );+ }++ Widget _buildSingleAvatar(User user) {+ return Container(+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: Colors.white,+ width: 1.167,+ ),+ ),+ child: UserAvatarWidget(+ user,+ type: AvatarType.lg,+ currentUserID: currentUserID,+ addStroke: false,+ ),+ );+ }++ List<User> _getActors() {+ final users = <User>[];+ final maxActors = feedItem.actorCount.clamp(1, 2);++ for (int i = 0; i < maxActors; i++) {+ final userID = feedItem.actorUserIDs[i];+ final anonID = feedItem.actorAnonIDs[i];++ if (userID <= 0 && anonID != null) {+ // Anonymous user+ users.add(+ User(+ id: userID,+ email: "[email protected]",+ name: anonID,+ ),+ );+ } else {+ // Get user from collections service+ final user = CollectionsService.instance+ .getFileOwner(userID, feedItem.collectionID);+ users.add(user);+ }+ }++ return users;+ }+}++/// Displays the text content: usernames and action description.+class _FeedTextContent extends StatelessWidget {+ final FeedItem feedItem;+ final int currentUserID;++ const _FeedTextContent({+ required this.feedItem,+ required this.currentUserID,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ final primaryUser = _getPrimaryUser();+ final primaryName = primaryUser.displayName ?? primaryUser.email;++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisSize: MainAxisSize.min,+ children: [+ // Username row+ _buildUsernameRow(context, primaryName, textTheme, colorScheme),+ const SizedBox(height: 2),+ // Action description+ Text(+ _getActionDescription(context),+ style: textTheme.mini.copyWith(+ color: colorScheme.textMuted,+ fontWeight: FontWeight.w500,+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ],+ );+ }++ Widget _buildUsernameRow(+ BuildContext context,+ String primaryName,+ EnteTextTheme textTheme,+ EnteColorScheme colorScheme,+ ) {+ if (!feedItem.hasMultipleActors) {+ // Single user+ return Text(+ primaryName,+ style: textTheme.small.copyWith(+ fontWeight: FontWeight.w600,+ color: colorScheme.textBase,+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ );+ }++ // Multiple users: "Username and X others"+ final othersCount = feedItem.additionalActorCount;+ final othersText = othersCount == 1+ ? AppLocalizations.of(context).and1Other+ : AppLocalizations.of(context).andXOthers(count: othersCount);++ return Text.rich(+ TextSpan(+ children: [+ TextSpan(+ text: primaryName,+ style: textTheme.small.copyWith(+ fontWeight: FontWeight.w600,+ color: colorScheme.textBase,+ ),+ ),+ TextSpan(+ text: " $othersText",+ style: textTheme.small.copyWith(+ fontWeight: FontWeight.w500,+ color: colorScheme.textMuted,+ ),+ ),+ ],+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ );+ }++ String _getActionDescription(BuildContext context) {+ final l10n = AppLocalizations.of(context);+ switch (feedItem.type) {+ case FeedItemType.photoLike:+ return l10n.likedYourPhoto;+ case FeedItemType.comment:+ return l10n.commentedOnYourPhoto;+ case FeedItemType.reply:+ return l10n.repliedToYourComment;+ case FeedItemType.commentLike:+ return l10n.likedYourComment;+ case FeedItemType.replyLike:+ return l10n.likedYourReply;+ }+ }++ User _getPrimaryUser() {+ final userID = feedItem.primaryActorUserID;+ final anonID = feedItem.primaryActorAnonID;++ if (userID <= 0 && anonID != null) {+ return User(+ id: userID,+ email: "[email protected]",+ name: anonID,+ );+ }++ return CollectionsService.instance+ .getFileOwner(userID, feedItem.collectionID);+ }+}++/// Displays the photo thumbnail for the feed item.+class _FeedThumbnail extends StatefulWidget {+ final int fileID;+ final int collectionID;++ const _FeedThumbnail({+ required this.fileID,+ required this.collectionID,+ });++ @override+ State<_FeedThumbnail> createState() => _FeedThumbnailState();+}++class _FeedThumbnailState extends State<_FeedThumbnail> {+ EnteFile? _file;+ bool _isLoading = true;++ @override+ void initState() {+ super.initState();+ _loadFile();+ }++ @override+ void didUpdateWidget(_FeedThumbnail oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.fileID != widget.fileID ||+ oldWidget.collectionID != widget.collectionID) {+ _loadFile();+ }+ }++ Future<void> _loadFile() async {+ setState(() => _isLoading = true);+ final file = await FilesDB.instance.getUploadedFile(+ widget.fileID,+ widget.collectionID,+ );+ if (mounted) {+ setState(() {+ _file = file;+ _isLoading = false;+ });+ }+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);++ if (_isLoading) {+ return Container(+ width: 66,+ height: 66,+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(7.792),+ ),+ );+ }++ if (_file == null) {+ return Container(+ width: 66,+ height: 66,+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(7.792),+ ),+ child: Icon(+ Icons.image_not_supported_outlined,+ color: colorScheme.strokeMuted,+ size: 24,+ ),+ );+ }++ return ClipRRect(+ borderRadius: BorderRadius.circular(7.792),+ child: SizedBox(+ width: 66,+ height: 66,+ child: ThumbnailWidget(+ _file!,+ fit: BoxFit.cover,+ rawThumbnail: true,+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/social/widgets/feed_preview_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/feed_preview_widget.dartnew file mode 100644index 0000000000..8cdee0a7fc--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_preview_widget.dart@@ -0,0 +1,94 @@+import "package:flutter/material.dart";+import "package:photos/core/configuration.dart";+import "package:photos/models/social/feed_data_provider.dart";+import "package:photos/models/social/feed_item.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/social/feed_screen.dart";+import "package:photos/ui/social/widgets/feed_item_widget.dart";+import "package:photos/utils/navigation_util.dart";++/// Widget that displays a preview of the latest feed item.+///+/// Shown in the Sharing tab to provide quick access to the activity feed.+class FeedPreviewWidget extends StatefulWidget {+ const FeedPreviewWidget({super.key});++ @override+ State<FeedPreviewWidget> createState() => _FeedPreviewWidgetState();+}++class _FeedPreviewWidgetState extends State<FeedPreviewWidget> {+ FeedItem? _latestItem;+ bool _isLoading = true;+ late final int _currentUserID;++ @override+ void initState() {+ super.initState();+ _currentUserID = Configuration.instance.getUserID() ?? 0;+ _loadLatestItem();+ }++ Future<void> _loadLatestItem() async {+ final item = await FeedDataProvider.instance.getLatestFeedItem();+ if (mounted) {+ setState(() {+ _latestItem = item;+ _isLoading = false;+ });+ }+ }++ void _onTap() {+ routeToPage(context, const FeedScreen());+ }++ @override+ Widget build(BuildContext context) {+ if (_isLoading) {+ return const SizedBox.shrink();+ }++ if (_latestItem == null) {+ return const SizedBox.shrink();+ }++ final colorScheme = getEnteColorScheme(context);++ return Padding(+ padding: const EdgeInsets.only(left: 4, right: 4, bottom: 8),+ child: Container(+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated,+ borderRadius: BorderRadius.circular(8),+ ),+ child: Material(+ color: Colors.transparent,+ child: InkWell(+ onTap: _onTap,+ borderRadius: BorderRadius.circular(8),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),+ child: Row(+ children: [+ Expanded(+ child: FeedItemWidget(+ feedItem: _latestItem!,+ currentUserID: _currentUserID,+ onTap: _onTap,+ ),+ ),+ Icon(+ Icons.chevron_right,+ color: colorScheme.strokeMuted,+ size: 24,+ ),+ ],+ ),+ ),+ ),+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dartindex 4176a200a8..cc948c30cc 100644--- a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart+++ b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart@@ -19,6 +19,7 @@ import "package:photos/ui/collections/album/row_item.dart";import "package:photos/ui/collections/collection_list_page.dart";import 'package:photos/ui/common/loading_widget.dart';import "package:photos/ui/components/buttons/icon_button_widget.dart";+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";@@ -161,6 +162,7 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>margin: const EdgeInsets.only(bottom: 50),child: Column(children: [+ const FeedPreviewWidget(),Column(mainAxisSize: MainAxisSize.min,children: [diff --git a/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart b/mobile/apps/photos/lib/utils/social/relative_time_formatter.dartindex 393656a72e..cbf3d28452 100644--- a/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart+++ b/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart@@ -5,8 +5,7 @@ import "package:intl/intl.dart";/// Server timestamps are in microseconds since epoch.String formatRelativeTime(int timestampMicros) {final now = DateTime.now();- final dateTime =- DateTime.fromMicrosecondsSinceEpoch(timestampMicros);+ final dateTime = DateTime.fromMicrosecondsSinceEpoch(timestampMicros);final difference = now.difference(dateTime);if (difference.inMinutes < 1) {