π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Fix user avatar not updating after linking contact to face
ashilkn9671f4e3fcc4
diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dartindex 65fe4462d6..535def5f09 100644--- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart+++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart@@ -462,9 +462,8 @@ class PersonService {email: email,),);- await updatePerson(updatedPerson).then((value) {- _resetEmailToNameCache();- });+ await updatePerson(updatedPerson);+ await _resetEmailToNameCache();return updatedPerson;}diff --git a/mobile/lib/ui/sharing/user_avator_widget.dart b/mobile/lib/ui/sharing/user_avator_widget.dartindex b6df9cbd5b..fc317fd500 100644--- a/mobile/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/lib/ui/sharing/user_avator_widget.dart@@ -1,6 +1,10 @@+import "dart:async";+import "package:collection/collection.dart";import 'package:flutter/material.dart';import "package:logging/logging.dart";+import "package:photos/core/event_bus.dart";+import "package:photos/events/people_changed_event.dart";import "package:photos/extensions/user_extension.dart";import "package:photos/models/api/collection/user.dart";import "package:photos/models/file/file.dart";@@ -8,6 +12,7 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.dimport "package:photos/theme/colors.dart";import 'package:photos/theme/ente_theme.dart';import "package:photos/ui/viewer/search/result/person_face_widget.dart";+import "package:photos/utils/debouncer.dart";import 'package:tuple/tuple.dart';enum AvatarType { small, mini, tiny, extra }@@ -35,24 +40,52 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {Future<String?>? _personID;EnteFile? _faceThumbnail;final _logger = Logger("_UserAvatarWidgetState");+ late final StreamSubscription<PeopleChangedEvent> _peopleChangedSubscription;+ final _debouncer = Debouncer(+ const Duration(milliseconds: 750),+ executionInterval: const Duration(seconds: 20),+ );@overridevoid initState() {super.initState();- if (PersonService- .instance.emailToPartialPersonDataMapCache[widget.user.email] !=- null) {- _personID = PersonService.instance.getPersons().then((people) async {- final person = people.firstWhereOrNull(- (person) => person.data.email == widget.user.email,- );- if (person != null) {- _faceThumbnail =- await PersonService.instance.getRecentFileOfPerson(person);+ _reload();+ _peopleChangedSubscription =+ Bus.instance.on<PeopleChangedEvent>().listen((event) {+ if (event.type == PeopleEventType.saveOrEditPerson) {+ _reload();+ }+ });+ }++ @override+ void dispose() {+ _peopleChangedSubscription.cancel();+ _debouncer.cancelDebounceTimer();+ super.dispose();+ }++ Future<void> _reload() async {+ _debouncer.run(() async {+ setState(() {+ if (PersonService+ .instance.emailToPartialPersonDataMapCache[widget.user.email] !=+ null) {+ _personID = PersonService.instance.getPersons().then((people) async {+ final person = people.firstWhereOrNull(+ (person) => person.data.email == widget.user.email,+ );+ if (person != null) {+ _faceThumbnail =+ await PersonService.instance.getRecentFileOfPerson(person);+ }+ return person?.remoteID;+ });+ } else {+ _personID = null;}- return person?.remoteID;});- }+ });}@override