Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Create new cluster when tapping unassigned face

laurenspriem811ffe011763
diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart
index bdc4db0070..f54b3c6ef4 100644
--- a/mobile/lib/face/db.dart
+++ b/mobile/lib/face/db.dart
@@ -348,6 +348,18 @@ class FaceMLDataDB {
return result;
}
+ Future<int?> getClusterIDForFaceID(String faceID) async {
+ final db = await instance.sqliteAsyncDB;
+ final List<Map<String, dynamic>> maps = await db.getAll(
+ 'SELECT $fcClusterID FROM $faceClustersTable WHERE $fcFaceId = ?',
+ [faceID],
+ );
+ if (maps.isEmpty) {
+ return null;
+ }
+ return maps.first[fcClusterID] as int;
+ }
+
Future<Map<int, Iterable<String>>> getAllClusterIdToFaceIDs() async {
final db = await instance.sqliteAsyncDB;
final Map<int, List<String>> result = {};
diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dart
index 4caf1305f4..9be6193344 100644
--- a/mobile/lib/ui/viewer/file_details/face_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart
@@ -4,6 +4,7 @@ import "dart:typed_data";
import "package:flutter/cupertino.dart";
import "package:flutter/foundation.dart" show kDebugMode;
import "package:flutter/material.dart";
+import "package:photos/extensions/stop_watch.dart";
import "package:photos/face/db.dart";
import "package:photos/face/model/face.dart";
import "package:photos/face/model/person.dart";
@@ -65,7 +66,50 @@ class _FaceWidgetState extends State<FaceWidget> {
name: "FaceWidget",
);
if (widget.person == null && widget.clusterID == null) {
- return;
+ // Get faceID and double check that it doesn't belong to an existing clusterID. If it does, push that cluster page
+ final w = (kDebugMode ? EnteWatch('FaceWidget') : null)
+ ?..start();
+ final existingClusterID = await FaceMLDataDB.instance
+ .getClusterIDForFaceID(widget.face.faceID);
+ w?.log('getting existing clusterID for faceID');
+ if (existingClusterID != null) {
+ final fileIdsToClusterIds =
+ await FaceMLDataDB.instance.getFileIdToClusterIds();
+ final files = await SearchService.instance.getAllFiles();
+ final clusterFiles = files
+ .where(
+ (file) =>
+ fileIdsToClusterIds[file.uploadedFileID]
+ ?.contains(existingClusterID) ??
+ false,
+ )
+ .toList();
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => ClusterPage(
+ clusterFiles,
+ clusterID: existingClusterID,
+ ),
+ ),
+ );
+ }
+
+ // Create new clusterID for the faceID and update DB to assign the faceID to the new clusterID
+ final int newClusterID =
+ DateTime.now().microsecondsSinceEpoch;
+ await FaceMLDataDB.instance.updateFaceIdToClusterId(
+ {widget.face.faceID: newClusterID},
+ );
+
+ // Push page for the new cluster
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => ClusterPage(
+ [widget.file],
+ clusterID: newClusterID,
+ ),
+ ),
+ );
}
if (widget.person != null) {
await Navigator.of(context).push(
@@ -230,7 +274,49 @@ class _FaceWidgetState extends State<FaceWidget> {
name: "FaceWidget",
);
if (widget.person == null && widget.clusterID == null) {
- return;
+ // Get faceID and double check that it doesn't belong to an existing clusterID. If it does, push that cluster page
+ final w = (kDebugMode ? EnteWatch('FaceWidget') : null)
+ ?..start();
+ final existingClusterID = await FaceMLDataDB.instance
+ .getClusterIDForFaceID(widget.face.faceID);
+ w?.log('getting existing clusterID for faceID');
+ if (existingClusterID != null) {
+ final fileIdsToClusterIds =
+ await FaceMLDataDB.instance.getFileIdToClusterIds();
+ final files = await SearchService.instance.getAllFiles();
+ final clusterFiles = files
+ .where(
+ (file) =>
+ fileIdsToClusterIds[file.uploadedFileID]
+ ?.contains(existingClusterID) ??
+ false,
+ )
+ .toList();
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => ClusterPage(
+ clusterFiles,
+ clusterID: existingClusterID,
+ ),
+ ),
+ );
+ }
+
+ // Create new clusterID for the faceID and update DB to assign the faceID to the new clusterID
+ final int newClusterID = DateTime.now().microsecondsSinceEpoch;
+ await FaceMLDataDB.instance.updateFaceIdToClusterId(
+ {widget.face.faceID: newClusterID},
+ );
+
+ // Push page for the new cluster
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => ClusterPage(
+ [widget.file],
+ clusterID: newClusterID,
+ ),
+ ),
+ );
}
if (widget.person != null) {
await Navigator.of(context).push(