π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show shared albums as separate feed events
ashilkna118974323e6
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 142cc3e7fa..1f8404d6ca 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -2599,6 +2599,14 @@}}},+ "sharedAlbumWithYou": "Shared {albumName} with you",+ "@sharedAlbumWithYou": {+ "placeholders": {+ "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.dartindex ce8984df00..36595e6d69 100644--- a/mobile/apps/photos/lib/models/social/feed_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart@@ -3,6 +3,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/collection/collection.dart";import "package:photos/models/file/file.dart";import "package:photos/models/social/comment.dart";import "package:photos/models/social/feed_item.dart";@@ -27,6 +28,7 @@ class FeedDataProvider {static const _kSharedPhotoFetchMaxPages = 5;static const _kSharedPhotoFetchMaxRows =_kSharedPhotoFetchPageSize * _kSharedPhotoFetchMaxPages;+ static const _kSharedCollectionPreviewFileLimit = 30;static const _kFeedItemsCacheTtlMs = 3000;Future<List<FeedItem>>? _inFlightFeedItemsFuture;String? _inFlightFeedItemsKey;@@ -164,12 +166,33 @@ class FeedDataProvider {// Aggregate shared photos (files added by others to user's collections)if (includeSharedPhotos) {+ final sharedCollectionsContext =+ _SharedCollectionsContext.fromCollections(+ CollectionsService.instance.getCollectionsForUI(+ includedShared: true,+ includeCollab: true,+ ),+ userID: userID,+ );++ final sharedPhotoFeedResult = await _getSharedPhotoFeedResult(+ userID: userID,+ limit: limit,+ collectionNames: sharedCollectionsContext.collectionNames,+ incomingCollectionSharedAtByID:+ sharedCollectionsContext.incomingCollectionSharedAtByID,+ );+feedItems.addAll(- await _getSharedPhotoFeedItems(- userID: userID,- limit: limit,+ _getSharedCollectionFeedItems(+ sharedCollectionsContext.incomingSharedCollections,+ sharedCollectionsContext.collectionNames,+ initialSharedFileIDsByCollection:+ sharedPhotoFeedResult.initialSharedFileIDsByCollection,),);++ feedItems.addAll(sharedPhotoFeedResult.sharedPhotoFeedItems);}// Filter out items where the associated file doesn't exist or collection is hidden@@ -426,28 +449,22 @@ class FeedDataProvider {/// 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({+ Future<_SharedPhotoFeedResult> _getSharedPhotoFeedResult({required int userID,int limit = 50,+ required Map<int, String> collectionNames,+ required Map<int, int> incomingCollectionSharedAtByID,}) async {final sharedPhotoFeedCutoffTime =kDebugMode ? 0 : 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,);+ final initialSharedFileIDsByCollection = <int, List<int>>{};var retainedRows = 0;var oldestFetchedAddedTime = 0;@@ -470,6 +487,18 @@ class FeedDataProvider {hiddenCollectionIds.contains(collectionID)) {continue;}+ final incomingSharedAt = incomingCollectionSharedAtByID[collectionID];+ if (incomingSharedAt != null && addedTime <= incomingSharedAt) {+ final uploadedFileID = file.uploadedFileID;+ if (uploadedFileID != null) {+ _appendSharedCollectionPreviewFile(+ initialSharedFileIDsByCollection,+ collectionID: collectionID,+ uploadedFileID: uploadedFileID,+ );+ }+ continue;+ }oldestFetchedAddedTime = addedTime;groupingState.addFile(file);retainedRows++;@@ -491,7 +520,11 @@ class FeedDataProvider {final grouped = groupingState.buildSnapshotSorted();if (grouped.length < limit) {if (reachedEnd) {- return _toSharedPhotoFeedItems(grouped, collectionNames);+ return _toSharedPhotoFeedResult(+ grouped,+ collectionNames,+ initialSharedFileIDsByCollection,+ );}continue;}@@ -508,7 +541,11 @@ class FeedDataProvider {final topGroupsAreClosed = oldestFetchedAddedTime <(minOldestAddedTime - _kSharedPhotoSessionGapMicros);if (topGroupsAreClosed || reachedEnd) {- return _toSharedPhotoFeedItems(grouped, collectionNames);+ return _toSharedPhotoFeedResult(+ grouped,+ collectionNames,+ initialSharedFileIDsByCollection,+ );}}@@ -518,31 +555,87 @@ class FeedDataProvider {}if (retainedRows == 0) {- return [];+ return _SharedPhotoFeedResult(+ sharedPhotoFeedItems: const [],+ initialSharedFileIDsByCollection: initialSharedFileIDsByCollection,+ );}final grouped = groupingState.buildSnapshotSorted();- return _toSharedPhotoFeedItems(grouped, collectionNames);+ return _toSharedPhotoFeedResult(+ grouped,+ collectionNames,+ initialSharedFileIDsByCollection,+ );}- List<FeedItem> _toSharedPhotoFeedItems(+ _SharedPhotoFeedResult _toSharedPhotoFeedResult(List<_SharedPhotoGroup> groups,Map<int, String> collectionNames,+ Map<int, List<int>> initialSharedFileIDsByCollection,) {- return groups- .map(- (group) => FeedItem(- type: FeedItemType.sharedPhoto,- collectionID: group.collectionID,- fileID: group.sharedFileIDs.first,- actorUserIDs: [group.ownerID],+ return _SharedPhotoFeedResult(+ sharedPhotoFeedItems: 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(),+ initialSharedFileIDsByCollection: initialSharedFileIDsByCollection,+ );+ }++ void _appendSharedCollectionPreviewFile(+ Map<int, List<int>> initialSharedFileIDsByCollection, {+ required int collectionID,+ required int uploadedFileID,+ }) {+ final previewFiles = initialSharedFileIDsByCollection.putIfAbsent(+ collectionID,+ () => <int>[],+ );+ if (previewFiles.length >= _kSharedCollectionPreviewFileLimit) {+ return;+ }+ previewFiles.add(uploadedFileID);+ }++ List<FeedItem> _getSharedCollectionFeedItems(+ List<Collection> incomingSharedCollections,+ Map<int, String> collectionNames, {+ required Map<int, List<int>> initialSharedFileIDsByCollection,+ }) {+ return incomingSharedCollections+ .where((collection) => (collection.sharedAt ?? 0) > 0)+ .map((collection) {+ final ownerID = collection.owner.id;+ if (ownerID == null) {+ return null;+ }+ final sharedFileIDs = initialSharedFileIDsByCollection[collection.id];+ return FeedItem(+ type: FeedItemType.sharedCollection,+ collectionID: collection.id,+ fileID:+ sharedFileIDs?.isNotEmpty == true ? sharedFileIDs!.first : null,+ actorUserIDs: [ownerID],actorAnonIDs: [null],- createdAt: group.createdAt,+ createdAt: collection.sharedAt!,isOwnedByCurrentUser: false,- sharedFileIDs: group.sharedFileIDs,- collectionName: collectionNames[group.collectionID],- ),- )+ sharedFileIDs: sharedFileIDs,+ collectionName: collectionNames[collection.id],+ );+ })+ .whereType<FeedItem>().toList();}@@ -607,6 +700,55 @@ class FeedDataProvider {}}+class _SharedPhotoFeedResult {+ final List<FeedItem> sharedPhotoFeedItems;+ final Map<int, List<int>> initialSharedFileIDsByCollection;++ const _SharedPhotoFeedResult({+ required this.sharedPhotoFeedItems,+ required this.initialSharedFileIDsByCollection,+ });+}++class _SharedCollectionsContext {+ final Map<int, String> collectionNames;+ final List<Collection> incomingSharedCollections;+ final Map<int, int> incomingCollectionSharedAtByID;++ const _SharedCollectionsContext({+ required this.collectionNames,+ required this.incomingSharedCollections,+ required this.incomingCollectionSharedAtByID,+ });++ factory _SharedCollectionsContext.fromCollections(+ List<Collection> collections, {+ required int userID,+ }) {+ final collectionNames = <int, String>{};+ final incomingSharedCollections = <Collection>[];+ final incomingCollectionSharedAtByID = <int, int>{};++ for (final collection in collections) {+ collectionNames[collection.id] = collection.displayName;+ if (collection.isDeleted || collection.isOwner(userID)) {+ continue;+ }+ incomingSharedCollections.add(collection);+ final sharedAt = collection.sharedAt;+ if (sharedAt != null && sharedAt > 0) {+ incomingCollectionSharedAtByID[collection.id] = sharedAt;+ }+ }++ return _SharedCollectionsContext(+ collectionNames: collectionNames,+ incomingSharedCollections: incomingSharedCollections,+ incomingCollectionSharedAtByID: incomingCollectionSharedAtByID,+ );+ }+}+class _SharedPhotoGroup {final int collectionID;final int ownerID;diff --git a/mobile/apps/photos/lib/models/social/feed_item.dart b/mobile/apps/photos/lib/models/social/feed_item.dartindex fd7e1572e3..cbda9ab26e 100644--- a/mobile/apps/photos/lib/models/social/feed_item.dart+++ b/mobile/apps/photos/lib/models/social/feed_item.dart@@ -17,6 +17,9 @@ enum FeedItemType {/// Photos shared by others to user's albumssharedPhoto,++ /// Album shared with the current user+ sharedCollection,}/// Represents an activity item in the user's feed.@@ -51,8 +54,8 @@ class FeedItem {/// Only populated for [FeedItemType.sharedPhoto].final List<int>? sharedFileIDs;- /// Collection name for display in shared photo items.- /// Only populated for [FeedItemType.sharedPhoto].+ /// Collection name for display in shared items.+ /// Populated for [FeedItemType.sharedPhoto] and [FeedItemType.sharedCollection].final String? collectionName;const FeedItem({diff --git a/mobile/apps/photos/lib/services/social_notification_coordinator.dart b/mobile/apps/photos/lib/services/social_notification_coordinator.dartindex 5480feb8d6..a79c513628 100644--- a/mobile/apps/photos/lib/services/social_notification_coordinator.dart+++ b/mobile/apps/photos/lib/services/social_notification_coordinator.dart@@ -240,6 +240,7 @@ class SocialNotificationCoordinator {FeedItemType.commentLike => false,FeedItemType.replyLike => false,FeedItemType.sharedPhoto => false,+ FeedItemType.sharedCollection => false,};final title = await _getSocialNotificationTitle(candidate);await NotificationService.instance.showNotification(@@ -281,6 +282,7 @@ class SocialNotificationCoordinator {case FeedItemType.commentLike:case FeedItemType.replyLike:case FeedItemType.sharedPhoto:+ case FeedItemType.sharedCollection:return false;}}@@ -294,6 +296,7 @@ class SocialNotificationCoordinator {case FeedItemType.commentLike:case FeedItemType.replyLike:case FeedItemType.sharedPhoto:+ case FeedItemType.sharedCollection:return _SocialNotificationGroup.like;}}@@ -361,6 +364,9 @@ class SocialNotificationCoordinator {case FeedItemType.sharedPhoto:// Shared photos don't trigger notificationsreturn '';+ case FeedItemType.sharedCollection:+ // Shared collections 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.dartindex 08c2006071..0262772114 100644--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart@@ -324,6 +324,22 @@ class _FeedScreenState extends State<FeedScreen> {);return true;}+ if (target.type == FeedItemType.sharedPhoto ||+ target.type == FeedItemType.sharedCollection) {+ await _openSharedCollection(+ FeedItem(+ type: target.type,+ collectionID: target.collectionID,+ actorUserIDs: const [0],+ actorAnonIDs: const [null],+ createdAt: DateTime.now().microsecondsSinceEpoch,+ isOwnedByCurrentUser: false,+ sharedFileIDs: target.fileID != null ? [target.fileID!] : null,+ ),+ jumpToFileID: target.fileID,+ );+ return true;+ }var fileID = target.fileID;if (fileID == null && target.commentID != null) {@@ -476,6 +492,9 @@ class _FeedScreenState extends State<FeedScreen> {case FeedItemType.sharedPhoto:_openSharedPhotos(item);break;+ case FeedItemType.sharedCollection:+ _openSharedCollection(item);+ break;case FeedItemType.comment:case FeedItemType.reply:case FeedItemType.commentLike: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 ac082a45d1..0bfde0cf1c 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@@ -47,8 +47,9 @@ class FeedItemWidget extends StatelessWidget {@overrideWidget build(BuildContext context) {- // SharedPhoto has a different layout with photos grid below- if (feedItem.type == FeedItemType.sharedPhoto) {+ // Shared feed items have a different layout with photos grid below.+ if (feedItem.type == FeedItemType.sharedPhoto ||+ feedItem.type == FeedItemType.sharedCollection) {return _buildSharedPhotoLayout(context);}@@ -129,6 +130,9 @@ class FeedItemWidget extends StatelessWidget {}Widget _buildSharedPhotoLayout(BuildContext context) {+ final hasSharedPhotos =+ feedItem.sharedFileIDs != null && feedItem.sharedFileIDs!.isNotEmpty;+return Padding(padding: const EdgeInsets.symmetric(vertical: 18),child: Column(@@ -143,7 +147,8 @@ class FeedItemWidget extends StatelessWidget {_FeedTypeIconWithTimeline(type: feedItem.type,showTimeline: !isLastItem,- timelineExtensionHeight: 400, // Longer for shared photo layout+ timelineExtensionHeight:+ hasSharedPhotos ? 400 : 95, // Longer only when grid exists),const SizedBox(width: 10),// Avatar and text@@ -178,8 +183,7 @@ class FeedItemWidget extends StatelessWidget {],),// Photos grid below with left padding to align with text- if (feedItem.sharedFileIDs != null &&- feedItem.sharedFileIDs!.isNotEmpty)+ if (hasSharedPhotos)Padding(padding: const EdgeInsets.only(left: 42, top: 12),child: SharedPhotosGrid(@@ -324,6 +328,12 @@ class _FeedTypeIconWithTimeline extends StatelessWidget {size: 18,color: getEnteColorScheme(context).textMuted,);+ case FeedItemType.sharedCollection:+ return Icon(+ Icons.add_rounded,+ size: 18,+ color: getEnteColorScheme(context).textMuted,+ );}}}@@ -554,6 +564,9 @@ class _FeedTextContent extends StatelessWidget {return isOwn ? l10n.likedYourReply : l10n.likedAReply;case FeedItemType.sharedPhoto:return _getSharedPhotoDescription(context);+ case FeedItemType.sharedCollection:+ final albumName = feedItem.collectionName ?? l10n.albums;+ return l10n.sharedAlbumWithYou(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.dartindex c95b4aee06..4227dc4453 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@@ -333,6 +333,9 @@ class _PreviewTextContent extends StatelessWidget {} else {return l10n.addedNMemoriesTo(count: count, albumName: albumName);}+ case FeedItemType.sharedCollection:+ final albumName = feedItem.collectionName ?? l10n.albums;+ return l10n.sharedAlbumWithYou(albumName: albumName);}}