π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make fallback avatar roles explicit
Neeraj Gupta3f60f5bbb830
diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dartindex 11ce1d4126..52170f79cb 100644--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart@@ -24,13 +24,6 @@ Color getUserAvatarColor(BuildContext context, User user) {AvatarIdentity getUserAvatarIdentity(User user) {final resolvedEmail = resolveKnownEmail(user);- 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,@@ -45,6 +38,7 @@ class UserAvatarWidget extends StatefulWidget {final int currentUserID;final bool thumbnailView;final bool addStroke;+ final AvatarIdentity? fallbackIdentity;const UserAvatarWidget(this.user, {@@ -53,6 +47,7 @@ class UserAvatarWidget extends StatefulWidget {this.type = AvatarType.medium,this.thumbnailView = false,this.addStroke = true,+ this.fallbackIdentity,});@override@@ -191,21 +186,31 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {: _FirstLetterCircularAvatar(user: widget.user,type: widget.type,+ fallbackIdentity: widget.fallbackIdentity,),),)- : _FirstLetterCircularAvatar(user: widget.user, type: widget.type);+ : _FirstLetterCircularAvatar(+ user: widget.user,+ type: widget.type,+ fallbackIdentity: widget.fallbackIdentity,+ );}}class _FirstLetterCircularAvatar extends StatelessWidget {final User user;final AvatarType type;- const _FirstLetterCircularAvatar({required this.user, required this.type});+ final AvatarIdentity? fallbackIdentity;+ const _FirstLetterCircularAvatar({+ required this.user,+ required this.type,+ required this.fallbackIdentity,+ });@overrideWidget build(BuildContext context) {- final identity = getUserAvatarIdentity(user);+ final identity = fallbackIdentity ?? getUserAvatarIdentity(user);final avatarStyle = getAvatarStyle(context, type);final double size = avatarStyle.item1;diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dartindex e2076723ea..d0486d1307 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart@@ -7,6 +7,7 @@ import "package:photos/models/api/collection/user.dart";import "package:photos/models/file/file.dart";import 'package:photos/models/file/trash_file.dart';import 'package:photos/ui/sharing/user_avator_widget.dart';+import "package:photos/utils/avatar_util.dart";class ThumbnailPlaceHolder extends StatelessWidget {final Color? color;@@ -136,10 +137,12 @@ class VideoOverlayDuration extends StatelessWidget {class OwnerAvatarOverlayIcon extends StatelessWidget {final User user;final AvatarType type;+ final AvatarIdentity? fallbackIdentity;const OwnerAvatarOverlayIcon(this.user, {super.key,this.type = AvatarType.small,+ this.fallbackIdentity,});@override@@ -148,7 +151,12 @@ class OwnerAvatarOverlayIcon extends StatelessWidget {alignment: Alignment.topRight,child: Padding(padding: const EdgeInsets.only(right: 4, top: 4),- child: UserAvatarWidget(user, type: type, thumbnailView: true),+ child: UserAvatarWidget(+ user,+ type: type,+ thumbnailView: true,+ fallbackIdentity: fallbackIdentity,+ ),),);}diff --git a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dartindex 64aabe2b48..986c114503 100644--- a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart@@ -29,6 +29,7 @@ import "package:photos/ui/sharing/user_avator_widget.dart";import 'package:photos/ui/viewer/file/file_icons_widget.dart';import 'package:photos/ui/viewer/gallery/component/group/type.dart';import 'package:photos/ui/viewer/gallery/state/gallery_context_state.dart';+import "package:photos/utils/avatar_util.dart";class ThumbnailWidget extends StatefulWidget {final EnteFile file;@@ -228,10 +229,12 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {);} else if (widget.file.isCollect) {contentChildren.add(- // Use -1 as userID for enforcing black avatar colorOwnerAvatarOverlayIcon(- User(id: -1, email: '', name: widget.file.uploaderName),+ User(email: '', name: widget.file.uploaderName),type: widget.ownerAvatarType,+ fallbackIdentity: AvatarIdentity.publicUploader(+ label: widget.file.uploaderName!,+ ),),);}diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dartindex ad3803aa5c..3493b536e9 100644--- a/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file_details/added_by_widget.dart@@ -23,10 +23,7 @@ class AddedByWidget extends StatelessWidget {if (uploaderName == null || uploaderName.isEmpty) {return const SizedBox.shrink();}- identity = AvatarIdentity(- label: uploaderName,- role: AvatarIdentityRole.publicUploader,- );+ identity = AvatarIdentity.publicUploader(label: uploaderName);} else {if (file.ownerID == null) {return const SizedBox.shrink();diff --git a/mobile/apps/photos/lib/utils/avatar_util.dart b/mobile/apps/photos/lib/utils/avatar_util.dartindex efd88f276b..93238200e8 100644--- a/mobile/apps/photos/lib/utils/avatar_util.dart+++ b/mobile/apps/photos/lib/utils/avatar_util.dart@@ -12,18 +12,11 @@ enum AvatarIdentityRole {}class AvatarIdentity {- AvatarIdentity({+ AvatarIdentity._({required this.label,- String? email,- int? userID,- String? personID,- this.role = AvatarIdentityRole.standard,- }) : key = avatarIdentityKey(- email: email,- userID: userID,- personID: personID,- name: label,- );+ required this.key,+ required this.role,+ });factory AvatarIdentity.account({required String label,@@ -38,15 +31,37 @@ class AvatarIdentity {normalizedEmail == normalizeAvatarEmail(currentUserEmail)? AvatarIdentityRole.currentUser: AvatarIdentityRole.standard;- return AvatarIdentity(+ return AvatarIdentity._(label: label,- email: normalizedEmail,- userID: userID,- personID: personID,+ key: avatarIdentityKey(+ email: normalizedEmail,+ userID: userID,+ personID: personID,+ name: label,+ ),role: role,);}+ factory AvatarIdentity.anonymous({+ required String label,+ required String anonymousID,+ }) {+ return AvatarIdentity._(+ label: label,+ key: avatarIdentityKey(anonymousID: anonymousID, name: label),+ role: AvatarIdentityRole.standard,+ );+ }++ factory AvatarIdentity.publicUploader({required String label}) {+ return AvatarIdentity._(+ label: label,+ key: avatarIdentityKey(name: label),+ role: AvatarIdentityRole.publicUploader,+ );+ }+final String label;final String key;final AvatarIdentityRole role;@@ -61,19 +76,24 @@ String avatarIdentityKey({String? email,int? userID,String? personID,+ String? anonymousID,String? name,}) {final normalizedEmail = normalizeAvatarEmail(email);if (normalizedEmail != null) {return "email:$normalizedEmail";}- if (userID != null) {+ if (userID != null && userID > 0) {return "user:$userID";}final normalizedPersonID = personID?.trim();if (normalizedPersonID != null && normalizedPersonID.isNotEmpty) {return "person:$normalizedPersonID";}+ final normalizedAnonymousID = anonymousID?.trim().toLowerCase();+ if (normalizedAnonymousID != null && normalizedAnonymousID.isNotEmpty) {+ return "anonymous:$normalizedAnonymousID";+ }final normalizedName = name?.trim().toLowerCase().replaceAll(RegExp(r"\s+")," ",diff --git a/mobile/apps/photos/test/utils/avatar_util_test.dart b/mobile/apps/photos/test/utils/avatar_util_test.dartindex 64293fc6f4..c534278e15 100644--- a/mobile/apps/photos/test/utils/avatar_util_test.dart+++ b/mobile/apps/photos/test/utils/avatar_util_test.dart@@ -5,13 +5,19 @@ import "package:photos/utils/avatar_util.dart";void main() {test("email identity is normalized and independent of the label", () {- final before = AvatarIdentity(+ final before = AvatarIdentity.account(label: "Alice",email: " [email protected] ",userID: 7,personID: "person-1",+ currentUserEmail: null,+ );+ final after = AvatarIdentity.account(+ label: "Bob",+ email: "[email protected]",+ userID: null,+ currentUserEmail: null,);- final after = AvatarIdentity(label: "Bob", email: "[email protected]");expect(before.key, "email:[email protected]");expect(after.key, before.key);@@ -33,6 +39,19 @@ void main() {"person:person-1",);expect(avatarIdentityKey(name: " Alice Smith "), "name:alice smith");+ expect(avatarIdentityKey(userID: -1, name: "Alice"), "name:alice");+ });++ test("anonymous identity is independent of its display name", () {+ final before = AvatarIdentity.anonymous(+ label: "Alice",+ anonymousID: " Anon-1 ",+ );+ final after = AvatarIdentity.anonymous(label: "Bob", anonymousID: "anon-1");++ expect(before.key, "anonymous:anon-1");+ expect(after.key, before.key);+ expect(after.role, AvatarIdentityRole.standard);});test("marks the signed-in email as the current-user role", () {@@ -52,9 +71,14 @@ void main() {ComponentTheme.lightTheme(),ComponentTheme.darkTheme(),]) {- for (final role in [- AvatarIdentityRole.currentUser,- AvatarIdentityRole.publicUploader,+ for (final identity in [+ AvatarIdentity.account(+ label: "A",+ email: "[email protected]",+ userID: 7,+ currentUserEmail: "[email protected]",+ ),+ AvatarIdentity.publicUploader(label: "A"),]) {late Color backgroundColor;await tester.pumpWidget(@@ -62,10 +86,7 @@ void main() {theme: theme,home: Builder(builder: (context) {- backgroundColor = avatarBackgroundColor(- context,- AvatarIdentity(label: "A", role: role),- );+ backgroundColor = avatarBackgroundColor(context, identity);return const SizedBox.shrink();},),