Skip to content

armgit / ente

Public Imported from GitHub
0

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

Keep contact avatar colors stable while editing

Neeraj Gupta5c8d6023bc7d
diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
index 776c12795b..1f305d850d 100644
--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
@@ -24,18 +24,18 @@ Color getUserAvatarColor(BuildContext context, User user) {
AvatarIdentity getUserAvatarIdentity(User user) {
final resolvedEmail = resolveKnownEmail(user);
- final currentEmail = normalizeAvatarEmail(Configuration.instance.getEmail());
- final role = user.id != null && user.id! < 0
- ? AvatarIdentityRole.publicUploader
- : currentEmail != null &&
- normalizeAvatarEmail(resolvedEmail) == currentEmail
- ? AvatarIdentityRole.currentUser
- : AvatarIdentityRole.standard;
- return AvatarIdentity(
+ if (user.id != null && user.id! < 0) {
+ return AvatarIdentity(
+ label: resolveDisplayName(user),
+ userID: user.id,
+ role: AvatarIdentityRole.publicUploader,
+ );
+ }
+ return AvatarIdentity.account(
label: resolveDisplayName(user),
email: resolvedEmail,
userID: user.id,
- role: role,
+ currentUserEmail: Configuration.instance.getEmail(),
);
}
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 aaba6982fb..ac96585831 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
@@ -6,6 +6,7 @@ import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.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/generated/l10n.dart";
@@ -26,6 +27,7 @@ import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";
import "package:photos/ui/viewer/search/result/contact_person_picker_page.dart";
import "package:photos/ui/viewer/search/result/contact_photo_adjust_page.dart";
import "package:photos/ui/viewer/search/result/contact_photo_picker_sheet.dart";
+import "package:photos/utils/avatar_util.dart";
import "package:photos/utils/contact_photo_util.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/person_contact_linking_util.dart";
@@ -218,14 +220,12 @@ class _EditContactPageState extends State<EditContactPage> {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
final trimmedName = _nameController.text.trim();
- final initial = trimmedName.isNotEmpty
- ? trimmedName.characters.first.toUpperCase()
- : widget.email.characters.first.toUpperCase();
- final avatarSeed = trimmedName.isNotEmpty ? trimmedName : widget.email;
- final avatarColor =
- colorScheme.avatarColors[avatarSeed.length.remainder(
- colorScheme.avatarColors.length,
- )];
+ final identity = AvatarIdentity.account(
+ label: trimmedName.isNotEmpty ? trimmedName : widget.email,
+ email: widget.email,
+ userID: widget.contactUserId,
+ currentUserEmail: Configuration.instance.getEmail(),
+ );
if (_isLoadingPhoto) {
return _ContactThumbnailShell(
@@ -244,10 +244,10 @@ class _EditContactPageState extends State<EditContactPage> {
return _ContactThumbnailShell(
size: size,
- backgroundColor: avatarColor,
+ backgroundColor: avatarBackgroundColor(context, identity),
child: Center(
child: Text(
- initial,
+ identity.initial,
style: textTheme.h1Bold.copyWith(
fontSize: 38.25,
height: 47.813 / 38.25,
diff --git a/mobile/apps/photos/lib/utils/avatar_util.dart b/mobile/apps/photos/lib/utils/avatar_util.dart
index 06046849fd..b6d8b7e746 100644
--- a/mobile/apps/photos/lib/utils/avatar_util.dart
+++ b/mobile/apps/photos/lib/utils/avatar_util.dart
@@ -17,6 +17,26 @@ class AvatarIdentity {
name: label,
);
+ factory AvatarIdentity.account({
+ required String label,
+ required String? email,
+ required int? userID,
+ required String? currentUserEmail,
+ }) {
+ final normalizedEmail = normalizeAvatarEmail(email);
+ final role =
+ normalizedEmail != null &&
+ normalizedEmail == normalizeAvatarEmail(currentUserEmail)
+ ? AvatarIdentityRole.currentUser
+ : AvatarIdentityRole.standard;
+ return AvatarIdentity(
+ label: label,
+ email: normalizedEmail,
+ userID: userID,
+ role: role,
+ );
+ }
+
final String label;
final String key;
final AvatarIdentityRole role;
diff --git a/mobile/apps/photos/test/utils/avatar_util_test.dart b/mobile/apps/photos/test/utils/avatar_util_test.dart
index 5dba40debf..a11363f9db 100644
--- a/mobile/apps/photos/test/utils/avatar_util_test.dart
+++ b/mobile/apps/photos/test/utils/avatar_util_test.dart
@@ -41,4 +41,16 @@ void main() {
expect(after.key, before.key);
expect(after.initial, "A");
});
+
+ test("marks the signed-in email as the current-user role", () {
+ final identity = AvatarIdentity.account(
+ label: "Alice",
+ email: " [email protected] ",
+ userID: 7,
+ currentUserEmail: "[email protected]",
+ );
+
+ expect(identity.role, AvatarIdentityRole.currentUser);
+ expect(identity.key, "email:[email protected]");
+ });
}