π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Derive anonymous avatar identity centrally
Neeraj Gupta25f1fd9a49a7
diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dartindex 1a7c4dd21d..52170f79cb 100644--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart@@ -32,13 +32,6 @@ AvatarIdentity getUserAvatarIdentity(User user) {);}-AvatarIdentity getAnonymousUserAvatarIdentity(User user, String anonymousID) {- return AvatarIdentity.anonymous(- label: resolveDisplayName(user),- anonymousID: anonymousID,- );-}-class UserAvatarWidget extends StatefulWidget {final User user;final AvatarType type;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.dartindex 2e8c9fb184..611c165905 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@@ -11,7 +11,6 @@ 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";-import "package:photos/utils/avatar_util.dart";const _shrinkWrapThreshold = 30;@@ -170,12 +169,6 @@ class _CommentLikesBottomSheetState extends State<CommentLikesBottomSheet> {final user = _getUserForReaction(reaction);return _CommentLikeListItem(user: user,- fallbackIdentity: reaction.anonUserID == null- ? null- : getAnonymousUserAvatarIdentity(- user,- reaction.anonUserID!,- ),currentUserID: widget.currentUserID,youLabel: l10n.you,onTap: () => openSocialActorContactDestination(@@ -198,14 +191,12 @@ class _CommentLikesBottomSheetState extends State<CommentLikesBottomSheet> {class _CommentLikeListItem extends StatelessWidget {final User user;- final AvatarIdentity? fallbackIdentity;final int currentUserID;final String youLabel;final VoidCallback? onTap;const _CommentLikeListItem({required this.user,- required this.fallbackIdentity,required this.currentUserID,required this.youLabel,this.onTap,@@ -224,7 +215,6 @@ class _CommentLikeListItem extends StatelessWidget {currentUserID: currentUserID,type: AvatarType.regular,addStroke: false,- fallbackIdentity: fallbackIdentity,),const SizedBox(width: 12),Expanded(diff --git a/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart b/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dartindex 1df5f0f5b8..325347eb95 100644--- a/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart+++ b/mobile/apps/photos/lib/ui/social/likes_bottom_sheet.dart@@ -18,7 +18,6 @@ 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";-import "package:photos/utils/avatar_util.dart";const _shrinkWrapThreshold = 30;@@ -413,9 +412,6 @@ class _LikesList extends StatelessWidget {final user = _getUserForReaction(reaction);return _LikeListItem(user: user,- fallbackIdentity: reaction.anonUserID == null- ? null- : getAnonymousUserAvatarIdentity(user, reaction.anonUserID!),currentUserID: currentUserID,youLabel: l10n.you,onTap: () => onUserTap(user),@@ -427,14 +423,12 @@ class _LikesList extends StatelessWidget {class _LikeListItem extends StatelessWidget {final User user;- final AvatarIdentity? fallbackIdentity;final int currentUserID;final String youLabel;final VoidCallback? onTap;const _LikeListItem({required this.user,- required this.fallbackIdentity,required this.currentUserID,required this.youLabel,this.onTap,@@ -453,7 +447,6 @@ class _LikeListItem extends StatelessWidget {currentUserID: currentUserID,type: AvatarType.regular,addStroke: false,- fallbackIdentity: fallbackIdentity,),const SizedBox(width: 12),Expanded(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.dartindex e76876313f..25903527be 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@@ -21,7 +21,6 @@ import "package:photos/ui/social/widgets/comment_actions_popup.dart";import "package:photos/ui/social/widgets/comment_like_count_capsule.dart";import "package:photos/ui/social/widgets/delete_comment_confirmation_dialog.dart";import "package:photos/ui/social/widgets/resolved_social_user_name.dart";-import "package:photos/utils/avatar_util.dart";import "package:photos/utils/social/relative_time_formatter.dart";final _logger = Logger("CommentBubbleWidget");@@ -520,12 +519,6 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>child: _Header(isOwnComment: widget.isOwnComment,user: widget.user,- fallbackIdentity: widget.comment.anonUserID == null- ? null- : getAnonymousUserAvatarIdentity(- widget.user,- widget.comment.anonUserID!,- ),createdAt: widget.comment.createdAt,currentUserID: widget.currentUserID,onAuthorTap: widget.onAuthorTap,@@ -825,7 +818,6 @@ class _CommentBubble extends StatelessWidget {class _Header extends StatelessWidget {final bool isOwnComment;final User user;- final AvatarIdentity? fallbackIdentity;final int createdAt;final int currentUserID;final VoidCallback? onAuthorTap;@@ -833,7 +825,6 @@ class _Header extends StatelessWidget {const _Header({required this.isOwnComment,required this.user,- required this.fallbackIdentity,required this.createdAt,required this.currentUserID,this.onAuthorTap,@@ -918,7 +909,6 @@ class _Header extends StatelessWidget {type: AvatarType.regular,thumbnailView: true,addStroke: false,- fallbackIdentity: fallbackIdentity,),const SizedBox(width: 10),Flexible(child: headerText),@@ -931,7 +921,6 @@ class _Header extends StatelessWidget {type: AvatarType.regular,thumbnailView: true,addStroke: false,- fallbackIdentity: fallbackIdentity,),],],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.dartindex a5a24131e2..8f173f197c 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@@ -13,9 +13,6 @@ import "package:photos/ui/sharing/user_avator_widget.dart";import "package:photos/ui/social/widgets/resolved_social_user_name.dart";import "package:photos/ui/social/widgets/shared_photos_grid.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";-import "package:photos/utils/avatar_util.dart";--typedef _AvatarActor = ({User user, AvatarIdentity? fallbackIdentity});/// Widget that displays a single feed item.class FeedItemWidget extends StatelessWidget {@@ -384,7 +381,7 @@ class _StackedAvatars extends StatelessWidget {if (displayCount == 1) {return _wrapActorTap(_buildSingleAvatar(actors.first, colorScheme),- actors.first.user,+ actors.first,);}@@ -408,11 +405,10 @@ class _StackedAvatars extends StatelessWidget {),),child: UserAvatarWidget(- actors.first.user,+ actors.first,type: AvatarType.regular,currentUserID: currentUserID,addStroke: false,- fallbackIdentity: actors.first.fallbackIdentity,),),),@@ -428,33 +424,31 @@ class _StackedAvatars extends StatelessWidget {),),child: UserAvatarWidget(- actors[1].user,+ actors[1],type: AvatarType.regular,currentUserID: currentUserID,addStroke: false,- fallbackIdentity: actors[1].fallbackIdentity,),),),],),),- actors.first.user,+ actors.first,);}- Widget _buildSingleAvatar(_AvatarActor actor, EnteColorScheme colorScheme) {+ Widget _buildSingleAvatar(User user, EnteColorScheme colorScheme) {return Container(decoration: BoxDecoration(shape: BoxShape.circle,border: Border.all(color: colorScheme.backgroundColour, width: 1.167),),child: UserAvatarWidget(- actor.user,+ user,type: AvatarType.regular,currentUserID: currentUserID,addStroke: false,- fallbackIdentity: actor.fallbackIdentity,),);}@@ -471,8 +465,8 @@ class _StackedAvatars extends StatelessWidget {);}- List<_AvatarActor> _getActors() {- final actors = <_AvatarActor>[];+ List<User> _getActors() {+ final users = <User>[];final maxActors = feedItem.actorCount.clamp(1, 2);for (int i = 0; i < maxActors; i++) {@@ -482,26 +476,20 @@ class _StackedAvatars extends StatelessWidget {if (userID <= 0 && anonID != null) {// Anonymous user - use decrypted display name if availablefinal displayName = anonDisplayNames[anonID] ?? anonID;- final user = User(- id: userID,- email: "[email protected]",- name: displayName,+ users.add(+ User(id: userID, email: "[email protected]", name: displayName),);- actors.add((- user: user,- fallbackIdentity: getAnonymousUserAvatarIdentity(user, anonID),- ));} else {// Get user from collections servicefinal user = CollectionsService.instance.getFileOwner(userID,feedItem.collectionID,);- actors.add((user: user, fallbackIdentity: null));+ users.add(user);}}- return actors;+ return users;}}diff --git a/mobile/apps/photos/lib/utils/avatar_util.dart b/mobile/apps/photos/lib/utils/avatar_util.dartindex 93238200e8..988741dc81 100644--- a/mobile/apps/photos/lib/utils/avatar_util.dart+++ b/mobile/apps/photos/lib/utils/avatar_util.dart@@ -37,23 +37,13 @@ class AvatarIdentity {email: normalizedEmail,userID: userID,personID: personID,+ anonymousID: _anonymousIDFromPlaceholderEmail(email),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,@@ -114,6 +104,17 @@ String? normalizeAvatarEmail(String? email) {return normalized;}+String? _anonymousIDFromPlaceholderEmail(String? email) {+ const suffix = "@unknown.com";+ final normalized = email?.trim().toLowerCase();+ if (normalized == null || !normalized.endsWith(suffix)) return null;+ final anonymousID = normalized.substring(+ 0,+ normalized.length - suffix.length,+ );+ return anonymousID.isEmpty ? null : anonymousID;+}+Color avatarBackgroundColor(BuildContext context, AvatarIdentity identity) {return identity.role == AvatarIdentityRole.standard? avatarColorForIdentity(context, identity.key)diff --git a/mobile/apps/photos/test/utils/avatar_util_test.dart b/mobile/apps/photos/test/utils/avatar_util_test.dartindex c534278e15..2ff3df0fd4 100644--- a/mobile/apps/photos/test/utils/avatar_util_test.dart+++ b/mobile/apps/photos/test/utils/avatar_util_test.dart@@ -26,12 +26,12 @@ void main() {test("falls back through stable IDs before name", () {expect(- avatarIdentityKey(+ AvatarIdentity.account(+ label: "Alice",email: "[email protected]",userID: 7,- personID: "person-1",- name: "Alice",- ),+ currentUserEmail: null,+ ).key,"user:7",);expect(@@ -43,11 +43,18 @@ void main() {});test("anonymous identity is independent of its display name", () {- final before = AvatarIdentity.anonymous(+ final before = AvatarIdentity.account(label: "Alice",- anonymousID: " Anon-1 ",+ email: " [email protected] ",+ userID: -1,+ currentUserEmail: null,+ );+ final after = AvatarIdentity.account(+ label: "Bob",+ email: "[email protected]",+ userID: -1,+ currentUserEmail: null,);- final after = AvatarIdentity.anonymous(label: "Bob", anonymousID: "anon-1");expect(before.key, "anonymous:anon-1");expect(after.key, before.key);