Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add internal shared photo feed items

Neeraj Gupta563c4044c0c9
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart
index 1533421655..99d07fcf5a 100644
--- a/mobile/apps/photos/lib/db/files_db.dart
+++ b/mobile/apps/photos/lib/db/files_db.dart
@@ -866,6 +866,77 @@ class FilesDB with SqlDbBase {
return files;
}
+ /// Gets multiple uploaded files by their IDs in a single query.
+ ///
+ /// Returns files in the same order as [fileIDs], with null for missing files.
+ /// More efficient than calling [getUploadedFile] multiple times.
+ Future<List<EnteFile?>> getUploadedFilesBatch(
+ List<int> fileIDs,
+ int collectionID,
+ ) async {
+ if (fileIDs.isEmpty) return [];
+
+ final db = await instance.sqliteAsyncDB;
+ final placeholders = fileIDs.map((_) => '?').join(',');
+ final query = '''
+ SELECT * FROM $filesTable
+ WHERE $columnUploadedFileID IN ($placeholders)
+ AND $columnCollectionID = ?
+ ''';
+
+ final results = await db.getAll(query, [...fileIDs, collectionID]);
+ final files = convertToFiles(results);
+
+ // Build a map for O(1) lookup
+ final fileMap = <int, EnteFile>{};
+ for (final file in files) {
+ if (file.uploadedFileID != null) {
+ fileMap[file.uploadedFileID!] = file;
+ }
+ }
+
+ // Return in same order as input, with null for missing
+ return fileIDs.map((id) => fileMap[id]).toList();
+ }
+
+ /// Gets files added by other users to user's collections.
+ ///
+ /// Returns files where owner_id != currentUserID, ordered by added_time DESC.
+ /// Used to populate the feed with shared photo items.
+ /// Hidden collections are filtered downstream in _filterFeedItems.
+ /// Offset is supported for paged fetches while aggregating feed groups.
+ Future<List<EnteFile>> getRecentlySharedFiles({
+ required int currentUserID,
+ int limit = 100,
+ int offset = 0,
+ int? addedTimeAfterOrEqualTo,
+ }) async {
+ final db = await instance.sqliteAsyncDB;
+ final whereClauses = <String>[
+ '$columnOwnerID IS NOT NULL',
+ '$columnOwnerID != ?',
+ '$columnAddedTime > 0',
+ '$columnUploadedFileID IS NOT NULL',
+ ];
+ final args = <Object>[currentUserID];
+ if (addedTimeAfterOrEqualTo != null) {
+ whereClauses.add('$columnAddedTime >= ?');
+ args.add(addedTimeAfterOrEqualTo);
+ }
+ args.add(limit);
+ args.add(offset);
+
+ final query = '''
+ SELECT * FROM $filesTable
+ WHERE ${whereClauses.join('\n AND ')}
+ ORDER BY $columnAddedTime DESC, $columnUploadedFileID DESC
+ LIMIT ?
+ OFFSET ?
+ ''';
+ final results = await db.getAll(query, args);
+ return convertToFiles(results);
+ }
+
Future<FileLoadResult> getFilesInCollections(
List<int> collectionIDs,
int startTime,
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index b9e128540f..b8b7b4ce12 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -2417,6 +2417,25 @@
"likedAComment": "Liked a comment",
"likedYourReply": "Liked your reply",
"likedAReply": "Liked a reply",
+ "addedAMemoryTo": "Added a memory to {albumName}",
+ "@addedAMemoryTo": {
+ "placeholders": {
+ "albumName": {
+ "type": "String"
+ }
+ }
+ },
+ "addedNMemoriesTo": "Added {count} memories to {albumName}",
+ "@addedNMemoriesTo": {
+ "placeholders": {
+ "count": {
+ "type": "int"
+ },
+ "albumName": {
+ "type": "String"
+ }
+ }
+ },
"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.dart
index 03035ba501..e0bb296e2e 100644
--- a/mobile/apps/photos/lib/models/social/feed_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart
@@ -6,6 +6,7 @@ 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";
+import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import 'package:photos/services/social_notification_coordinator.dart';
import "package:photos/services/social_sync_service.dart";
@@ -20,6 +21,11 @@ class FeedDataProvider {
final _logger = Logger('FeedDataProvider');
final _db = SocialDB.instance;
+ static const _kSharedPhotoSessionGapMicros = 1000 * 1000 * 60 * 10;
+ static const _kSharedPhotoFetchPageSize = 200;
+ static const _kSharedPhotoFetchMaxPages = 5;
+ static const _kSharedPhotoFetchMaxRows =
+ _kSharedPhotoFetchPageSize * _kSharedPhotoFetchMaxPages;
/// Gets feed items aggregated from local database.
///
@@ -104,6 +110,9 @@ class FeedDataProvider {
),
);
+ // Aggregate shared photos (files added by others to user's collections)
+ feedItems.addAll(await _getSharedPhotoFeedItems(userID: userID));
+
// Filter out items where the associated file doesn't exist or collection is hidden
final validItems = await _filterFeedItems(feedItems);
@@ -332,11 +341,143 @@ class FeedDataProvider {
.toList();
}
+ /// Gets shared photo feed items.
+ ///
+ /// Groups files added by others into session-like buckets using
+ /// (collectionID, ownerID) + a short addedTime gap.
+ /// Hidden collections are filtered downstream in _filterFeedItems.
+ Future<List<FeedItem>> _getSharedPhotoFeedItems({
+ required int userID,
+ int limit = 50,
+ }) async {
+ if (!flagService.internalUser) {
+ return [];
+ }
+
+ final sharedPhotoFeedCutoffTime =
+ await localSettings.getOrCreateSharedPhotoFeedCutoffTime();
+
+ // Build collection ID -> name map for display
+ final allCollections = CollectionsService.instance.getCollectionsForUI(
+ includedShared: true,
+ includeCollab: true,
+ );
+ final hiddenCollectionIds =
+ CollectionsService.instance.getHiddenCollectionIds();
+ final collectionNames = <int, String>{};
+ for (final c in allCollections) {
+ collectionNames[c.id] = c.displayName;
+ }
+
+ final groupingState = _SharedPhotoGroupingState(
+ sessionGapMicros: _kSharedPhotoSessionGapMicros,
+ );
+ var retainedRows = 0;
+ var oldestFetchedAddedTime = 0;
+
+ for (var page = 0; page < _kSharedPhotoFetchMaxPages; page++) {
+ final pageFiles = await FilesDB.instance.getRecentlySharedFiles(
+ currentUserID: userID,
+ limit: _kSharedPhotoFetchPageSize,
+ offset: page * _kSharedPhotoFetchPageSize,
+ addedTimeAfterOrEqualTo: sharedPhotoFeedCutoffTime,
+ );
+ if (pageFiles.isEmpty) {
+ break;
+ }
+
+ for (final file in pageFiles) {
+ final collectionID = file.collectionID;
+ final addedTime = file.addedTime;
+ if (collectionID == null ||
+ addedTime == null ||
+ hiddenCollectionIds.contains(collectionID)) {
+ continue;
+ }
+ oldestFetchedAddedTime = addedTime;
+ groupingState.addFile(file);
+ retainedRows++;
+ if (retainedRows >= _kSharedPhotoFetchMaxRows) {
+ break;
+ }
+ }
+
+ final reachedEnd = pageFiles.length < _kSharedPhotoFetchPageSize ||
+ retainedRows >= _kSharedPhotoFetchMaxRows;
+ if (retainedRows == 0) {
+ if (reachedEnd) {
+ break;
+ }
+ continue;
+ }
+
+ if (groupingState.roughGroupCount >= limit) {
+ final grouped = groupingState.buildSnapshotSorted();
+ if (grouped.length < limit) {
+ if (reachedEnd) {
+ return _toSharedPhotoFeedItems(grouped, collectionNames);
+ }
+ continue;
+ }
+ final topGroups = grouped.take(limit).toList();
+ var minOldestAddedTime = topGroups.first.oldestAddedTime;
+ for (final group in topGroups.skip(1)) {
+ if (group.oldestAddedTime < minOldestAddedTime) {
+ minOldestAddedTime = group.oldestAddedTime;
+ }
+ }
+
+ // Once we've scanned older than this threshold, unseen rows cannot
+ // extend any of the top groups.
+ final topGroupsAreClosed = oldestFetchedAddedTime <
+ (minOldestAddedTime - _kSharedPhotoSessionGapMicros);
+ if (topGroupsAreClosed || reachedEnd) {
+ return _toSharedPhotoFeedItems(grouped, collectionNames);
+ }
+ }
+
+ if (reachedEnd) {
+ break;
+ }
+ }
+
+ if (retainedRows == 0) {
+ return [];
+ }
+
+ final grouped = groupingState.buildSnapshotSorted();
+ return _toSharedPhotoFeedItems(grouped, collectionNames);
+ }
+
+ List<FeedItem> _toSharedPhotoFeedItems(
+ List<_SharedPhotoGroup> groups,
+ Map<int, String> collectionNames,
+ ) {
+ return groups
+ .map(
+ (group) => FeedItem(
+ type: FeedItemType.sharedPhoto,
+ collectionID: group.collectionID,
+ fileID: group.sharedFileIDs.first,
+ actorUserIDs: [group.ownerID],
+ actorAnonIDs: [null],
+ createdAt: group.createdAt,
+ isOwnedByCurrentUser: false,
+ sharedFileIDs: group.sharedFileIDs,
+ collectionName: collectionNames[group.collectionID],
+ ),
+ )
+ .toList();
+ }
+
/// Filters out feed items that should not be displayed.
///
/// Removes items where:
/// - The associated file no longer exists in FilesDB
/// - The collection is hidden
+ ///
+ /// For sharedPhoto items, filters out deleted files from sharedFileIDs
+ /// and only removes the item if ALL shared files are deleted.
Future<List<FeedItem>> _filterFeedItems(
List<FeedItem> items,
) async {
@@ -346,10 +487,15 @@ class FeedDataProvider {
final hiddenCollectionIds =
CollectionsService.instance.getHiddenCollectionIds();
- // Collect unique (fileID, collectionID) pairs
+ // Collect unique (fileID, collectionID) pairs - include all sharedFileIDs
final filesToCheck = <(int, int)>{};
for (final item in items) {
- if (item.fileID != null) {
+ if (item.type == FeedItemType.sharedPhoto && item.sharedFileIDs != null) {
+ // For shared items, check all files in the list
+ for (final fileID in item.sharedFileIDs!) {
+ filesToCheck.add((fileID, item.collectionID));
+ }
+ } else if (item.fileID != null) {
filesToCheck.add((item.fileID!, item.collectionID));
}
}
@@ -365,19 +511,155 @@ class FeedDataProvider {
final existingFiles =
await FilesDB.instance.getExistingFileKeys(filesToCheck);
- // Filter out invalid items
- return items.where((item) {
+ // Filter and transform items
+ final result = <FeedItem>[];
+ for (final item in items) {
// Exclude hidden collections
if (hiddenCollectionIds.contains(item.collectionID)) {
- return false;
+ continue;
+ }
+
+ // Handle sharedPhoto items specially
+ if (item.type == FeedItemType.sharedPhoto && item.sharedFileIDs != null) {
+ // Filter to only existing files
+ final existingSharedFiles = item.sharedFileIDs!.where((fileID) {
+ final key = '${item.collectionID}_$fileID';
+ return existingFiles.contains(key);
+ }).toList();
+
+ // Only keep item if at least one file still exists
+ if (existingSharedFiles.isNotEmpty) {
+ // Update item with filtered sharedFileIDs and new fileID
+ result.add(
+ item.copyWith(
+ sharedFileIDs: existingSharedFiles,
+ fileID: existingSharedFiles.first,
+ ),
+ );
+ }
+ continue;
}
+
// Items without fileID (collection-level activity) are kept
if (item.fileID == null) {
- return true;
+ result.add(item);
+ continue;
}
+
// Exclude items where file no longer exists
final key = '${item.collectionID}_${item.fileID}';
- return existingFiles.contains(key);
- }).toList();
+ if (existingFiles.contains(key)) {
+ result.add(item);
+ }
+ }
+
+ return result;
+ }
+}
+
+class _SharedPhotoGroup {
+ final int collectionID;
+ final int ownerID;
+ final int createdAt;
+ final int oldestAddedTime;
+ final List<int> sharedFileIDs;
+
+ const _SharedPhotoGroup({
+ required this.collectionID,
+ required this.ownerID,
+ required this.createdAt,
+ required this.oldestAddedTime,
+ required this.sharedFileIDs,
+ });
+}
+
+class _SharedPhotoGroupBuilder {
+ final int collectionID;
+ final int ownerID;
+ final int createdAt;
+ int oldestAddedTime;
+ final List<int> sharedFileIDs;
+
+ _SharedPhotoGroupBuilder({
+ required this.collectionID,
+ required this.ownerID,
+ required this.createdAt,
+ required int firstFileID,
+ }) : oldestAddedTime = createdAt,
+ sharedFileIDs = [firstFileID];
+
+ void add(int fileID, int addedTime) {
+ sharedFileIDs.add(fileID);
+ oldestAddedTime = addedTime;
+ }
+
+ _SharedPhotoGroup build() {
+ return _SharedPhotoGroup(
+ collectionID: collectionID,
+ ownerID: ownerID,
+ createdAt: createdAt,
+ oldestAddedTime: oldestAddedTime,
+ sharedFileIDs: List<int>.from(sharedFileIDs),
+ );
+ }
+}
+
+class _SharedPhotoGroupingState {
+ final int sessionGapMicros;
+ final Map<String, _SharedPhotoGroupBuilder> _activeGroups = {};
+ final List<_SharedPhotoGroup> _closedGroups = [];
+
+ _SharedPhotoGroupingState({
+ required this.sessionGapMicros,
+ });
+
+ int get roughGroupCount => _closedGroups.length + _activeGroups.length;
+
+ void addFile(EnteFile file) {
+ final addedTime = file.addedTime;
+ final ownerID = file.ownerID;
+ final collectionID = file.collectionID;
+ final uploadedFileID = file.uploadedFileID;
+ if (addedTime == null ||
+ ownerID == null ||
+ collectionID == null ||
+ uploadedFileID == null) {
+ return;
+ }
+
+ final key = '${collectionID}_$ownerID';
+ final currentGroup = _activeGroups[key];
+ if (currentGroup == null) {
+ _activeGroups[key] = _SharedPhotoGroupBuilder(
+ collectionID: collectionID,
+ ownerID: ownerID,
+ createdAt: addedTime,
+ firstFileID: uploadedFileID,
+ );
+ return;
+ }
+
+ final gapFromCurrentGroup = currentGroup.oldestAddedTime - addedTime;
+ if (gapFromCurrentGroup <= sessionGapMicros) {
+ currentGroup.add(uploadedFileID, addedTime);
+ return;
+ }
+
+ _closedGroups.add(currentGroup.build());
+ _activeGroups[key] = _SharedPhotoGroupBuilder(
+ collectionID: collectionID,
+ ownerID: ownerID,
+ createdAt: addedTime,
+ firstFileID: uploadedFileID,
+ );
+ }
+
+ List<_SharedPhotoGroup> buildSnapshotSorted() {
+ final groups = <_SharedPhotoGroup>[
+ ..._closedGroups,
+ ..._activeGroups.values.map((g) => g.build()),
+ ];
+ groups.sort((a, b) => b.createdAt.compareTo(a.createdAt));
+ return groups;
}
}
diff --git a/mobile/apps/photos/lib/models/social/feed_item.dart b/mobile/apps/photos/lib/models/social/feed_item.dart
index 99dfcf6c0b..fd7e1572e3 100644
--- a/mobile/apps/photos/lib/models/social/feed_item.dart
+++ b/mobile/apps/photos/lib/models/social/feed_item.dart
@@ -14,6 +14,9 @@ enum FeedItemType {
/// Reaction (like) on user's reply
replyLike,
+
+ /// Photos shared by others to user's albums
+ sharedPhoto,
}
/// Represents an activity item in the user's feed.
@@ -44,6 +47,14 @@ class FeedItem {
/// For commentLike/replyLike: whether the user wrote the liked comment/reply.
final bool isOwnedByCurrentUser;
+ /// File IDs for shared photo items (multiple photos can be grouped).
+ /// Only populated for [FeedItemType.sharedPhoto].
+ final List<int>? sharedFileIDs;
+
+ /// Collection name for display in shared photo items.
+ /// Only populated for [FeedItemType.sharedPhoto].
+ final String? collectionName;
+
const FeedItem({
required this.type,
required this.collectionID,
@@ -53,6 +64,8 @@ class FeedItem {
required this.actorAnonIDs,
required this.createdAt,
required this.isOwnedByCurrentUser,
+ this.sharedFileIDs,
+ this.collectionName,
});
/// Number of users who performed this action.
@@ -70,11 +83,16 @@ class FeedItem {
/// Number of additional actors beyond the primary.
int get additionalActorCount => actorCount - 1;
+ /// Number of shared files in this feed item.
+ /// Only meaningful for [FeedItemType.sharedPhoto].
+ int get sharedFileCount => sharedFileIDs?.length ?? 0;
+
@override
String toString() {
return 'FeedItem(type: $type, collectionID: $collectionID, '
'fileID: $fileID, commentID: $commentID, '
- 'actorCount: $actorCount, createdAt: $createdAt)';
+ 'actorCount: $actorCount, createdAt: $createdAt, '
+ 'sharedFileCount: $sharedFileCount)';
}
@override
@@ -92,4 +110,31 @@ class FeedItem {
int get hashCode {
return Object.hash(type, collectionID, fileID, commentID, createdAt);
}
+
+ /// Creates a copy of this FeedItem with the given fields replaced.
+ FeedItem copyWith({
+ FeedItemType? type,
+ int? collectionID,
+ int? fileID,
+ String? commentID,
+ List<int>? actorUserIDs,
+ List<String?>? actorAnonIDs,
+ int? createdAt,
+ bool? isOwnedByCurrentUser,
+ List<int>? sharedFileIDs,
+ String? collectionName,
+ }) {
+ return FeedItem(
+ type: type ?? this.type,
+ collectionID: collectionID ?? this.collectionID,
+ fileID: fileID ?? this.fileID,
+ commentID: commentID ?? this.commentID,
+ actorUserIDs: actorUserIDs ?? this.actorUserIDs,
+ actorAnonIDs: actorAnonIDs ?? this.actorAnonIDs,
+ createdAt: createdAt ?? this.createdAt,
+ isOwnedByCurrentUser: isOwnedByCurrentUser ?? this.isOwnedByCurrentUser,
+ sharedFileIDs: sharedFileIDs ?? this.sharedFileIDs,
+ collectionName: collectionName ?? this.collectionName,
+ );
+ }
}
diff --git a/mobile/apps/photos/lib/services/social_notification_coordinator.dart b/mobile/apps/photos/lib/services/social_notification_coordinator.dart
index 4f0c8df792..5480feb8d6 100644
--- a/mobile/apps/photos/lib/services/social_notification_coordinator.dart
+++ b/mobile/apps/photos/lib/services/social_notification_coordinator.dart
@@ -239,6 +239,7 @@ class SocialNotificationCoordinator {
FeedItemType.reply => candidate.parentCommentUserID == userID,
FeedItemType.commentLike => false,
FeedItemType.replyLike => false,
+ FeedItemType.sharedPhoto => false,
};
final title = await _getSocialNotificationTitle(candidate);
await NotificationService.instance.showNotification(
@@ -279,6 +280,7 @@ class SocialNotificationCoordinator {
return true;
case FeedItemType.commentLike:
case FeedItemType.replyLike:
+ case FeedItemType.sharedPhoto:
return false;
}
}
@@ -291,6 +293,7 @@ class SocialNotificationCoordinator {
case FeedItemType.photoLike:
case FeedItemType.commentLike:
case FeedItemType.replyLike:
+ case FeedItemType.sharedPhoto:
return _SocialNotificationGroup.like;
}
}
@@ -355,6 +358,9 @@ class SocialNotificationCoordinator {
return s.likedYourComment;
case FeedItemType.replyLike:
return s.likedYourReply;
+ case FeedItemType.sharedPhoto:
+ // Shared photos don't trigger notifications
+ return '';
}
}
diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dart
index 6689d37636..ad0ea0c1bb 100644
--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart
@@ -6,6 +6,7 @@ import "package:logging/logging.dart";
import "package:photos/core/configuration.dart";
import "package:photos/db/files_db.dart";
import "package:photos/generated/l10n.dart";
+import "package:photos/models/file/file.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";
@@ -303,9 +304,7 @@ class _FeedScreenState extends State<FeedScreen> {
_anonDisplayNamesByCollection[item.collectionID] ??
const {},
isLastItem: isLastItem,
- onTap: () => item.type == FeedItemType.photoLike
- ? _openPhoto(item)
- : _openComments(item),
+ onTap: () => _handleFeedItemTap(item),
);
},
),
@@ -342,6 +341,23 @@ class _FeedScreenState extends State<FeedScreen> {
);
}
+ void _handleFeedItemTap(FeedItem item) {
+ switch (item.type) {
+ case FeedItemType.photoLike:
+ _openPhoto(item);
+ break;
+ case FeedItemType.sharedPhoto:
+ _openSharedPhotos(item);
+ break;
+ case FeedItemType.comment:
+ case FeedItemType.reply:
+ case FeedItemType.commentLike:
+ case FeedItemType.replyLike:
+ _openComments(item);
+ break;
+ }
+ }
+
/// Opens the photo viewer for the feed item, then shows the comments sheet.
Future<void> _openComments(FeedItem item) async {
var fileID = item.fileID;
@@ -418,4 +434,33 @@ class _FeedScreenState extends State<FeedScreen> {
),
);
}
+
+ /// Opens a gallery view of the shared photos.
+ Future<void> _openSharedPhotos(FeedItem item) async {
+ final fileIDs = item.sharedFileIDs;
+ if (fileIDs == null || fileIDs.isEmpty) return;
+
+ // Load all files using batch query
+ final loadedFiles = await FilesDB.instance.getUploadedFilesBatch(
+ fileIDs,
+ item.collectionID,
+ );
+ final files = loadedFiles.whereType<EnteFile>().toList();
+
+ if (files.isEmpty || !mounted) return;
+
+ unawaited(
+ routeToPage(
+ context,
+ DetailPage(
+ DetailPageConfiguration(
+ files,
+ 0,
+ "feed_shared_photos",
+ ),
+ ),
+ forceCustomPageRoute: true,
+ ),
+ );
+ }
}
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.dart
index 1b8d2ade7b..711fac0e25 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
@@ -11,6 +11,7 @@ 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/social/widgets/shared_photos_grid.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
/// Widget that displays a single feed item.
@@ -38,6 +39,15 @@ class FeedItemWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ // SharedPhoto has a different layout with photos grid below
+ if (feedItem.type == FeedItemType.sharedPhoto) {
+ return _buildSharedPhotoLayout(context);
+ }
+
+ return _buildDefaultLayout(context);
+ }
+
+ Widget _buildDefaultLayout(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
return Padding(
@@ -109,6 +119,64 @@ class FeedItemWidget extends StatelessWidget {
),
);
}
+
+ Widget _buildSharedPhotoLayout(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 18),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Header row: Icon + Avatar + Text
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ // Feed type icon with timeline line
+ _FeedTypeIconWithTimeline(
+ type: feedItem.type,
+ showTimeline: !isLastItem,
+ timelineExtensionHeight: 400, // Longer for shared photo layout
+ ),
+ const SizedBox(width: 10),
+ // Avatar and text
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Avatar
+ _StackedAvatars(
+ feedItem: feedItem,
+ currentUserID: currentUserID,
+ anonDisplayNames: anonDisplayNames,
+ ),
+ const SizedBox(height: 4),
+ // Text content
+ _FeedTextContent(
+ feedItem: feedItem,
+ currentUserID: currentUserID,
+ anonDisplayNames: anonDisplayNames,
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ // Photos grid below with left padding to align with text
+ if (feedItem.sharedFileIDs != null &&
+ feedItem.sharedFileIDs!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(left: 42, top: 12),
+ child: SharedPhotosGrid(
+ fileIDs: feedItem.sharedFileIDs!,
+ collectionID: feedItem.collectionID,
+ onTap: onTap,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
}
/// Displays the feed type icon with optional timeline line passing through center.
@@ -120,7 +188,7 @@ class _FeedTypeIconWithTimeline extends StatelessWidget {
/// Height of the timeline line extending below the icon.
/// Extends from icon center through text content and padding to next item's icon.
- static const double _timelineExtensionHeight = 95;
+ final double timelineExtensionHeight;
/// Width of the dashed timeline line.
static const double _timelineWidth = 1.5;
@@ -128,6 +196,7 @@ class _FeedTypeIconWithTimeline extends StatelessWidget {
const _FeedTypeIconWithTimeline({
required this.type,
required this.showTimeline,
+ this.timelineExtensionHeight = 95,
});
@override
@@ -150,7 +219,7 @@ class _FeedTypeIconWithTimeline extends StatelessWidget {
left: (32 - _timelineWidth) / 2, // Center the line
top: 16, // Start from icon center
child: CustomPaint(
- size: const Size(_timelineWidth, _timelineExtensionHeight),
+ size: Size(_timelineWidth, timelineExtensionHeight),
painter: _DashedLinePainter(color: timelineColor),
),
),
@@ -233,6 +302,12 @@ class _FeedTypeIconWithTimeline extends StatelessWidget {
),
],
);
+ case FeedItemType.sharedPhoto:
+ return Icon(
+ Icons.add_box_outlined,
+ size: 18,
+ color: getEnteColorScheme(context).textMuted,
+ );
}
}
}
@@ -461,6 +536,20 @@ class _FeedTextContent extends StatelessWidget {
return isOwn ? l10n.likedYourComment : l10n.likedAComment;
case FeedItemType.replyLike:
return isOwn ? l10n.likedYourReply : l10n.likedAReply;
+ case FeedItemType.sharedPhoto:
+ return _getSharedPhotoDescription(context);
+ }
+ }
+
+ String _getSharedPhotoDescription(BuildContext context) {
+ final l10n = AppLocalizations.of(context);
+ final count = feedItem.sharedFileCount;
+ final albumName = feedItem.collectionName ?? l10n.albums;
+
+ if (count == 1) {
+ return l10n.addedAMemoryTo(albumName: albumName);
+ } else {
+ return l10n.addedNMemoriesTo(count: count, albumName: albumName);
}
}
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.dart
index bdceda432c..c95b4aee06 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
@@ -325,6 +325,14 @@ class _PreviewTextContent extends StatelessWidget {
return isOwn ? l10n.likedYourComment : l10n.likedAComment;
case FeedItemType.replyLike:
return isOwn ? l10n.likedYourReply : l10n.likedAReply;
+ case FeedItemType.sharedPhoto:
+ final count = feedItem.sharedFileCount;
+ final albumName = feedItem.collectionName ?? l10n.albums;
+ if (count == 1) {
+ return l10n.addedAMemoryTo(albumName: albumName);
+ } else {
+ return l10n.addedNMemoriesTo(count: count, albumName: albumName);
+ }
}
}
diff --git a/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart
new file mode 100644
index 0000000000..859b418e81
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart
@@ -0,0 +1,310 @@
+import "package:flutter/foundation.dart";
+import "package:flutter/material.dart";
+import "package:photos/db/files_db.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/viewer/file/thumbnail_widget.dart";
+
+/// Displays a grid of shared photos with different layouts based on count.
+///
+/// Layouts:
+/// - 1 photo: Full width, aspect ratio based on image
+/// - 2 photos: Vertical stack (two rows)
+/// - 3 photos: 2 on top, 1 on bottom spanning full width
+/// - 4+ photos: 2x2 grid with "+N" overlay on last cell if more than 4
+class SharedPhotosGrid extends StatefulWidget {
+ /// List of file IDs to display.
+ final List<int> fileIDs;
+
+ /// Collection ID for loading files.
+ final int collectionID;
+
+ /// Called when user taps on the grid.
+ final VoidCallback? onTap;
+
+ /// Size of the grid (width). Height is calculated based on layout.
+ final double gridSize;
+
+ const SharedPhotosGrid({
+ required this.fileIDs,
+ required this.collectionID,
+ this.onTap,
+ this.gridSize = 300,
+ super.key,
+ });
+
+ @override
+ State<SharedPhotosGrid> createState() => _SharedPhotosGridState();
+}
+
+class _SharedPhotosGridState extends State<SharedPhotosGrid> {
+ List<EnteFile?> _files = [];
+ bool _isLoading = true;
+
+ @override
+ void initState() {
+ super.initState();
+ _loadFiles();
+ }
+
+ @override
+ void didUpdateWidget(SharedPhotosGrid oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (!listEquals(oldWidget.fileIDs, widget.fileIDs) ||
+ oldWidget.collectionID != widget.collectionID) {
+ _loadFiles();
+ }
+ }
+
+ Future<void> _loadFiles() async {
+ setState(() => _isLoading = true);
+
+ // Load up to 4 files for display using batch query
+ final filesToLoad = widget.fileIDs.take(4).toList();
+ final files = await FilesDB.instance.getUploadedFilesBatch(
+ filesToLoad,
+ widget.collectionID,
+ );
+
+ if (mounted) {
+ setState(() {
+ _files = files;
+ _isLoading = false;
+ });
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
+ if (_isLoading) {
+ return Container(
+ width: widget.gridSize,
+ height: widget.gridSize,
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ );
+ }
+
+ final validFiles = _files.whereType<EnteFile>().toList();
+ if (validFiles.isEmpty) {
+ return Container(
+ width: widget.gridSize,
+ height: widget.gridSize,
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Icon(
+ Icons.photo_library_outlined,
+ color: colorScheme.strokeMuted,
+ size: 48,
+ ),
+ );
+ }
+
+ return GestureDetector(
+ onTap: widget.onTap,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(12),
+ child: SizedBox(
+ width: widget.gridSize,
+ height: widget.gridSize,
+ child: _buildGrid(validFiles),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildGrid(List<EnteFile> files) {
+ final count = files.length;
+ final totalCount = widget.fileIDs.length;
+ final extraCount = totalCount - 4;
+
+ switch (count) {
+ case 1:
+ return _buildSinglePhoto(files[0]);
+ case 2:
+ return _buildTwoPhotos(files);
+ case 3:
+ return _buildThreePhotos(files);
+ default:
+ return _buildFourPlusPhotos(files, extraCount);
+ }
+ }
+
+ Widget _buildSinglePhoto(EnteFile file) {
+ return ThumbnailWidget(
+ file,
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ );
+ }
+
+ Widget _buildTwoPhotos(List<EnteFile> files) {
+ const gap = 4.0;
+ final itemHeight = (widget.gridSize - gap) / 2;
+
+ return Column(
+ children: [
+ SizedBox(
+ height: itemHeight,
+ width: widget.gridSize,
+ child: ThumbnailWidget(
+ files[0],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ const SizedBox(height: gap),
+ SizedBox(
+ height: itemHeight,
+ width: widget.gridSize,
+ child: ThumbnailWidget(
+ files[1],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildThreePhotos(List<EnteFile> files) {
+ const gap = 4.0;
+ final itemWidth = (widget.gridSize - gap) / 2;
+ final itemHeight = (widget.gridSize - gap) / 2;
+
+ return Column(
+ children: [
+ // Top row: 2 photos
+ Row(
+ children: [
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: ThumbnailWidget(
+ files[0],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ const SizedBox(width: gap),
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: ThumbnailWidget(
+ files[1],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: gap),
+ // Bottom row: 1 photo spanning full width
+ SizedBox(
+ height: itemHeight,
+ width: widget.gridSize,
+ child: ThumbnailWidget(
+ files[2],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildFourPlusPhotos(List<EnteFile> files, int extraCount) {
+ const gap = 4.0;
+ final itemWidth = (widget.gridSize - gap) / 2;
+ final itemHeight = (widget.gridSize - gap) / 2;
+
+ return Column(
+ children: [
+ // Top row
+ Row(
+ children: [
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: ThumbnailWidget(
+ files[0],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ const SizedBox(width: gap),
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: ThumbnailWidget(
+ files[1],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: gap),
+ // Bottom row
+ Row(
+ children: [
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: ThumbnailWidget(
+ files[2],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ ),
+ const SizedBox(width: gap),
+ // Fourth photo with optional +N overlay
+ SizedBox(
+ height: itemHeight,
+ width: itemWidth,
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ ThumbnailWidget(
+ files[3],
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
+ if (extraCount > 0) _buildExtraCountOverlay(extraCount),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+
+ Widget _buildExtraCountOverlay(int extraCount) {
+ return Positioned(
+ right: 4,
+ bottom: 4,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
+ decoration: BoxDecoration(
+ color: const Color(0x99000000),
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: Text(
+ '+$extraCount',
+ style: const TextStyle(
+ color: Colors.white,
+ fontSize: 13,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dart
index a61cc309d5..2661bfe443 100644
--- a/mobile/apps/photos/lib/utils/local_settings.dart
+++ b/mobile/apps/photos/lib/utils/local_settings.dart
@@ -61,6 +61,7 @@ class LocalSettings {
static const kShowLocalIDOverThumbnails = "show_local_id_over_thumbnails";
static const kEnableDatabaseLogging = "enable_db_logging";
static const _kInternalUserDisabled = "ls.internal_user_disabled";
+ static const _kSharedPhotoFeedCutoffTime = "ls.shared_photo_feed_cutoff_time";
static const _kWrapped2025ResumeIndex = "ls.wrapped_2025_resume_index";
static const _kWrapped2025Complete = "ls.wrapped_2025_complete";
static const _kAppLockEnabled = "ls.app_lock_enabled";
@@ -378,6 +379,18 @@ class LocalSettings {
await _prefs.setBool(_kInternalUserDisabled, value);
}
+ Future<int> getOrCreateSharedPhotoFeedCutoffTime() async {
+ final existingCutoff = _prefs.getInt(_kSharedPhotoFeedCutoffTime);
+ if (existingCutoff != null) {
+ return existingCutoff;
+ }
+
+ // files.added_time is stored in microseconds since epoch.
+ final cutoff = DateTime.now().microsecondsSinceEpoch;
+ await _prefs.setInt(_kSharedPhotoFeedCutoffTime, cutoff);
+ return cutoff;
+ }
+
int wrapped2025ResumeIndex() {
return _prefs.getInt(_kWrapped2025ResumeIndex) ?? 0;
}