Skip to content

armgit / ente

Public Imported from GitHub
0

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

Feed 3/n

Neeraj Guptafc25979af97f
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart
index 2790418a64..2e4e4603a2 100644
--- a/mobile/apps/photos/lib/db/files_db.dart
+++ b/mobile/apps/photos/lib/db/files_db.dart
@@ -587,6 +587,56 @@ class FilesDB with SqlDbBase {
return ids;
}
+ /// Checks which (fileID, collectionID) pairs exist in the database.
+ ///
+ /// Returns a set of keys in the format "collectionID_fileID" for files that exist.
+ /// This is more efficient than calling getUploadedFile() for each pair.
+ Future<Set<String>> getExistingFileKeys(
+ Set<(int fileID, int collectionID)> pairs,
+ ) async {
+ if (pairs.isEmpty) return {};
+
+ final db = await instance.sqliteAsyncDB;
+ final existingKeys = <String>{};
+
+ // Build a query with OR conditions for each pair
+ // SQLite has a limit on compound SELECT statements, so we batch
+ const batchSize = 100;
+ final pairsList = pairs.toList();
+
+ for (var i = 0; i < pairsList.length; i += batchSize) {
+ final batch = pairsList.sublist(
+ i,
+ i + batchSize > pairsList.length ? pairsList.length : i + batchSize,
+ );
+
+ final conditions = batch
+ .map(
+ (_) => '($columnUploadedFileID = ? AND $columnCollectionID = ?)',
+ )
+ .join(' OR ');
+
+ final args = <Object>[];
+ for (final (fileID, collectionID) in batch) {
+ args.add(fileID);
+ args.add(collectionID);
+ }
+
+ final results = await db.getAll(
+ 'SELECT $columnUploadedFileID, $columnCollectionID FROM $filesTable WHERE $conditions',
+ args,
+ );
+
+ for (final row in results) {
+ final fileID = row[columnUploadedFileID] as int;
+ final collectionID = row[columnCollectionID] as int;
+ existingKeys.add('${collectionID}_$fileID');
+ }
+ }
+
+ return existingKeys;
+ }
+
Future<(Set<int>, Map<String, int>)> getUploadAndHash(
int collectionID,
) async {
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
index 6778022c2e..f6a071c854 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.social2.db";
+ static const _databaseName = "ente.social3.db";
static const _databaseVersion = 1;
static const _commentsTable = 'comments';
@@ -87,7 +87,7 @@ class SocialDB {
CREATE TABLE $_anonProfilesTable (
anon_user_id TEXT NOT NULL,
collection_id INTEGER NOT NULL,
- display_name TEXT NOT NULL,
+ data TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
PRIMARY KEY (anon_user_id, collection_id)
@@ -782,7 +782,7 @@ class SocialDB {
return {
'anon_user_id': profile.anonUserID,
'collection_id': profile.collectionID,
- 'display_name': profile.displayName,
+ 'data': profile.data,
'created_at': profile.createdAt,
'updated_at': profile.updatedAt,
};
@@ -792,7 +792,7 @@ class SocialDB {
return AnonProfile(
anonUserID: row['anon_user_id'] as String,
collectionID: row['collection_id'] as int,
- displayName: row['display_name'] as String,
+ data: row['data'] as String,
createdAt: row['created_at'] as int,
updatedAt: row['updated_at'] as int,
);
diff --git a/mobile/apps/photos/lib/events/social_data_updated_event.dart b/mobile/apps/photos/lib/events/social_data_updated_event.dart
new file mode 100644
index 0000000000..e21f2d2783
--- /dev/null
+++ b/mobile/apps/photos/lib/events/social_data_updated_event.dart
@@ -0,0 +1,25 @@
+import "package:photos/events/event.dart";
+
+/// Event fired when social data (comments, reactions) has been synced.
+///
+/// Used to notify UI components that they should refresh their display.
+class SocialDataUpdatedEvent extends Event {
+ /// The collection ID that was synced, or null if multiple collections were synced.
+ final int? collectionID;
+
+ /// Whether new comments were synced.
+ final bool hasNewComments;
+
+ /// Whether new reactions were synced.
+ final bool hasNewReactions;
+
+ SocialDataUpdatedEvent({
+ this.collectionID,
+ this.hasNewComments = false,
+ this.hasNewReactions = false,
+ });
+
+ @override
+ String get reason =>
+ 'SocialDataUpdatedEvent{collectionID: $collectionID, comments: $hasNewComments, reactions: $hasNewReactions}';
+}
diff --git a/mobile/apps/photos/lib/models/social/anon_profile.dart b/mobile/apps/photos/lib/models/social/anon_profile.dart
index 01641bf529..5f1ba2a4e1 100644
--- a/mobile/apps/photos/lib/models/social/anon_profile.dart
+++ b/mobile/apps/photos/lib/models/social/anon_profile.dart
@@ -1,7 +1,9 @@
+import 'dart:convert';
+
/// Decrypted anonymous user profile stored locally.
///
-/// Stores the decrypted display name for anonymous users who interact
-/// via shared album links.
+/// Stores the decrypted profile data (JSON) for anonymous users who interact
+/// via shared album links. The raw JSON is preserved for forward compatibility.
class AnonProfile {
/// The anonymous user ID (e.g., "anon_abc123")
final String anonUserID;
@@ -9,8 +11,10 @@ class AnonProfile {
/// The collection this profile belongs to
final int collectionID;
- /// The decrypted display name
- final String displayName;
+ /// The decrypted profile data as raw JSON string.
+ /// Format: {"userName": "..."}
+ /// May contain additional fields in future versions.
+ final String data;
/// When the profile was created (microseconds since epoch)
final int createdAt;
@@ -21,8 +25,21 @@ class AnonProfile {
AnonProfile({
required this.anonUserID,
required this.collectionID,
- required this.displayName,
+ required this.data,
required this.createdAt,
required this.updatedAt,
});
+
+ /// Extracts the display name from the JSON data.
+ ///
+ /// Returns the userName field if present, otherwise returns null.
+ String? get displayName {
+ if (data.isEmpty) return null;
+ try {
+ final json = jsonDecode(data) as Map<String, dynamic>;
+ return json['userName'] as String?;
+ } catch (_) {
+ return null;
+ }
+ }
}
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 6aed54ed01..d39a748095 100644
--- a/mobile/apps/photos/lib/models/social/feed_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/feed_data_provider.dart
@@ -292,34 +292,18 @@ class FeedDataProvider {
if (items.isEmpty) return items;
// Collect unique (fileID, collectionID) pairs
- final filesToCheck = <String, (int fileID, int collectionID)>{};
+ final filesToCheck = <(int, int)>{};
for (final item in items) {
if (item.fileID != null) {
- final key = '${item.collectionID}_${item.fileID}';
- filesToCheck[key] = (item.fileID!, item.collectionID);
+ filesToCheck.add((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);
- }
- }
+ // Check which files exist using batch query (single DB call)
+ final existingFiles =
+ await FilesDB.instance.getExistingFileKeys(filesToCheck);
// Filter items to only include those with existing files
return items.where((item) {
diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dart
index 8ca120b5ad..ec61f821db 100644
--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart
@@ -293,4 +293,36 @@ class SocialDataProvider {
}
return null;
}
+
+ // ============ Anon Profile methods ============
+
+ /// Gets the decrypted display name for an anonymous user.
+ ///
+ /// Returns the display name from the synced AnonProfile if available,
+ /// otherwise returns [fallback] (typically the raw anonUserID).
+ Future<String> getAnonDisplayName(
+ String anonUserID,
+ int collectionID, {
+ String? fallback,
+ }) async {
+ final profile = await _db.getAnonProfile(anonUserID, collectionID);
+ return profile?.displayName ?? fallback ?? anonUserID;
+ }
+
+ /// Gets all anon profiles for a collection as a map of anonUserID -> displayName.
+ ///
+ /// Only includes profiles where displayName could be extracted from the data.
+ Future<Map<String, String>> getAnonDisplayNamesForCollection(
+ int collectionID,
+ ) async {
+ final profiles = await _db.getAnonProfilesForCollection(collectionID);
+ final result = <String, String>{};
+ for (final p in profiles) {
+ final name = p.displayName;
+ if (name != null) {
+ result[p.anonUserID] = name;
+ }
+ }
+ return result;
+ }
}
diff --git a/mobile/apps/photos/lib/services/social_service.dart b/mobile/apps/photos/lib/services/social_service.dart
index 9b7039f269..16da09b68e 100644
--- a/mobile/apps/photos/lib/services/social_service.dart
+++ b/mobile/apps/photos/lib/services/social_service.dart
@@ -500,9 +500,10 @@ class SocialService {
return padded.substring(0, nullIndex);
}
- /// Decrypts anonymous profile name.
+ /// Decrypts anonymous profile data.
///
- /// Returns the decrypted display name, or empty string if decryption fails.
+ /// Returns the decrypted JSON string, or empty string if decryption fails.
+ /// The payload is JSON: {"userName": "..."} (may have more fields in future).
String decryptAnonProfile(String? cipher, String? nonce, int collectionID) {
if (cipher == null || nonce == null || cipher.isEmpty || nonce.isEmpty) {
return '';
diff --git a/mobile/apps/photos/lib/services/social_sync_service.dart b/mobile/apps/photos/lib/services/social_sync_service.dart
index cdd1c782a8..524b7c0ac5 100644
--- a/mobile/apps/photos/lib/services/social_sync_service.dart
+++ b/mobile/apps/photos/lib/services/social_sync_service.dart
@@ -1,6 +1,8 @@
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
+import 'package:photos/core/event_bus.dart';
import 'package:photos/db/social_db.dart';
+import 'package:photos/events/social_data_updated_event.dart';
import 'package:photos/models/social/anon_profile.dart';
import 'package:photos/models/social/api_responses.dart';
import 'package:photos/models/social/comment.dart';
@@ -171,12 +173,26 @@ class SocialSyncService {
);
int syncedCount = 0;
+ bool hasNewComments = false;
+ bool hasNewReactions = false;
+
for (final update in latestUpdates.updates) {
try {
- final needsSync = await _needsSync(update);
- if (needsSync) {
+ final localCommentsSyncTime =
+ await _db.getCommentsSyncTime(update.collectionID);
+ final localReactionsSyncTime =
+ await _db.getReactionsSyncTime(update.collectionID);
+
+ final needsCommentsSync = update.commentsUpdatedAt != null &&
+ update.commentsUpdatedAt! > localCommentsSyncTime;
+ final needsReactionsSync = update.reactionsUpdatedAt != null &&
+ update.reactionsUpdatedAt! > localReactionsSyncTime;
+
+ if (needsCommentsSync || needsReactionsSync) {
await syncCollection(update.collectionID);
syncedCount++;
+ hasNewComments = hasNewComments || needsCommentsSync;
+ hasNewReactions = hasNewReactions || needsReactionsSync;
}
// Sync anon profiles if needed
@@ -196,6 +212,16 @@ class SocialSyncService {
}
_logger.info('Synced $syncedCount collections with new updates');
+
+ // Fire event if any data was synced
+ if (syncedCount > 0) {
+ Bus.instance.fire(
+ SocialDataUpdatedEvent(
+ hasNewComments: hasNewComments,
+ hasNewReactions: hasNewReactions,
+ ),
+ );
+ }
} catch (e) {
_logger.severe('Failed to fetch latest updates', e);
} finally {
@@ -203,28 +229,6 @@ class SocialSyncService {
}
}
- /// Checks if a collection needs syncing based on server vs local timestamps.
- Future<bool> _needsSync(CollectionLatestUpdate update) async {
- final localCommentsSyncTime =
- await _db.getCommentsSyncTime(update.collectionID);
- final localReactionsSyncTime =
- await _db.getReactionsSyncTime(update.collectionID);
-
- // Check if comments need sync
- if (update.commentsUpdatedAt != null &&
- update.commentsUpdatedAt! > localCommentsSyncTime) {
- return true;
- }
-
- // Check if reactions need sync
- if (update.reactionsUpdatedAt != null &&
- update.reactionsUpdatedAt! > localReactionsSyncTime) {
- return true;
- }
-
- return false;
- }
-
/// Syncs anonymous profiles for a collection.
Future<void> syncAnonProfiles(int collectionID) async {
try {
@@ -238,7 +242,7 @@ class SocialSyncService {
final profiles = <AnonProfile>[];
for (final apiProfile in response.profiles) {
- final displayName = _api.decryptAnonProfile(
+ final data = _api.decryptAnonProfile(
apiProfile.cipher,
apiProfile.nonce,
collectionID,
@@ -248,7 +252,7 @@ class SocialSyncService {
AnonProfile(
anonUserID: apiProfile.anonUserID,
collectionID: apiProfile.collectionID,
- displayName: displayName,
+ data: data,
createdAt: apiProfile.createdAt,
updatedAt: apiProfile.updatedAt,
),
diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dart
index 6dd66594b2..2e40ce5e80 100644
--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart
@@ -47,6 +47,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {
bool _hasMoreComments = true;
int _offset = 0;
final Map<int, User> _userCache = {};
+ Map<String, String> _anonDisplayNames = {};
String? _highlightedCommentID;
bool _hasScrolledToHighlight = false;
@@ -138,16 +139,23 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {
setState(() => _isLoading = true);
// Load local data first for immediate display
- final comments =
- await SocialDataProvider.instance.getCommentsForFilePaginated(
- widget.fileID,
- collectionID: _selectedCollectionID,
- limit: _pageSize,
- offset: 0,
- );
+ final results = await Future.wait([
+ SocialDataProvider.instance.getCommentsForFilePaginated(
+ widget.fileID,
+ collectionID: _selectedCollectionID,
+ limit: _pageSize,
+ offset: 0,
+ ),
+ SocialDataProvider.instance
+ .getAnonDisplayNamesForCollection(_selectedCollectionID),
+ ]);
+
+ final comments = results[0] as List<Comment>;
+ final anonNames = results[1] as Map<String, String>;
setState(() {
_comments.addAll(comments);
+ _anonDisplayNames = anonNames;
_offset = comments.length;
_hasMoreComments = comments.length == _pageSize;
_isLoading = false;
@@ -258,6 +266,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {
_offset = 0;
_hasMoreComments = true;
_userCache.clear();
+ _anonDisplayNames = {};
});
_loadInitialComments();
}
@@ -281,10 +290,13 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {
}
if (comment.isAnonymous) {
+ final anonID = comment.anonUserID;
+ final displayName =
+ anonID != null ? (_anonDisplayNames[anonID] ?? anonID) : "Anonymous";
final user = User(
id: comment.userID,
- email: "${comment.anonUserID ?? "anonymous"}@unknown.com",
- name: comment.anonUserID ?? "Anonymous",
+ email: "${anonID ?? "anonymous"}@unknown.com",
+ name: displayName,
);
_userCache[comment.userID] = user;
return user;
diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dart
index 9aa2013478..d9edd153b5 100644
--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart
@@ -29,6 +29,9 @@ class _FeedScreenState extends State<FeedScreen> {
bool _isLoading = true;
late final int _currentUserID;
+ /// Map of collectionID -> (anonUserID -> displayName)
+ Map<int, Map<String, String>> _anonDisplayNamesByCollection = {};
+
@override
void initState() {
super.initState();
@@ -42,9 +45,13 @@ class _FeedScreenState extends State<FeedScreen> {
// Load local data first
final items = await FeedDataProvider.instance.getFeedItems(limit: 50);
+ // Load anon display names for all collections in feed
+ final anonNames = await _loadAnonDisplayNames(items);
+
if (mounted) {
setState(() {
_feedItems = items;
+ _anonDisplayNamesByCollection = anonNames;
_isLoading = false;
});
}
@@ -53,6 +60,23 @@ class _FeedScreenState extends State<FeedScreen> {
unawaited(_syncAndRefresh());
}
+ Future<Map<int, Map<String, String>>> _loadAnonDisplayNames(
+ List<FeedItem> items,
+ ) async {
+ final collectionIDs = items.map((e) => e.collectionID).toSet();
+ final results = <int, Map<String, String>>{};
+
+ await Future.wait(
+ collectionIDs.map((collectionID) async {
+ final names = await SocialDataProvider.instance
+ .getAnonDisplayNamesForCollection(collectionID);
+ results[collectionID] = names;
+ }),
+ );
+
+ return results;
+ }
+
Future<void> _syncAndRefresh() async {
try {
await FeedDataProvider.instance.syncAllSharedCollections();
@@ -63,9 +87,13 @@ class _FeedScreenState extends State<FeedScreen> {
final freshItems =
await FeedDataProvider.instance.getFeedItems(limit: 50);
+ // Reload anon display names for new items
+ final freshAnonNames = await _loadAnonDisplayNames(freshItems);
+
if (mounted) {
setState(() {
_feedItems = freshItems;
+ _anonDisplayNamesByCollection = freshAnonNames;
});
}
} catch (_) {
@@ -118,6 +146,9 @@ class _FeedScreenState extends State<FeedScreen> {
),
feedItem: item,
currentUserID: _currentUserID,
+ anonDisplayNames:
+ _anonDisplayNamesByCollection[item.collectionID] ??
+ const {},
onTap: () => _onFeedItemTap(item),
);
},
diff --git a/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart b/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart
index 145d4cdd13..f7816c40f2 100644
--- a/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart
+++ b/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart
@@ -57,6 +57,7 @@ class _LikesBottomSheetState extends State<LikesBottomSheet> {
List<CollectionLikeInfo> _sharedCollections = [];
late int _selectedCollectionID;
late final int _currentUserID;
+ Map<String, String> _anonDisplayNames = {};
@override
void initState() {
@@ -138,15 +139,22 @@ class _LikesBottomSheetState extends State<LikesBottomSheet> {
widget.fileID,
);
- final likes =
- await SocialDataProvider.instance.getReactionsForFileInCollection(
- widget.fileID,
- _selectedCollectionID,
- );
+ final results = await Future.wait([
+ SocialDataProvider.instance.getReactionsForFileInCollection(
+ widget.fileID,
+ _selectedCollectionID,
+ ),
+ SocialDataProvider.instance
+ .getAnonDisplayNamesForCollection(_selectedCollectionID),
+ ]);
+
+ final likes = results[0] as List<Reaction>;
+ final anonNames = results[1] as Map<String, String>;
if (mounted) {
setState(() {
_likes = likes;
+ _anonDisplayNames = anonNames;
_isLoading = false;
});
}
@@ -161,14 +169,25 @@ class _LikesBottomSheetState extends State<LikesBottomSheet> {
}
Future<void> _onCollectionSelected(int collectionID) async {
- // Load likes for new collection first to avoid flash/jump
- final likes = await SocialDataProvider.instance
- .getReactionsForFileInCollection(widget.fileID, collectionID);
+ // Load likes and anon names for new collection first to avoid flash/jump
+ final results = await Future.wait([
+ SocialDataProvider.instance.getReactionsForFileInCollection(
+ widget.fileID,
+ collectionID,
+ ),
+ SocialDataProvider.instance.getAnonDisplayNamesForCollection(
+ collectionID,
+ ),
+ ]);
+
+ final likes = results[0] as List<Reaction>;
+ final anonNames = results[1] as Map<String, String>;
if (mounted) {
setState(() {
_selectedCollectionID = collectionID;
_likes = likes;
+ _anonDisplayNames = anonNames;
});
}
}
@@ -220,6 +239,7 @@ class _LikesBottomSheetState extends State<LikesBottomSheet> {
likes: _likes,
currentUserID: _currentUserID,
selectedCollectionID: _selectedCollectionID,
+ anonDisplayNames: _anonDisplayNames,
),
),
],
@@ -317,19 +337,24 @@ class _LikesList extends StatelessWidget {
final List<Reaction> likes;
final int currentUserID;
final int selectedCollectionID;
+ final Map<String, String> anonDisplayNames;
const _LikesList({
required this.likes,
required this.currentUserID,
required this.selectedCollectionID,
+ required this.anonDisplayNames,
});
User _getUserForReaction(Reaction reaction) {
if (reaction.isAnonymous) {
+ final anonID = reaction.anonUserID;
+ final displayName =
+ anonID != null ? (anonDisplayNames[anonID] ?? anonID) : "Anonymous";
return User(
id: reaction.userID,
- email: "${reaction.anonUserID ?? "anonymous"}@unknown.com",
- name: reaction.anonUserID ?? "Anonymous",
+ email: "${anonID ?? "anonymous"}@unknown.com",
+ name: displayName,
);
}
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 b5e7c8536c..c769d806ec 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
@@ -20,10 +20,14 @@ class FeedItemWidget extends StatelessWidget {
final int currentUserID;
final VoidCallback? onTap;
+ /// Map of anonUserID -> decrypted display name for the collection.
+ final Map<String, String> anonDisplayNames;
+
const FeedItemWidget({
required this.feedItem,
required this.currentUserID,
this.onTap,
+ this.anonDisplayNames = const {},
super.key,
});
@@ -46,6 +50,7 @@ class FeedItemWidget extends StatelessWidget {
_StackedAvatars(
feedItem: feedItem,
currentUserID: currentUserID,
+ anonDisplayNames: anonDisplayNames,
),
const SizedBox(width: 10),
// Text content
@@ -53,6 +58,7 @@ class FeedItemWidget extends StatelessWidget {
child: _FeedTextContent(
feedItem: feedItem,
currentUserID: currentUserID,
+ anonDisplayNames: anonDisplayNames,
),
),
const SizedBox(width: 12),
@@ -169,10 +175,12 @@ class _FeedTypeIcon extends StatelessWidget {
class _StackedAvatars extends StatelessWidget {
final FeedItem feedItem;
final int currentUserID;
+ final Map<String, String> anonDisplayNames;
const _StackedAvatars({
required this.feedItem,
required this.currentUserID,
+ required this.anonDisplayNames,
});
@override
@@ -252,12 +260,13 @@ class _StackedAvatars extends StatelessWidget {
final anonID = feedItem.actorAnonIDs[i];
if (userID <= 0 && anonID != null) {
- // Anonymous user
+ // Anonymous user - use decrypted display name if available
+ final displayName = anonDisplayNames[anonID] ?? anonID;
users.add(
User(
id: userID,
- name: anonID,
+ name: displayName,
),
);
} else {
@@ -276,10 +285,12 @@ class _StackedAvatars extends StatelessWidget {
class _FeedTextContent extends StatelessWidget {
final FeedItem feedItem;
final int currentUserID;
+ final Map<String, String> anonDisplayNames;
const _FeedTextContent({
required this.feedItem,
required this.currentUserID,
+ required this.anonDisplayNames,
});
@override
@@ -381,10 +392,12 @@ class _FeedTextContent extends StatelessWidget {
final anonID = feedItem.primaryActorAnonID;
if (userID <= 0 && anonID != null) {
+ // Anonymous user - use decrypted display name if available
+ final displayName = anonDisplayNames[anonID] ?? anonID;
return User(
id: userID,
- name: anonID,
+ name: displayName,
);
}
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.dart
index 8cdee0a7fc..e8f6cd590a 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/feed_preview_widget.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_preview_widget.dart
@@ -1,11 +1,18 @@
+import "dart:async";
+
import "package:flutter/material.dart";
import "package:photos/core/configuration.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/people_changed_event.dart";
+import "package:photos/events/social_data_updated_event.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/social/feed_screen.dart";
import "package:photos/ui/social/widgets/feed_item_widget.dart";
import "package:photos/utils/navigation_util.dart";
+import "package:photos/utils/standalone/debouncer.dart";
/// Widget that displays a preview of the latest feed item.
///
@@ -21,19 +28,60 @@ class _FeedPreviewWidgetState extends State<FeedPreviewWidget> {
FeedItem? _latestItem;
bool _isLoading = true;
late final int _currentUserID;
+ Map<String, String> _anonDisplayNames = {};
+
+ late final StreamSubscription<SocialDataUpdatedEvent> _socialDataSubscription;
+ late final StreamSubscription<PeopleChangedEvent> _peopleChangedSubscription;
+ final _refreshDebouncer = Debouncer(const Duration(milliseconds: 500));
@override
void initState() {
super.initState();
_currentUserID = Configuration.instance.getUserID() ?? 0;
_loadLatestItem();
+
+ // Listen for social data updates (comments/reactions synced)
+ _socialDataSubscription =
+ Bus.instance.on<SocialDataUpdatedEvent>().listen((event) {
+ _refreshDebouncer.run(() => _loadLatestItem());
+ });
+
+ // Listen for people changes (user names updated)
+ _peopleChangedSubscription =
+ Bus.instance.on<PeopleChangedEvent>().listen((event) {
+ // Refresh if a person was saved/edited and matches the current actor
+ if (event.type == PeopleEventType.saveOrEditPerson &&
+ _latestItem != null) {
+ final personUserID = event.person?.data.userID;
+ if (personUserID != null &&
+ _latestItem!.actorUserIDs.contains(personUserID)) {
+ _refreshDebouncer.run(() => _loadLatestItem());
+ }
+ }
+ });
+ }
+
+ @override
+ void dispose() {
+ _socialDataSubscription.cancel();
+ _peopleChangedSubscription.cancel();
+ super.dispose();
}
Future<void> _loadLatestItem() async {
final item = await FeedDataProvider.instance.getLatestFeedItem();
+
+ // Load anon display names if there's an item
+ Map<String, String> anonNames = {};
+ if (item != null) {
+ anonNames = await SocialDataProvider.instance
+ .getAnonDisplayNamesForCollection(item.collectionID);
+ }
+
if (mounted) {
setState(() {
_latestItem = item;
+ _anonDisplayNames = anonNames;
_isLoading = false;
});
}
@@ -75,6 +123,7 @@ class _FeedPreviewWidgetState extends State<FeedPreviewWidget> {
child: FeedItemWidget(
feedItem: _latestItem!,
currentUserID: _currentUserID,
+ anonDisplayNames: _anonDisplayNames,
onTap: _onTap,
),
),