Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob] Fix person custom avatar rendering

Neeraj Guptabe06d45e3a79
diff --git a/mobile/lib/db/entities_db.dart b/mobile/lib/db/entities_db.dart
index b8b48fbe4a..f7a8afe0fa 100644
--- a/mobile/lib/db/entities_db.dart
+++ b/mobile/lib/db/entities_db.dart
@@ -62,4 +62,17 @@ extension EntitiesDB on FilesDB {
return LocalEntityData.fromJson(maps[i]);
});
}
+
+ Future<LocalEntityData?> getEntity(EntityType type, String id) async {
+ final db = await database;
+ final List<Map<String, dynamic>> maps = await db.query(
+ "entities",
+ where: "type = ? AND id = ?",
+ whereArgs: [type.typeToString(), id],
+ );
+ if (maps.isEmpty) {
+ return null;
+ }
+ return LocalEntityData.fromJson(maps.first);
+ }
}
diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart
index a96f962604..617d81bdb8 100644
--- a/mobile/lib/face/db.dart
+++ b/mobile/lib/face/db.dart
@@ -207,24 +207,16 @@ class FaceMLDataDB {
Future<Face?> getCoverFaceForPerson({
required int recentFileID,
String? personID,
+ String? personAvatorFaceID,
int? clusterID,
}) async {
// read person from db
final db = await instance.database;
if (personID != null) {
- final List<Map<String, dynamic>> maps = await db.rawQuery(
- 'SELECT * FROM $personTable where $idColumn = ?',
- [personID],
- );
- if (maps.isEmpty) {
- throw Exception("Person with id $personID not found");
- }
-
- final person = mapRowToPerson(maps.first);
final List<int> fileId = [recentFileID];
int? avatarFileId;
- if (person.data.avatarFaceId != null) {
- avatarFileId = int.tryParse(person.data.avatarFaceId!.split('_')[0]);
+ if (personAvatorFaceID != null) {
+ avatarFileId = int.tryParse(personAvatorFaceID!.split('_')[0]);
if (avatarFileId != null) {
fileId.add(avatarFileId);
}
diff --git a/mobile/lib/services/entity_service.dart b/mobile/lib/services/entity_service.dart
index 29bb085278..6319f9e8ec 100644
--- a/mobile/lib/services/entity_service.dart
+++ b/mobile/lib/services/entity_service.dart
@@ -50,6 +50,10 @@ class EntityService {
return await _db.getEntities(type);
}
+ Future<LocalEntityData?> getEntity(EntityType type, String id) async {
+ return await _db.getEntity(type, id);
+ }
+
Future<LocalEntityData> addOrUpdate(
EntityType type,
String plainText, {
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 59f418273d..811eec3ac6 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
@@ -37,6 +37,15 @@ class PersonService {
.toList();
}
+ Future<PersonEntity?> getPerson(String id) {
+ return entityService.getEntity(EntityType.person, id).then((e) {
+ if (e == null) {
+ return null;
+ }
+ return PersonEntity(e.id, PersonData.fromJson(json.decode(e.data)));
+ });
+ }
+
Future<Map<String, PersonEntity>> getPersonsMap() async {
final entities = await entityService.getEntities(EntityType.person);
final Map<String, PersonEntity> map = {};
diff --git a/mobile/lib/ui/viewer/search/result/person_face_widget.dart b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
index 832f4abb3b..d0ee35e8e2 100644
--- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
@@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';
import "package:photos/db/files_db.dart";
import "package:photos/face/db.dart";
import "package:photos/face/model/face.dart";
+import "package:photos/face/model/person.dart";
import 'package:photos/models/file/file.dart';
+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
import "package:photos/utils/face/face_box_crop.dart";
@@ -81,8 +83,17 @@ class PersonFaceWidget extends StatelessWidget {
}
Future<Face?> _getFace() async {
+ String? personAvatarFaceID;
+ if (personId != null) {
+ PersonEntity? personEntity =
+ await PersonService.instance.getPerson(personId!);
+ if (personEntity != null) {
+ personAvatarFaceID = personEntity.data.avatarFaceId;
+ }
+ }
return await FaceMLDataDB.instance.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
+ personAvatorFaceID: personAvatarFaceID,
personID: personId,
clusterID: clusterID,
);