Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use linked person names in Family

Neeraj Gupta4c5616836218
diff --git a/mobile/apps/photos/lib/ui/family/family_dashboard.dart b/mobile/apps/photos/lib/ui/family/family_dashboard.dart
index 4bbe334ab9..7cad46d0e9 100644
--- a/mobile/apps/photos/lib/ui/family/family_dashboard.dart
+++ b/mobile/apps/photos/lib/ui/family/family_dashboard.dart
@@ -68,6 +68,7 @@ class FamilyDashboard extends StatelessWidget {
required this.contactsByUserId,
required this.profilePictureBytesByUserId,
required this.linkedPersonIdsByUserId,
+ required this.linkedPersonNamesByUserId,
required this.onMemberTap,
required this.onAddMember,
required this.remainingSlots,
@@ -80,6 +81,7 @@ class FamilyDashboard extends StatelessWidget {
final Map<int, contacts.ContactRecord?> contactsByUserId;
final Map<int, Uint8List?> profilePictureBytesByUserId;
final Map<int, String> linkedPersonIdsByUserId;
+ final Map<int, String> linkedPersonNamesByUserId;
final ValueChanged<FamilyMember> onMemberTap;
final VoidCallback onAddMember;
final int remainingSlots;
@@ -158,16 +160,23 @@ class FamilyDashboard extends StatelessWidget {
}
String _displayNameFor(FamilyMember member) =>
- _savedNameFor(member) ?? member.email;
+ _savedNameFor(member) ?? _linkedPersonNameFor(member) ?? member.email;
String _storageLabelFor(FamilyMember member) =>
- _savedNameFor(member) ?? member.email.split('@').first;
+ _savedNameFor(member) ??
+ _linkedPersonNameFor(member) ??
+ member.email.split('@').first;
String? _savedNameFor(FamilyMember member) {
final savedName = contactsByUserId[member.userID]?.data?.name.trim();
return savedName == null || savedName.isEmpty ? null : savedName;
}
+ String? _linkedPersonNameFor(FamilyMember member) {
+ final personName = linkedPersonNamesByUserId[member.userID]?.trim();
+ return personName == null || personName.isEmpty ? null : personName;
+ }
+
AvatarComponentColor _avatarColorFor(FamilyMember member) =>
familyMemberAvatarComponentColor(member);
}
diff --git a/mobile/apps/photos/lib/ui/family/family_plan_page.dart b/mobile/apps/photos/lib/ui/family/family_plan_page.dart
index 145c1f1fb0..639bc84148 100644
--- a/mobile/apps/photos/lib/ui/family/family_plan_page.dart
+++ b/mobile/apps/photos/lib/ui/family/family_plan_page.dart
@@ -348,38 +348,48 @@ class _FamilyPlanPageState extends State<FamilyPlanPage> {
Widget _buildDashboard(BuildContext context, {required bool isAdminView}) {
final members = _userDetails.familyData?.members ?? const <FamilyMember>[];
+ final linkedPersons = _linkedPersonsFor(members);
return FamilyDashboard(
userDetails: _userDetails,
members: members,
isAdmin: isAdminView,
contactsByUserId: _contactsByUserId,
profilePictureBytesByUserId: _profilePictureBytesByUserId,
- linkedPersonIdsByUserId: _linkedPersonIdsFor(members),
+ linkedPersonIdsByUserId: linkedPersons.idsByUserId,
+ linkedPersonNamesByUserId: linkedPersons.namesByUserId,
onMemberTap: _showMemberActions,
onAddMember: () => unawaited(_openInvitePage()),
remainingSlots: _remainingSlots,
);
}
- Map<int, String> _linkedPersonIdsFor(List<FamilyMember> members) {
+ ({Map<int, String> idsByUserId, Map<int, String> namesByUserId})
+ _linkedPersonsFor(List<FamilyMember> members) {
if (!PersonService.isInitialized) {
- return const {};
+ return (idsByUserId: const {}, namesByUserId: const {});
}
- final result = <int, String>{};
+ final idsByUserId = <int, String>{};
+ final namesByUserId = <int, String>{};
for (final member in members) {
final userID = member.userID;
if (userID == null) {
continue;
}
- final personID = PersonService.instance.getCachedPartialPersonData(
+ final personData = PersonService.instance.getCachedPartialPersonData(
userID: userID,
email: member.email,
- )?[PersonService.kPersonIDKey];
- if (personID != null) {
- result[userID] = personID;
+ );
+ final personID = personData?[PersonService.kPersonIDKey];
+ if (personID == null) {
+ continue;
+ }
+ idsByUserId[userID] = personID;
+ final personName = personData?[PersonService.kNameKey]?.trim();
+ if (personName != null && personName.isNotEmpty) {
+ namesByUserId[userID] = personName;
}
}
- return result;
+ return (idsByUserId: idsByUserId, namesByUserId: namesByUserId);
}
Widget _buildDashboardOverflow(BuildContext context) {
diff --git a/mobile/apps/photos/test/ui/family/family_dashboard_test.dart b/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
index 29fc7d67a3..a4db7c9056 100644
--- a/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
+++ b/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
@@ -192,6 +192,10 @@ void main() {
},
profilePictureBytesByUserId: const {},
linkedPersonIdsByUserId: const {},
+ linkedPersonNamesByUserId: const {
+ 1: 'Person current user',
+ 42: 'Person saved member',
+ },
onMemberTap: (member) => selectedMember = member,
onAddMember: () {},
remainingSlots: 2,
@@ -261,10 +265,14 @@ void main() {
},
);
- testWidgets('uses a linked Person face when no contact photo is saved', (
+ testWidgets('uses a linked Person name and face without a saved contact', (
tester,
) async {
- final member = _member(email: '[email protected]', userID: 42);
+ final member = _member(
+ email: '[email protected]',
+ userID: 42,
+ status: FamilyMemberStatus.self,
+ );
final members = [member];
await tester.pumpWidget(
@@ -280,6 +288,7 @@ void main() {
contactsByUserId: const {},
profilePictureBytesByUserId: const {},
linkedPersonIdsByUserId: const {42: 'person-42'},
+ linkedPersonNamesByUserId: const {42: 'Current person'},
onMemberTap: (_) {},
onAddMember: () {},
remainingSlots: 0,
@@ -288,6 +297,7 @@ void main() {
),
);
+ expect(find.text('Current person'), findsWidgets);
expect(find.byType(PersonFaceWidget), findsOneWidget);
final personAvatar = tester.widget<PersonFaceWidget>(
find.byType(PersonFaceWidget),
@@ -326,6 +336,7 @@ void main() {
},
profilePictureBytesByUserId: const {},
linkedPersonIdsByUserId: const {},
+ linkedPersonNamesByUserId: const {4: 'Aaron'},
onMemberTap: (_) {},
onAddMember: () {},
remainingSlots: 0,
@@ -339,7 +350,7 @@ void main() {
tester
.widgetList<MenuComponent>(find.byType(MenuComponent))
.map((item) => item.title),
- ['[email protected]', 'Amy', '[email protected]', 'Zoe'],
+ ['[email protected]', 'Aaron', 'Amy', 'Zoe'],
);
});
}