Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Make face filtering work (yet to be optimized for performance)

ashilkn2f54acab5870
diff --git a/mobile/lib/db/ml/db.dart b/mobile/lib/db/ml/db.dart
index 0d4b0c2772..71e5a88e6e 100644
--- a/mobile/lib/db/ml/db.dart
+++ b/mobile/lib/db/ml/db.dart
@@ -981,4 +981,22 @@ class MLDataDB {
_logger.severe('Error dropping feedback tables', e);
}
}
+
+ Future<List<int>> getFileIDsFromFace(List<String> faceIDs) async {
+ final fileIDS = <int>[];
+ String inParam = "";
+ for (String faceID in faceIDs) {
+ inParam += "'$faceID', ";
+ }
+ inParam = inParam.substring(0, inParam.length - 2);
+ final db = await instance.asyncDB;
+ final result = await db.getAll(
+ 'SELECT $fileIDColumn FROM $facesTable WHERE $faceIDColumn IN ($inParam)',
+ );
+
+ for (var row in result) {
+ fileIDS.add(row[fileIDColumn] as int);
+ }
+ return fileIDS;
+ }
}
diff --git a/mobile/lib/models/search/hierarchical/face_filter.dart b/mobile/lib/models/search/hierarchical/face_filter.dart
index 921f9f4221..ee2adf3ca5 100644
--- a/mobile/lib/models/search/hierarchical/face_filter.dart
+++ b/mobile/lib/models/search/hierarchical/face_filter.dart
@@ -41,7 +41,7 @@ class FaceFilter extends HierarchicalSearchFilter {
@override
bool isMatch(EnteFile file) {
- return false;
+ throw UnimplementedError();
}
@override
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/applied_filters.dart b/mobile/lib/ui/viewer/hierarchicial_search/applied_filters.dart
index e51cde10f2..87c9d5a31d 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/applied_filters.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/applied_filters.dart
@@ -57,6 +57,9 @@ class _AppliedFiltersState extends State<AppliedFilters> {
clusterId: filter.clusterId,
faceThumbnailFile: EnteFile(),
name: filter.name(),
+ onTap: () {
+ _searchFilterDataProvider.removeAppliedFilters([filter]);
+ },
)
: GenericFilterChip(
label: filter.name(),
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/filter_chip.dart b/mobile/lib/ui/viewer/hierarchicial_search/filter_chip.dart
index ebcee9465f..62a284fd12 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/filter_chip.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/filter_chip.dart
@@ -56,49 +56,54 @@ class FaceFilterChip extends StatelessWidget {
final String? clusterId;
final EnteFile faceThumbnailFile;
final String name;
+ final VoidCallback onTap;
const FaceFilterChip({
required this.personId,
required this.clusterId,
required this.faceThumbnailFile,
required this.name,
+ required this.onTap,
super.key,
});
@override
Widget build(BuildContext context) {
- return Container(
- decoration: BoxDecoration(
- color: getEnteColorScheme(context).fillFaint,
- borderRadius: const BorderRadius.all(Radius.circular(8)),
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 8.0),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- ClipOval(
- child: SizedBox(
- width: 32,
- height: 32,
- child: PersonFaceWidget(
- faceThumbnailFile,
- personId: personId,
- clusterID: clusterId,
+ return GestureDetector(
+ onTap: onTap.call,
+ child: Container(
+ decoration: BoxDecoration(
+ color: getEnteColorScheme(context).fillFaint,
+ borderRadius: const BorderRadius.all(Radius.circular(8)),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 8.0),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ ClipOval(
+ child: SizedBox(
+ width: 32,
+ height: 32,
+ child: PersonFaceWidget(
+ faceThumbnailFile,
+ personId: personId,
+ clusterID: clusterId,
+ ),
),
),
- ),
- name.isNotEmpty
- ? Padding(
- padding: const EdgeInsets.symmetric(horizontal: 4),
- child: Text(
- name,
- style: getEnteTextTheme(context).miniBold,
- ),
- )
- : const SizedBox.shrink(),
- ],
+ name.isNotEmpty
+ ? Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Text(
+ name,
+ style: getEnteTextTheme(context).miniBold,
+ ),
+ )
+ : const SizedBox.shrink(),
+ ],
+ ),
),
),
);
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters.dart b/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters.dart
index da81438fec..b51619d2a1 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters.dart
@@ -56,6 +56,9 @@ class _RecommendedFiltersState extends State<RecommendedFilters> {
clusterId: filter.clusterId,
faceThumbnailFile: filter.faceFile,
name: filter.name(),
+ onTap: () {
+ _searchFilterDataProvider.applyFilters([filter]);
+ },
)
: GenericFilterChip(
label: filter.name(),
diff --git a/mobile/lib/utils/hierarchical_search_util.dart b/mobile/lib/utils/hierarchical_search_util.dart
index f68662e6ab..3d615e4959 100644
--- a/mobile/lib/utils/hierarchical_search_util.dart
+++ b/mobile/lib/utils/hierarchical_search_util.dart
@@ -31,7 +31,36 @@ Future<List<EnteFile>> getFilteredFiles(
final resultsNeverComputedFilters = <HierarchicalSearchFilter>[];
for (HierarchicalSearchFilter filter in filters) {
- if (filter.getMatchedUploadedIDs().isEmpty) {
+ if (filter is FaceFilter && filter.getMatchedUploadedIDs().isEmpty) {
+ try {
+ if (filter.personId != null) {
+ //getFilesForPerson
+ final personClusterIDs = await MLDataDB.instance.getPersonClusterIDs(
+ filter.personId!,
+ );
+ final cluterToFaceIDs =
+ await MLDataDB.instance.getClusterToFaceIDs(personClusterIDs);
+
+ final faceIDs = <String>[];
+ for (Iterable<String> faceIDsIterable in cluterToFaceIDs.values) {
+ faceIDs.addAll(faceIDsIterable);
+ }
+
+ final fileIDs = await MLDataDB.instance.getFileIDsFromFace(faceIDs);
+ filter.matchedUploadedIDs.addAll(fileIDs);
+ } else if (filter.clusterId != null) {
+ //getFilesForCluster
+
+ final cluterToFaceIDs =
+ await MLDataDB.instance.getClusterToFaceIDs({filter.clusterId!});
+ final faceIDs = cluterToFaceIDs.values.expand((e) => e).toList();
+ final fileIDs = await MLDataDB.instance.getFileIDsFromFace(faceIDs);
+ filter.matchedUploadedIDs.addAll(fileIDs);
+ }
+ } catch (e) {
+ log("Error in face filter: $e");
+ }
+ } else if (filter.getMatchedUploadedIDs().isEmpty) {
resultsNeverComputedFilters.add(filter);
}
}