Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] refine contact flows and social actor routing

Neeraj Guptaba0ab08773f8
diff --git a/mobile/apps/photos/lib/services/contacts/contact_identity_resolver.dart b/mobile/apps/photos/lib/services/contacts/contact_identity_resolver.dart
index 62b013094e..01f26d304b 100644
--- a/mobile/apps/photos/lib/services/contacts/contact_identity_resolver.dart
+++ b/mobile/apps/photos/lib/services/contacts/contact_identity_resolver.dart
@@ -18,7 +18,7 @@ String resolveDisplayName(User user) {
}
String? resolveKnownEmail(User user) {
- if (flagService.internalUser && user.id != null && user.id! > 0) {
+ if (flagService.enableContact && user.id != null && user.id! > 0) {
final savedEmail = _knownEmailOrNull(
PhotosContactsService.instance.getCachedResolvedEmailByUserId(user.id),
);
@@ -30,8 +30,19 @@ String? resolveKnownEmail(User user) {
return _knownEmailOrNull(user.email);
}
+bool matchesResolvedContactQuery(User user, String lowerCaseQuery) {
+ if (lowerCaseQuery.isEmpty) {
+ return true;
+ }
+
+ final resolvedName = resolveDisplayName(user).toLowerCase();
+ final resolvedEmail = (resolveKnownEmail(user) ?? user.email).toLowerCase();
+ return resolvedName.contains(lowerCaseQuery) ||
+ resolvedEmail.contains(lowerCaseQuery);
+}
+
String? _savedContactName(User user) {
- if (!flagService.internalUser || user.id == null || user.id! <= 0) {
+ if (!flagService.enableContact || user.id == null || user.id! <= 0) {
return null;
}
diff --git a/mobile/apps/photos/lib/services/photos_contacts_service.dart b/mobile/apps/photos/lib/services/photos_contacts_service.dart
index 45ef53cf95..a0074df522 100644
--- a/mobile/apps/photos/lib/services/photos_contacts_service.dart
+++ b/mobile/apps/photos/lib/services/photos_contacts_service.dart
@@ -1,6 +1,5 @@
-import "dart:typed_data";
-
import "package:ente_contacts/contacts.dart" as contacts;
+import "package:flutter/foundation.dart";
import "package:logging/logging.dart";
import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
@@ -13,6 +12,11 @@ class PhotosContactsService {
preferences: ServiceLocator.instance.prefs,
);
+ @visibleForTesting
+ PhotosContactsService.forTesting({
+ required contacts.ContactsService contactsService,
+ }) : _contacts = contactsService;
+
static final PhotosContactsService instance =
PhotosContactsService._privateConstructor();
@@ -31,22 +35,21 @@ class PhotosContactsService {
bool get hasHydratedCache => _hasHydratedCache;
Future<void> ensureReady() async {
- final config = Configuration.instance;
- final authToken = config.getToken();
- if (!flagService.internalUser) {
+ if (!flagService.enableContact) {
_resetSessionState(notify: true);
return;
}
- final sessionKey = _buildSessionKey();
- if (sessionKey == null) {
+ final session = _buildSession();
+ if (session == null) {
_resetSessionState(notify: true);
return;
}
+ final sessionKey = _buildSessionKey(session);
if (_readyFuture != null && _sessionKey == sessionKey) {
await _readyFuture;
- if (authToken != null && _sessionAuthToken != authToken) {
- await _contacts.updateAuthToken(authToken);
- _sessionAuthToken = authToken;
+ if (_sessionAuthToken != session.authToken) {
+ await _contacts.updateAuthToken(session.authToken);
+ _sessionAuthToken = session.authToken;
}
return;
}
@@ -54,10 +57,10 @@ class PhotosContactsService {
_resetSessionState(notify: true);
}
_sessionKey = sessionKey;
- _sessionAuthToken = authToken;
+ _sessionAuthToken = session.authToken;
late final Future<void> readyFuture;
readyFuture =
- _openAndSync().catchError((Object error, StackTrace stackTrace) {
+ _openAndSync(session).catchError((Object error, StackTrace stackTrace) {
if (identical(_readyFuture, readyFuture)) {
_readyFuture = null;
}
@@ -209,53 +212,88 @@ class PhotosContactsService {
return contact;
}
- String? _buildSessionKey() {
- final config = Configuration.instance;
- final userId = config.getUserID();
- final accountKey = config.getKey();
- if (config.getToken() == null || userId == null || accountKey == null) {
- return null;
+ @visibleForTesting
+ Future<void> debugOpenAndSync(contacts.ContactsSession session) async {
+ _sessionKey = _buildSessionKey(session);
+ _sessionAuthToken = session.authToken;
+ await _openAndSync(session);
+ }
+
+ @visibleForTesting
+ void debugHydrateContacts(
+ List<contacts.ContactRecord> contacts, {
+ bool markHydrated = false,
+ }) {
+ for (final contact in contacts) {
+ _cacheContact(contact);
+ }
+ if (markHydrated) {
+ _hasHydratedCache = true;
}
- return "${config.getHttpEndpoint()}|$userId";
}
- Future<void> _openAndSync() async {
+ @visibleForTesting
+ void debugReset({bool notify = false}) {
+ _resetSessionState(notify: notify);
+ }
+
+ contacts.ContactsSession? _buildSession() {
final config = Configuration.instance;
- final token = config.getToken();
final userId = config.getUserID();
final accountKey = config.getKey();
+ final token = config.getToken();
if (token == null || userId == null || accountKey == null) {
- return;
+ return null;
}
final packageInfo = ServiceLocator.instance.packageInfo;
- await _contacts.open(
- contacts.ContactsSession(
- baseUrl: config.getHttpEndpoint(),
- authToken: token,
- userId: userId,
- accountKey: accountKey,
- clientPackage: packageInfo.packageName,
- clientVersion: packageInfo.version,
- ),
+ return contacts.ContactsSession(
+ baseUrl: config.getHttpEndpoint(),
+ authToken: token,
+ userId: userId,
+ accountKey: accountKey,
+ clientPackage: packageInfo.packageName,
+ clientVersion: packageInfo.version,
);
- final contactsDiff = await _contacts.sync();
- for (final contact in contactsDiff) {
- _invalidateProfilePictureCache(contact.contactUserId);
- _cacheContact(contact);
- }
+ }
+
+ String _buildSessionKey(contacts.ContactsSession session) {
+ return "${session.baseUrl}|${session.userId}";
+ }
+
+ Future<void> _openAndSync(contacts.ContactsSession session) async {
+ await _contacts.open(session);
final cachedUserIdsBeforeHydration = _contactsByUserId.keys.toSet();
- final diffUserIds =
- contactsDiff.map((contact) => contact.contactUserId).toSet();
final localContacts = await _hydrateCacheFromLocalDb();
_hasHydratedCache = true;
final newlyHydratedLocalUserIds = localContacts
.map((contact) => contact.contactUserId)
.where((userId) => !cachedUserIdsBeforeHydration.contains(userId))
.toSet();
- final changedUserIds = {...diffUserIds, ...newlyHydratedLocalUserIds};
+ final changedUserIds = <int>{...newlyHydratedLocalUserIds};
+ var shouldRetrySync = false;
+ try {
+ final contactsDiff = await _contacts.sync();
+ for (final contact in contactsDiff) {
+ _invalidateProfilePictureCache(contact.contactUserId);
+ _cacheContact(contact);
+ }
+ changedUserIds.addAll(
+ contactsDiff.map((contact) => contact.contactUserId),
+ );
+ } catch (e, s) {
+ shouldRetrySync = true;
+ _logger.warning(
+ "Failed to sync contacts after hydrating local cache",
+ e,
+ s,
+ );
+ }
if (changedUserIds.isNotEmpty) {
_notifyContactsChanged(changedUserIds);
}
+ if (shouldRetrySync && _sessionKey == _buildSessionKey(session)) {
+ _readyFuture = null;
+ }
}
void _notifyChanged(contacts.ContactRecord contact) {
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index a4d1e34459..46ecab870e 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -117,7 +117,7 @@ class SearchService {
}
Future<void> _warmContactsCacheIfNeeded() async {
- if (!flagService.internalUser ||
+ if (!flagService.enableContact ||
PhotosContactsService.instance.hasHydratedCache) {
return;
}
@@ -132,6 +132,51 @@ class SearchService {
}
}
+ Future<GenericSearchResult?> buildContactSearchResultForUser(User user) async {
+ final userId = user.id;
+ if (userId == null || userId <= 0) {
+ return null;
+ }
+
+ await _warmContactsCacheIfNeeded();
+
+ final allFiles = await getAllFilesForSearch();
+ final files = allFiles.where((file) => file.ownerID == userId).toList();
+ final collections = _collectionService
+ .getCollectionsForUI(includedShared: true, includeCollab: true)
+ .where((collection) => _isVisibleSharedCollectionForContact(collection))
+ .where((collection) => _isSameContactUser(collection.owner, user))
+ .toList();
+
+ return GenericSearchResult(
+ ResultType.shared,
+ resolveDisplayName(user),
+ files,
+ hierarchicalSearchFilter: ContactsFilter(
+ user: user,
+ occurrence: kMostRelevantFilter,
+ matchedUploadedIDs: filesToUploadedFileIDs(files),
+ ),
+ params: _contactSearchParams(user, collections),
+ );
+ }
+
+ bool _isVisibleSharedCollectionForContact(Collection collection) {
+ final ownerID = Configuration.instance.getUserID();
+ return !collection.isHidden() &&
+ ownerID != null &&
+ !collection.isOwner(ownerID);
+ }
+
+ bool _isSameContactUser(User source, User target) {
+ final sourceId = source.id;
+ final targetId = target.id;
+ if (sourceId != null && targetId != null && sourceId > 0 && targetId > 0) {
+ return sourceId == targetId;
+ }
+ return source.email == target.email;
+ }
+
Future<List<EnteFile>> getAllFilesForSearch() async {
if (_cachedFilesFuture != null && _cachedFilesForSearch != null) {
return _cachedFilesForSearch!;
@@ -1684,9 +1729,7 @@ class SearchService {
final fileOwner = CollectionsService.instance
.getFileOwner(file.ownerID!, file.collectionID);
- if (fileOwner.email.toLowerCase().contains(lowerCaseQuery) ||
- ((fileOwner.displayName?.toLowerCase().contains(lowerCaseQuery)) ??
- false)) {
+ if (matchesResolvedContactQuery(fileOwner, lowerCaseQuery)) {
if (peopleToSharedFiles.containsKey(fileOwner)) {
peopleToSharedFiles[fileOwner]!.add(file);
} else {
@@ -1702,9 +1745,7 @@ class SearchService {
if (existingEmails.contains(user.email)) {
continue;
}
- if (user.email.toLowerCase().contains(lowerCaseQuery) ||
- ((user.displayName?.toLowerCase().contains(lowerCaseQuery)) ??
- false)) {
+ if (matchesResolvedContactQuery(user, lowerCaseQuery)) {
peopleToSharedFiles[user] = [];
}
}
diff --git a/mobile/apps/photos/lib/ui/social/comment_likes_bottom_sheet.dart b/mobile/apps/photos/lib/ui/social/comment_likes_bottom_sheet.dart
index de27d79a73..5e28905a4a 100644
--- a/mobile/apps/photos/lib/ui/social/comment_likes_bottom_sheet.dart
+++ b/mobile/apps/photos/lib/ui/social/comment_likes_bottom_sheet.dart
@@ -9,6 +9,7 @@ import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
+import "package:photos/ui/social/social_actor_contact_navigation.dart";
import "package:photos/ui/social/widgets/resolved_social_user_name.dart";
const _shrinkWrapThreshold = 30;
@@ -25,6 +26,7 @@ Future<void> showCommentLikesBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) => CommentLikesBottomSheet(
+ launchContext: context,
reactions: reactions,
collectionID: collectionID,
currentUserID: currentUserID,
@@ -33,11 +35,13 @@ Future<void> showCommentLikesBottomSheet(
}
class CommentLikesBottomSheet extends StatefulWidget {
+ final BuildContext launchContext;
final List<Reaction> reactions;
final int collectionID;
final int currentUserID;
const CommentLikesBottomSheet({
+ required this.launchContext,
required this.reactions,
required this.collectionID,
required this.currentUserID,
@@ -164,6 +168,13 @@ class _CommentLikesBottomSheetState extends State<CommentLikesBottomSheet> {
user: user,
currentUserID: widget.currentUserID,
youLabel: l10n.you,
+ onTap: () => openSocialActorContactDestination(
+ context,
+ user,
+ currentUserID: widget.currentUserID,
+ navigationContext: widget.launchContext,
+ dismissCurrentRoute: true,
+ ),
);
},
),
@@ -179,18 +190,20 @@ class _CommentLikeListItem extends StatelessWidget {
final User user;
final int currentUserID;
final String youLabel;
+ final VoidCallback? onTap;
const _CommentLikeListItem({
required this.user,
required this.currentUserID,
required this.youLabel,
+ this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
- return Padding(
+ final row = Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
@@ -237,5 +250,15 @@ class _CommentLikeListItem extends StatelessWidget {
],
),
);
+
+ if (onTap == null || user.id == currentUserID) {
+ return row;
+ }
+
+ return GestureDetector(
+ onTap: onTap,
+ behavior: HitTestBehavior.opaque,
+ child: row,
+ );
}
}
diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dart
index 84306a8b09..0ad62646e8 100644
--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart
@@ -17,6 +17,7 @@ import 'package:photos/services/social_notification_coordinator.dart';
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
+import "package:photos/ui/social/social_actor_contact_navigation.dart";
import "package:photos/ui/social/widgets/collection_selector_widget.dart";
import "package:photos/ui/social/widgets/comment_bubble_widget.dart";
import "package:photos/ui/social/widgets/comment_input_widget.dart";
@@ -33,6 +34,7 @@ Future<void> showFileCommentsBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) => _DraggableCommentsSheet(
+ launchContext: context,
collectionID: collectionID,
fileID: fileID,
highlightCommentID: highlightCommentID,
@@ -41,11 +43,13 @@ Future<void> showFileCommentsBottomSheet(
}
class _DraggableCommentsSheet extends StatefulWidget {
+ final BuildContext launchContext;
final int collectionID;
final int fileID;
final String? highlightCommentID;
const _DraggableCommentsSheet({
+ required this.launchContext,
required this.collectionID,
required this.fileID,
this.highlightCommentID,
@@ -77,6 +81,7 @@ class _DraggableCommentsSheetState extends State<_DraggableCommentsSheet> {
snapSizes: isKeyboardOpen ? null : const [0.6],
expand: false,
builder: (context, scrollController) => FileCommentsBottomSheet(
+ launchContext: widget.launchContext,
collectionID: widget.collectionID,
fileID: widget.fileID,
highlightCommentID: widget.highlightCommentID,
@@ -88,6 +93,7 @@ class _DraggableCommentsSheetState extends State<_DraggableCommentsSheet> {
}
class FileCommentsBottomSheet extends StatefulWidget {
+ final BuildContext launchContext;
final int collectionID;
final int fileID;
@@ -101,6 +107,7 @@ class FileCommentsBottomSheet extends StatefulWidget {
final DraggableScrollableController sheetController;
const FileCommentsBottomSheet({
+ required this.launchContext,
required this.collectionID,
required this.fileID,
required this.dragController,
@@ -740,6 +747,14 @@ class _FileCommentsBottomSheetState extends State<FileCommentsBottomSheet> {
comment.parentCommentID!,
)
: null,
+ onAuthorTap: () =>
+ openSocialActorContactDestination(
+ context,
+ _getUserForComment(comment),
+ currentUserID: _currentUserID,
+ navigationContext: widget.launchContext,
+ dismissCurrentRoute: true,
+ ),
);
},
),
diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dart
index 235c7536bd..94ab367b44 100644
--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart
@@ -17,6 +17,7 @@ import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
import "package:photos/ui/social/comments_screen.dart";
+import "package:photos/ui/social/social_actor_contact_navigation.dart";
import "package:photos/ui/social/widgets/feed_item_widget.dart";
import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
@@ -601,6 +602,12 @@ class _FeedScreenState extends State<FeedScreen> {
sharedFileIDs: item.sharedFileIDs,
),
),
+ onPrimaryActorTap: (user) =>
+ openSocialActorContactDestination(
+ context,
+ user,
+ currentUserID: _currentUserID,
+ ),
);
},
),
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 4c1b90f4e9..8ee62ec66a 100644
--- a/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart
+++ b/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart
@@ -15,6 +15,7 @@ import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
+import "package:photos/ui/social/social_actor_contact_navigation.dart";
import "package:photos/ui/social/widgets/collection_selector_widget.dart";
import "package:photos/ui/social/widgets/resolved_social_user_name.dart";
@@ -31,6 +32,7 @@ Future<void> showLikesBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) => LikesBottomSheet(
+ launchContext: context,
fileID: fileID,
initialCollectionID: initialCollectionID,
),
@@ -38,10 +40,12 @@ Future<void> showLikesBottomSheet(
}
class LikesBottomSheet extends StatefulWidget {
+ final BuildContext launchContext;
final int fileID;
final int initialCollectionID;
const LikesBottomSheet({
+ required this.launchContext,
required this.fileID,
required this.initialCollectionID,
super.key,
@@ -259,6 +263,13 @@ class _LikesBottomSheetState extends State<LikesBottomSheet> {
currentUserID: _currentUserID,
selectedCollectionID: _selectedCollectionID,
anonDisplayNames: _anonDisplayNames,
+ onUserTap: (user) => openSocialActorContactDestination(
+ context,
+ user,
+ currentUserID: _currentUserID,
+ navigationContext: widget.launchContext,
+ dismissCurrentRoute: true,
+ ),
),
),
],
@@ -360,12 +371,14 @@ class _LikesList extends StatelessWidget {
final int currentUserID;
final int selectedCollectionID;
final Map<String, String> anonDisplayNames;
+ final ValueChanged<User> onUserTap;
const _LikesList({
required this.likes,
required this.currentUserID,
required this.selectedCollectionID,
required this.anonDisplayNames,
+ required this.onUserTap,
});
User _getUserForReaction(Reaction reaction) {
@@ -399,6 +412,7 @@ class _LikesList extends StatelessWidget {
user: user,
currentUserID: currentUserID,
youLabel: l10n.you,
+ onTap: () => onUserTap(user),
);
},
);
@@ -409,18 +423,20 @@ class _LikeListItem extends StatelessWidget {
final User user;
final int currentUserID;
final String youLabel;
+ final VoidCallback? onTap;
const _LikeListItem({
required this.user,
required this.currentUserID,
required this.youLabel,
+ this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
- return Padding(
+ final row = Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
@@ -467,5 +483,15 @@ class _LikeListItem extends StatelessWidget {
],
),
);
+
+ if (onTap == null || user.id == currentUserID) {
+ return row;
+ }
+
+ return GestureDetector(
+ onTap: onTap,
+ behavior: HitTestBehavior.opaque,
+ child: row,
+ );
}
}
diff --git a/mobile/apps/photos/lib/ui/social/social_actor_contact_navigation.dart b/mobile/apps/photos/lib/ui/social/social_actor_contact_navigation.dart
new file mode 100644
index 0000000000..62b1cd8a62
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/social/social_actor_contact_navigation.dart
@@ -0,0 +1,106 @@
+import "package:ente_pure_utils/ente_pure_utils.dart";
+import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/models/api/collection/user.dart";
+import "package:photos/models/search/generic_search_result.dart";
+import "package:photos/service_locator.dart" show flagService;
+import "package:photos/services/contacts/contact_identity_resolver.dart";
+import "package:photos/services/photos_contacts_service.dart";
+import "package:photos/services/search_service.dart";
+import "package:photos/ui/viewer/search/result/contact_result_page.dart";
+import "package:photos/ui/viewer/search/result/edit_contact_page.dart";
+
+final _logger = Logger("SocialActorContactNavigation");
+
+bool canOpenSocialActorContactDestination(
+ User user, {
+ required int currentUserID,
+}) {
+ if (!flagService.enableContact) {
+ return false;
+ }
+ final userId = user.id;
+ if (userId == null || userId <= 0 || userId == currentUserID) {
+ return false;
+ }
+ return resolveKnownEmail(user) != null;
+}
+
+Future<void> openSocialActorContactDestination(
+ BuildContext context,
+ User user, {
+ required int currentUserID,
+ BuildContext? navigationContext,
+ bool dismissCurrentRoute = false,
+}) async {
+ if (!canOpenSocialActorContactDestination(
+ user,
+ currentUserID: currentUserID,
+ )) {
+ return;
+ }
+
+ final userId = user.id!;
+ final email = resolveKnownEmail(user);
+ if (email == null) {
+ return;
+ }
+
+ final destination = await _buildDestination(user, userId: userId, email: email);
+ if (destination == null) {
+ return;
+ }
+
+ final targetContext = navigationContext ?? context;
+ if (dismissCurrentRoute && context.mounted) {
+ Navigator.of(context).pop();
+ }
+ if (!targetContext.mounted) {
+ return;
+ }
+ await routeToPage(targetContext, destination);
+}
+
+Future<Widget?> _buildDestination(
+ User user, {
+ required int userId,
+ required String email,
+}) async {
+ final contactsService = PhotosContactsService.instance;
+ final cachedContact = contactsService.getCachedContactByUserId(userId);
+ if (cachedContact != null) {
+ return _contactResultPageForUser(user);
+ }
+
+ if (!contactsService.hasHydratedCache) {
+ try {
+ await contactsService.ensureReady();
+ } catch (e, s) {
+ _logger.warning(
+ "Failed to initialize contacts before opening social actor destination",
+ e,
+ s,
+ );
+ }
+ }
+
+ final savedContact = contactsService.getCachedContactByUserId(userId);
+ if (savedContact != null) {
+ return _contactResultPageForUser(user);
+ }
+
+ return EditContactPage(
+ contactUserId: userId,
+ email: email,
+ existingContact: null,
+ );
+}
+
+Future<Widget?> _contactResultPageForUser(User user) async {
+ final GenericSearchResult? searchResult =
+ await SearchService.instance.buildContactSearchResultForUser(user);
+ if (searchResult == null) {
+ return null;
+ }
+ return ContactResultPage(searchResult);
+}
diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
index b9ff45659e..54d0ed937a 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
@@ -47,6 +47,9 @@ class CommentBubbleWidget extends StatefulWidget {
/// Callback invoked when the user taps on the parent quote preview.
final VoidCallback? onParentQuoteTap;
+ /// Callback invoked when the user taps the visible author header.
+ final VoidCallback? onAuthorTap;
+
const CommentBubbleWidget({
required this.comment,
required this.user,
@@ -62,6 +65,7 @@ class CommentBubbleWidget extends StatefulWidget {
this.isHighlighted = false,
this.onAutoHighlightDismissed,
this.onParentQuoteTap,
+ this.onAuthorTap,
super.key,
});
@@ -513,6 +517,7 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>
user: widget.user,
createdAt: widget.comment.createdAt,
currentUserID: widget.currentUserID,
+ onAuthorTap: widget.onAuthorTap,
),
),
),
@@ -807,12 +812,14 @@ class _Header extends StatelessWidget {
final User user;
final int createdAt;
final int currentUserID;
+ final VoidCallback? onAuthorTap;
const _Header({
required this.isOwnComment,
required this.user,
required this.createdAt,
required this.currentUserID,
+ this.onAuthorTap,
});
@override
@@ -881,7 +888,7 @@ class _Header extends StatelessWidget {
),
);
- return Row(
+ final row = Row(
mainAxisAlignment:
isOwnComment ? MainAxisAlignment.end : MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
@@ -909,5 +916,15 @@ class _Header extends StatelessWidget {
],
],
);
+
+ if (isOwnComment || onAuthorTap == null) {
+ return row;
+ }
+
+ return GestureDetector(
+ onTap: onAuthorTap,
+ behavior: HitTestBehavior.opaque,
+ child: row,
+ );
}
}
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 1642a69515..52700e3b80 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
@@ -30,6 +30,9 @@ class FeedItemWidget extends StatelessWidget {
/// Called when the user taps shared-feed header text/avatar area.
final VoidCallback? onSharedHeaderTap;
+ /// Called when the user taps the primary actor avatar or name.
+ final ValueChanged<User>? onPrimaryActorTap;
+
/// Called when the user taps the +N extra-count badge in the shared grid.
final VoidCallback? onSharedExtraCountTap;
@@ -47,6 +50,7 @@ class FeedItemWidget extends StatelessWidget {
this.onTap,
this.onSharedPhotoTap,
this.onSharedHeaderTap,
+ this.onPrimaryActorTap,
this.onSharedExtraCountTap,
this.anonDisplayNames = const {},
this.isLastItem = false,
@@ -96,6 +100,7 @@ class FeedItemWidget extends StatelessWidget {
feedItem: feedItem,
currentUserID: currentUserID,
anonDisplayNames: anonDisplayNames,
+ onPrimaryActorTap: onPrimaryActorTap,
),
],
),
@@ -107,6 +112,7 @@ class FeedItemWidget extends StatelessWidget {
feedItem: feedItem,
currentUserID: currentUserID,
anonDisplayNames: anonDisplayNames,
+ onPrimaryActorTap: onPrimaryActorTap,
),
),
],
@@ -172,6 +178,7 @@ class FeedItemWidget extends StatelessWidget {
feedItem: feedItem,
currentUserID: currentUserID,
anonDisplayNames: anonDisplayNames,
+ onPrimaryActorTap: onPrimaryActorTap,
),
const SizedBox(height: 4),
// Text content
@@ -184,6 +191,7 @@ class FeedItemWidget extends StatelessWidget {
feedItem: feedItem,
currentUserID: currentUserID,
anonDisplayNames: anonDisplayNames,
+ onPrimaryActorTap: onPrimaryActorTap,
),
),
),
@@ -355,11 +363,13 @@ class _StackedAvatars extends StatelessWidget {
final FeedItem feedItem;
final int currentUserID;
final Map<String, String> anonDisplayNames;
+ final ValueChanged<User>? onPrimaryActorTap;
const _StackedAvatars({
required this.feedItem,
required this.currentUserID,
required this.anonDisplayNames,
+ this.onPrimaryActorTap,
});
@override
@@ -369,11 +379,15 @@ class _StackedAvatars extends StatelessWidget {
final displayCount = actors.length.clamp(1, 2);
if (displayCount == 1) {
- return _buildSingleAvatar(actors.first, colorScheme);
+ return _wrapActorTap(
+ _buildSingleAvatar(actors.first, colorScheme),
+ actors.first,
+ );
}
// Stacked avatars with overlap
- return SizedBox(
+ return _wrapActorTap(
+ SizedBox(
width: 28 + 21, // First avatar + second avatar offset
height: 28,
child: Stack(
@@ -419,6 +433,8 @@ class _StackedAvatars extends StatelessWidget {
),
],
),
+ ),
+ actors.first,
);
}
@@ -440,6 +456,18 @@ class _StackedAvatars extends StatelessWidget {
);
}
+ Widget _wrapActorTap(Widget child, User primaryActor) {
+ final onTap = onPrimaryActorTap;
+ if (onTap == null) {
+ return child;
+ }
+ return GestureDetector(
+ onTap: () => onTap(primaryActor),
+ behavior: HitTestBehavior.opaque,
+ child: child,
+ );
+ }
+
List<User> _getActors() {
final users = <User>[];
final maxActors = feedItem.actorCount.clamp(1, 2);
@@ -475,11 +503,13 @@ class _FeedTextContent extends StatelessWidget {
final FeedItem feedItem;
final int currentUserID;
final Map<String, String> anonDisplayNames;
+ final ValueChanged<User>? onPrimaryActorTap;
const _FeedTextContent({
required this.feedItem,
required this.currentUserID,
required this.anonDisplayNames,
+ this.onPrimaryActorTap,
});
@override
@@ -495,12 +525,22 @@ class _FeedTextContent extends StatelessWidget {
children: [
ResolvedSocialUserName(
user: primaryUser,
- builder: (context, primaryName) => _buildUsernameRow(
- context,
- primaryName,
- textTheme,
- colorScheme,
- ),
+ builder: (context, primaryName) {
+ final row = _buildUsernameRow(
+ context,
+ primaryName,
+ textTheme,
+ colorScheme,
+ );
+ if (onPrimaryActorTap == null) {
+ return row;
+ }
+ return GestureDetector(
+ onTap: () => onPrimaryActorTap!(primaryUser),
+ behavior: HitTestBehavior.opaque,
+ child: row,
+ );
+ },
),
const SizedBox(height: 2),
// Action description
diff --git a/mobile/apps/photos/lib/ui/social/widgets/resolved_social_user_name.dart b/mobile/apps/photos/lib/ui/social/widgets/resolved_social_user_name.dart
index 2562bd7fe4..9d92b5aab7 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/resolved_social_user_name.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/resolved_social_user_name.dart
@@ -38,7 +38,7 @@ class _ResolvedSocialUserNameState extends State<ResolvedSocialUserName> {
Bus.instance.on<ContactsChangedEvent>().listen((event) {
if (mounted &&
event.matchesContactUserId(widget.user.id) &&
- flagService.internalUser) {
+ flagService.enableContact) {
setState(() {});
}
});
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart
index 969f406037..2e26bd2939 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart
@@ -1,8 +1,10 @@
import "package:flutter/material.dart";
import "package:modal_bottom_sheet/modal_bottom_sheet.dart";
+import "package:photos/generated/l10n.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file_load_result.dart";
import "package:photos/models/selected_files.dart";
+import "package:photos/services/search_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/bottom_of_title_bar_widget.dart";
@@ -14,11 +16,11 @@ import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.da
Future<EnteFile?> showContactPhotoPickerSheet(
BuildContext context, {
- required List<EnteFile> files,
+ List<EnteFile>? initialFiles,
}) {
return showBarModalBottomSheet<EnteFile>(
context: context,
- builder: (context) => _ContactPhotoPickerSheet(files: files),
+ builder: (context) => _ContactPhotoPickerSheet(initialFiles: initialFiles),
shape: const RoundedRectangleBorder(
side: BorderSide(width: 0),
borderRadius: BorderRadius.vertical(top: Radius.circular(5)),
@@ -31,9 +33,9 @@ Future<EnteFile?> showContactPhotoPickerSheet(
}
class _ContactPhotoPickerSheet extends StatelessWidget {
- final List<EnteFile> files;
+ final List<EnteFile>? initialFiles;
- const _ContactPhotoPickerSheet({required this.files});
+ const _ContactPhotoPickerSheet({this.initialFiles});
@override
Widget build(BuildContext context) {
@@ -65,8 +67,13 @@ class _ContactPhotoPickerSheet extends StatelessWidget {
creationEndTime, {
limit,
asc,
- }) async =>
- FileLoadResult(files, false),
+ }) async {
+ final files =
+ initialFiles ??
+ await SearchService.instance
+ .getAllFilesForGenericGallery();
+ return FileLoadResult(files, false);
+ },
tagPrefix: "pick_contact_photo_gallery",
selectedFiles: selectedFiles,
limitSelectionToOne: true,
@@ -100,7 +107,8 @@ class _ContactPhotoPickerSheet extends StatelessWidget {
key: ValueKey(value),
isDisabled: !value,
buttonType: ButtonType.neutral,
- labelText: "Set selected photo",
+ labelText:
+ AppLocalizations.of(context).useSelectedPhoto,
onTap: () async {
Navigator.pop(context, selectedFiles.files.first);
},
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart
index 144aa4d602..f883d40882 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart
@@ -346,8 +346,8 @@ class _ContactResultPageState extends State<ContactResultPage> {
EditContactPage(
contactUserId: contactUserId,
email: _contactEmail,
- files: files,
existingContact: _savedContact,
+ photoPickerFiles: files,
),
);
if (updated is contacts.ContactRecord && mounted) {
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
index a86cf30b8f..8dd4f23989 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
@@ -3,12 +3,14 @@ import "dart:typed_data";
import "package:ente_contacts/contacts.dart" as contacts;
import "package:ente_pure_utils/ente_pure_utils.dart";
+import "package:figma_squircle/figma_squircle.dart";
import "package:flutter/material.dart";
import "package:intl/intl.dart";
import "package:logging/logging.dart";
import "package:photos/core/constants.dart";
import "package:photos/db/files_db.dart";
import "package:photos/db/ml/db.dart";
+import "package:photos/generated/l10n.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/models/search/generic_search_result.dart";
@@ -20,7 +22,10 @@ import "package:photos/services/photos_contacts_service.dart";
import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
+import "package:photos/ui/components/action_sheet_widget.dart";
+import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";
+import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
@@ -35,14 +40,14 @@ import "package:photos/utils/thumbnail_util.dart";
class EditContactPage extends StatefulWidget {
final int contactUserId;
final String email;
- final List<EnteFile> files;
final contacts.ContactRecord? existingContact;
+ final List<EnteFile>? photoPickerFiles;
const EditContactPage({
required this.contactUserId,
required this.email,
- required this.files,
required this.existingContact,
+ this.photoPickerFiles,
super.key,
});
@@ -55,6 +60,7 @@ class _EditContactPageState extends State<EditContactPage> {
static const _avatarSize = 108.0;
static const _editBadgeSize = 32.0;
static const _avatarRadius = 20.0;
+ static const _avatarCornerSmoothing = 0.6;
final _logger = Logger("EditContactPage");
late final TextEditingController _nameController;
@@ -90,135 +96,170 @@ class _EditContactPageState extends State<EditContactPage> {
}
bool get _canSave => !_isSaving && _nameController.text.trim().isNotEmpty;
+ String get _initialName => (widget.existingContact?.data?.name ?? "").trim();
+ String? get _initialBirthDate => widget.existingContact?.data?.birthDate;
+ bool get _hasUnsavedChanges =>
+ _nameController.text.trim() != _initialName ||
+ _selectedBirthDate != _initialBirthDate ||
+ _photoDirty;
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- return Scaffold(
- backgroundColor: colorScheme.backgroundColour,
- appBar: AppBar(
- elevation: 0,
- scrolledUnderElevation: 0,
+ return PopScope(
+ canPop: !_isSaving && !_hasUnsavedChanges,
+ onPopInvokedWithResult: (didPop, result) async {
+ if (didPop || _isSaving || !_hasUnsavedChanges) {
+ return;
+ }
+
+ final action = await _showExitConfirmationDialog(context);
+ if (!mounted || action == null || action == ButtonAction.cancel) {
+ return;
+ }
+
+ if (_canSave && action == ButtonAction.first) {
+ await _saveContact();
+ return;
+ }
+
+ final shouldPop = _canSave
+ ? action == ButtonAction.second
+ : action == ButtonAction.first;
+ if (shouldPop && context.mounted) {
+ Navigator.of(context).pop();
+ }
+ },
+ child: Scaffold(
backgroundColor: colorScheme.backgroundColour,
- surfaceTintColor: Colors.transparent,
- title: Text(
- "Edit contact",
- style: textTheme.h3Bold.copyWith(
- fontSize: 20,
- height: 28 / 20,
+ appBar: AppBar(
+ elevation: 0,
+ scrolledUnderElevation: 0,
+ backgroundColor: colorScheme.backgroundColour,
+ surfaceTintColor: Colors.transparent,
+ title: Text(
+ "Edit contact",
+ style: textTheme.h3Bold.copyWith(
+ fontSize: 20,
+ height: 28 / 20,
+ ),
),
+ centerTitle: false,
),
- centerTitle: false,
- ),
- body: Column(
- children: [
- Expanded(
- child: ListView(
- padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
- children: [
- Center(
- child: GestureDetector(
- onTap: _pickContactPhoto,
- child: Stack(
- clipBehavior: Clip.none,
- children: [
- _buildAvatar(context, size: _avatarSize),
- Positioned(
- right: 0,
- bottom: 0,
- child: _AvatarEditButton(
- size: _editBadgeSize,
- onTap: _pickContactPhoto,
- ),
+ body: Column(
+ children: [
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
+ children: [
+ Center(
+ child: SizedBox(
+ width: _avatarSize,
+ height: _avatarSize,
+ child: GestureDetector(
+ onTap: _pickContactPhoto,
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ _buildAvatar(context, size: _avatarSize),
+ Positioned(
+ right: -4,
+ bottom: -4,
+ child: _AvatarEditButton(
+ size: _editBadgeSize,
+ onTap: _pickContactPhoto,
+ ),
+ ),
+ ],
),
- ],
+ ),
),
),
- ),
- const SizedBox(height: 32),
- if (_showAutofillRow) ...[
- MenuItemWidgetNew(
- title: "Auto-fetch from people",
- subText: "Use their name and photo",
- titleToSubTextSpacing: 4,
- subTextStyle: textTheme.mini.copyWith(
- color: colorScheme.textMuted,
- height: 16 / 12,
+ const SizedBox(height: 32),
+ if (_showAutofillRow) ...[
+ MenuItemWidgetNew(
+ title: "Auto-fetch from people",
+ subText: "Use their name and photo",
+ titleToSubTextSpacing: 4,
+ subTextStyle: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ height: 16 / 12,
+ ),
+ leadingIconSize: 44,
+ leadingIconWidget: _AutofillLeadingWidget(
+ person: _autofillPerson,
+ previewPeople: _autofillPreviewPeople,
+ ),
+ trailingIcon: Icons.chevron_right_rounded,
+ onTap: _autoFillFromPeople,
),
- leadingIconSize: 44,
- leadingIconWidget: _AutofillLeadingWidget(
- person: _autofillPerson,
- previewPeople: _autofillPreviewPeople,
+ const SizedBox(height: 28),
+ ],
+ const _FieldLabel(text: "Email", isRequired: true),
+ const SizedBox(height: 8),
+ _InputShell(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 16,
+ ),
+ child: Text(
+ widget.email,
+ style: textTheme.body,
+ ),
),
- trailingIcon: Icons.chevron_right_rounded,
- onTap: _autoFillFromPeople,
),
- const SizedBox(height: 28),
- ],
- const _FieldLabel(text: "Email", isRequired: true),
- const SizedBox(height: 8),
- _InputShell(
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 16,
- ),
- child: Text(
- widget.email,
+ const SizedBox(height: 24),
+ const _FieldLabel(text: "Name"),
+ const SizedBox(height: 8),
+ _InputShell(
+ child: TextField(
+ controller: _nameController,
+ textCapitalization: TextCapitalization.words,
style: textTheme.body,
- ),
- ),
- ),
- const SizedBox(height: 24),
- const _FieldLabel(text: "Name"),
- const SizedBox(height: 8),
- _InputShell(
- child: TextField(
- controller: _nameController,
- textCapitalization: TextCapitalization.words,
- style: textTheme.body,
- decoration: InputDecoration(
- hintText: "Enter a name",
- hintStyle: textTheme.bodyFaint,
- border: InputBorder.none,
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 16,
+ decoration: InputDecoration(
+ hintText: "Enter a name",
+ hintStyle: textTheme.bodyFaint,
+ border: InputBorder.none,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 16,
+ ),
),
),
),
- ),
- const SizedBox(height: 24),
- const _FieldLabel(text: "Birthday"),
- const SizedBox(height: 8),
- _BirthDateField(
- value: _selectedBirthDate,
- onTap: _pickBirthDate,
- onClear: _selectedBirthDate == null
- ? null
- : () {
- setState(() {
- _selectedBirthDate = null;
- });
- },
- hintText: "Enter date of birth",
- ),
- ],
+ const SizedBox(height: 24),
+ const _FieldLabel(text: "Birthday"),
+ const SizedBox(height: 8),
+ _BirthDateField(
+ value: _selectedBirthDate,
+ onTap: _pickBirthDate,
+ onClear: _selectedBirthDate == null
+ ? null
+ : () {
+ setState(() {
+ _selectedBirthDate = null;
+ });
+ },
+ hintText: "Enter date of birth",
+ ),
+ ],
+ ),
),
- ),
- SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
- child: _SaveContactButton(
- isDisabled: !_canSave,
- onTap: _canSave ? _saveContact : null,
+ SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
+ child: _SaveContactButton(
+ isDisabled: !_canSave,
+ onTap: _canSave ? _saveContact : null,
+ ),
),
),
- ),
- ],
+ ],
+ ),
),
);
}
@@ -235,36 +276,26 @@ class _EditContactPageState extends State<EditContactPage> {
avatarSeed.length.remainder(colorScheme.avatarColors.length)];
if (_isLoadingPhoto) {
- return Container(
- width: size,
- height: size,
- decoration: BoxDecoration(
- color: colorScheme.fillFaint,
- borderRadius: BorderRadius.circular(_avatarRadius),
- ),
+ return _ContactThumbnailShell(
+ size: size,
+ backgroundColor: colorScheme.fillFaint,
child: const Center(child: EnteLoadingWidget()),
);
}
if (_draftPhotoBytes != null) {
- return ClipRRect(
- borderRadius: BorderRadius.circular(_avatarRadius),
+ return _ContactThumbnailShell(
+ size: size,
child: Image.memory(
_draftPhotoBytes!,
- width: size,
- height: size,
fit: BoxFit.cover,
),
);
}
- return Container(
- width: size,
- height: size,
- decoration: BoxDecoration(
- color: avatarColor,
- borderRadius: BorderRadius.circular(_avatarRadius),
- ),
+ return _ContactThumbnailShell(
+ size: size,
+ backgroundColor: avatarColor,
child: Center(
child: Text(
initial,
@@ -308,16 +339,9 @@ class _EditContactPageState extends State<EditContactPage> {
}
Future<void> _pickContactPhoto() async {
- final pickerFiles = widget.files.isNotEmpty
- ? widget.files
- : await SearchService.instance.getAllFilesForGenericGallery();
- if (pickerFiles.isEmpty) {
- showShortToast(context, "No photos available to use");
- return;
- }
final selectedFile = await showContactPhotoPickerSheet(
context,
- files: pickerFiles,
+ initialFiles: widget.photoPickerFiles,
);
if (selectedFile == null) {
return;
@@ -427,6 +451,65 @@ class _EditContactPageState extends State<EditContactPage> {
}
}
+ Future<ButtonAction?> _showExitConfirmationDialog(
+ BuildContext context,
+ ) async {
+ final l10n = AppLocalizations.of(context);
+ if (_canSave) {
+ final actionResult = await showActionSheet(
+ context: context,
+ body: l10n.saveChangesBeforeLeavingQuestion,
+ buttons: [
+ ButtonWidget(
+ buttonType: ButtonType.neutral,
+ labelText: l10n.save,
+ isInAlert: true,
+ buttonAction: ButtonAction.first,
+ shouldStickToDarkTheme: true,
+ ),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ labelText: l10n.dontSave,
+ isInAlert: true,
+ buttonAction: ButtonAction.second,
+ shouldStickToDarkTheme: true,
+ ),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ labelText: l10n.cancel,
+ isInAlert: true,
+ buttonAction: ButtonAction.cancel,
+ shouldStickToDarkTheme: true,
+ ),
+ ],
+ );
+ return actionResult?.action;
+ }
+
+ final actionResult = await showActionSheet(
+ context: context,
+ body: l10n.doYouWantToDiscardTheEditsYouHaveMade,
+ buttons: [
+ ButtonWidget(
+ labelText: l10n.yesDiscardChanges,
+ buttonType: ButtonType.critical,
+ shouldStickToDarkTheme: true,
+ buttonAction: ButtonAction.first,
+ isInAlert: true,
+ ),
+ ButtonWidget(
+ labelText: l10n.cancel,
+ buttonType: ButtonType.secondary,
+ shouldStickToDarkTheme: true,
+ buttonAction: ButtonAction.cancel,
+ isInAlert: true,
+ ),
+ ],
+ actionSheetType: ActionSheetType.defaultActionSheet,
+ );
+ return actionResult?.action;
+ }
+
Future<Uint8List?> _loadEditablePhotoBytesFromFile(EnteFile file) async {
return getThumbnail(file);
}
@@ -712,19 +795,20 @@ class _AvatarEditButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return Material(
- color: getEnteColorScheme(context).primary500,
- shape: const CircleBorder(),
- child: InkWell(
- onTap: onTap,
- customBorder: const CircleBorder(),
- child: SizedBox(
- width: size,
- height: size,
- child: const Icon(
+ return GestureDetector(
+ onTap: onTap,
+ child: Container(
+ width: size,
+ height: size,
+ decoration: BoxDecoration(
+ color: getEnteColorScheme(context).greenBase,
+ shape: BoxShape.circle,
+ ),
+ child: const Center(
+ child: Icon(
Icons.edit_outlined,
color: Colors.white,
- size: 16,
+ size: 12,
),
),
),
@@ -732,6 +816,36 @@ class _AvatarEditButton extends StatelessWidget {
}
}
+class _ContactThumbnailShell extends StatelessWidget {
+ const _ContactThumbnailShell({
+ required this.size,
+ required this.child,
+ this.backgroundColor,
+ });
+
+ final double size;
+ final Widget child;
+ final Color? backgroundColor;
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ width: size,
+ height: size,
+ child: ClipSmoothRect(
+ radius: SmoothBorderRadius(
+ cornerRadius: _EditContactPageState._avatarRadius,
+ cornerSmoothing: _EditContactPageState._avatarCornerSmoothing,
+ ),
+ child: ColoredBox(
+ color: backgroundColor ?? Colors.transparent,
+ child: SizedBox.expand(child: child),
+ ),
+ ),
+ );
+ }
+}
+
class _AutofillLeadingWidget extends StatelessWidget {
final PersonEntity? person;
final List<PersonEntity> previewPeople;
diff --git a/mobile/apps/photos/test/services/photos_contacts_service_test.dart b/mobile/apps/photos/test/services/photos_contacts_service_test.dart
new file mode 100644
index 0000000000..f2483a1f37
--- /dev/null
+++ b/mobile/apps/photos/test/services/photos_contacts_service_test.dart
@@ -0,0 +1,83 @@
+import 'dart:typed_data';
+
+import 'package:ente_contacts/contacts.dart' as contacts;
+import 'package:flutter_test/flutter_test.dart';
+import 'package:photos/services/photos_contacts_service.dart';
+
+void main() {
+ late FakeContactsService contactsService;
+ late PhotosContactsService service;
+ late contacts.ContactsSession session;
+
+ setUp(() {
+ contactsService = FakeContactsService(
+ localContacts: const [
+ contacts.ContactRecord(
+ id: 'ct_1',
+ contactUserId: 7,
+ email: '[email protected]',
+ data: contacts.ContactData(contactUserId: 7, name: 'Alice'),
+ profilePictureAttachmentId: null,
+ isDeleted: false,
+ createdAt: 1,
+ updatedAt: 2,
+ ),
+ ],
+ syncError: StateError('boom'),
+ );
+ service = PhotosContactsService.forTesting(contactsService: contactsService);
+ session = contacts.ContactsSession(
+ baseUrl: 'http://localhost:8080',
+ authToken: 'token',
+ userId: 1,
+ accountKey: Uint8List.fromList([1, 2, 3]),
+ );
+ });
+
+ test('debugOpenAndSync hydrates local cache even when sync fails', () async {
+ await service.debugOpenAndSync(session);
+
+ expect(service.hasHydratedCache, isTrue);
+ expect(service.getCachedSavedNameByUserId(7), 'Alice');
+ expect(service.getCachedResolvedEmailByUserId(7), '[email protected]');
+ expect(await service.getContactByUserId(7), isNotNull);
+ expect(contactsService.openCalls, 1);
+ expect(contactsService.syncCalls, 1);
+ });
+}
+
+class FakeContactsService extends Fake implements contacts.ContactsService {
+ FakeContactsService({
+ required this.localContacts,
+ this.syncDiff = const [],
+ this.syncError,
+ });
+
+ final List<contacts.ContactRecord> localContacts;
+ final List<contacts.ContactRecord> syncDiff;
+ final Object? syncError;
+ int openCalls = 0;
+ int syncCalls = 0;
+
+ @override
+ Future<void> open(contacts.ContactsSession session) async {
+ openCalls += 1;
+ }
+
+ @override
+ Future<List<contacts.ContactRecord>> getContacts({
+ bool includeDeleted = false,
+ }) async {
+ return localContacts;
+ }
+
+ @override
+ Future<List<contacts.ContactRecord>> sync() async {
+ syncCalls += 1;
+ final error = syncError;
+ if (error != null) {
+ throw error;
+ }
+ return syncDiff;
+ }
+}