Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob] Add support for removing people to cluster mapping

Neeraj Gupta2d5855873776
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<void> 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<void> 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<void> 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<PeopleAppBar> {
// ],
// ),
// ),
- // 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<PeopleAppBar> {
await setCoverPhoto(context);
} else if (value == PeoplPopupAction.hide) {
// ignore: unawaited_futures
+ } else if (value == PeoplPopupAction.remove) {
+ await PersonService.instance.deletePerson(widget.person.remoteID);
}
},
),