From 2d5855873776413d60507e0f01452ddfa5409750 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 8 Apr 2024 07:43:08 +0530 Subject: [PATCH] [mob] Add support for removing people to cluster mapping --- mobile/lib/face/db.dart | 11 ++++++++ .../face_ml/person/person_service.dart | 25 +++++++++++++++++ .../lib/ui/viewer/people/people_app_bar.dart | 28 +++++++++++-------- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index bb901a044c..93c4617731 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -368,6 +368,17 @@ class FaceMLDataDB { await batch.commit(noResult: true); } + Future removePerson(String personID) async { + final db = await instance.database; + await db.delete( + clusterPersonTable, + where: '$personIdColumn = ?', + whereArgs: [personID], + ); + await db.delete(notPersonFeedback, + where: '$personIdColumn = ?', whereArgs: [personID]); + } + /// Returns a map of faceID to record of clusterId and faceEmbeddingBlob /// /// Only selects faces with score greater than [minScore] and blur score greater than [minClarity] 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.dart index 4f86e3d1e3..bb66161cbf 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 @@ -1,5 +1,7 @@ import "dart:convert"; +import "package:photos/core/event_bus.dart"; +import "package:photos/events/people_changed_event.dart"; import "package:photos/face/db.dart"; import "package:photos/face/model/person.dart"; import "package:photos/models/api/entity/type.dart"; @@ -84,6 +86,29 @@ class PersonService { return PersonEntity(result.id, data); } + Future deletePerson(String personID, {bool onlyMapping = true}) async { + if (onlyMapping) { + final PersonEntity? entity = await getPerson(personID); + if (entity == null) { + return; + } + final PersonEntity justName = + PersonEntity(personID, PersonData(name: entity.data.name)); + await entityService.addOrUpdate( + EntityType.person, + json.encode(justName.data.toJson()), + id: personID, + ); + await faceMLDataDB.removePerson(personID); + } else { + await entityService.deleteEntry(personID); + await faceMLDataDB.removePerson(personID); + } + + // fire PeopleChangeEvent + Bus.instance.fire(PeopleChangedEvent()); + } + Future storeRemoteFeedback() async { await entityService.syncEntities(); final entities = await entityService.getEntities(EntityType.person); diff --git a/mobile/lib/ui/viewer/people/people_app_bar.dart b/mobile/lib/ui/viewer/people/people_app_bar.dart index 14ced3ea28..14741b5e29 100644 --- a/mobile/lib/ui/viewer/people/people_app_bar.dart +++ b/mobile/lib/ui/viewer/people/people_app_bar.dart @@ -39,6 +39,7 @@ class PeopleAppBar extends StatefulWidget { enum PeoplPopupAction { rename, setCover, + remove, viewPhotos, confirmPhotos, hide, @@ -164,18 +165,19 @@ class _AppBarWidgetState extends State { // ], // ), // ), - // PopupMenuItem( - // value: PeoplPopupAction.rename, - // child: Row( - // children: [ - // const Icon(Icons.visibility_off), - // const Padding( - // padding: EdgeInsets.all(8), - // ), - // Text(S.of(context).hide), - // ], - // ), - // ), + + PopupMenuItem( + value: PeoplPopupAction.remove, + child: Row( + children: [ + const Icon(Icons.remove_circle_outline), + const Padding( + padding: EdgeInsets.all(8), + ), + Text(S.of(context).remove), + ], + ), + ), const PopupMenuItem( value: PeoplPopupAction.viewPhotos, child: Row( @@ -235,6 +237,8 @@ class _AppBarWidgetState extends State { await setCoverPhoto(context); } else if (value == PeoplPopupAction.hide) { // ignore: unawaited_futures + } else if (value == PeoplPopupAction.remove) { + await PersonService.instance.deletePerson(widget.person.remoteID); } }, ),