π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][contacts] add contact lookups for photos integration
Neeraj Gupta07632bfc88ae
diff --git a/mobile/packages/contacts/lib/src/db/contacts_database.dart b/mobile/packages/contacts/lib/src/db/contacts_database.dartindex 3ad51c8373..67712412b6 100644--- a/mobile/packages/contacts/lib/src/db/contacts_database.dart+++ b/mobile/packages/contacts/lib/src/db/contacts_database.dart@@ -92,6 +92,25 @@ class ContactsDatabase {return _fromRow(rows.first);}+ Future<ContactRecord?> getContactByUserId(+ int contactUserId, {+ bool includeDeleted = false,+ }) async {+ final db = await database;+ final rows = await db.query(+ _contactsTable,+ where: includeDeleted+ ? 'contact_user_id = ?'+ : 'contact_user_id = ? AND is_deleted = 0',+ whereArgs: [contactUserId],+ limit: 1,+ );+ if (rows.isEmpty) {+ return null;+ }+ return _fromRow(rows.first);+ }+Future<List<ContactRecord>> getContacts({bool includeDeleted = false}) async {final db = await database;final rows = await db.query(diff --git a/mobile/packages/contacts/lib/src/service/contacts_service.dart b/mobile/packages/contacts/lib/src/service/contacts_service.dartindex c624e008eb..6dc2cd11e2 100644--- a/mobile/packages/contacts/lib/src/service/contacts_service.dart+++ b/mobile/packages/contacts/lib/src/service/contacts_service.dart@@ -96,6 +96,16 @@ class ContactsService {return _database.getContact(contactId);}+ Future<ContactRecord?> getContactByUserId(+ int contactUserId, {+ bool includeDeleted = false,+ }) {+ return _database.getContactByUserId(+ contactUserId,+ includeDeleted: includeDeleted,+ );+ }+Future<ContactRecord> createContact(ContactData data) async {final created = await _requireCtx().createContact(data);await _database.upsertContacts([created]);diff --git a/mobile/packages/contacts/test/contacts_database_test.dart b/mobile/packages/contacts/test/contacts_database_test.dartindex 99c7c209af..686b6006a0 100644--- a/mobile/packages/contacts/test/contacts_database_test.dart+++ b/mobile/packages/contacts/test/contacts_database_test.dart@@ -47,6 +47,7 @@ void main() {await database.configure(userId: 1);expect((await database.getContacts()).single.id, 'ct_1');expect((await database.getContacts()).single.email, '[email protected]');+ expect((await database.getContactByUserId(200))?.id, 'ct_1');});test('clearTable removes all contacts databases', () async {diff --git a/mobile/packages/contacts/test/contacts_service_test.dart b/mobile/packages/contacts/test/contacts_service_test.dartindex 60979be0de..27c57525a6 100644--- a/mobile/packages/contacts/test/contacts_service_test.dart+++ b/mobile/packages/contacts/test/contacts_service_test.dart@@ -96,6 +96,7 @@ void main() {const ContactData(contactUserId: 2, name: 'B'),);expect((await service.getContact(created.id))!.data!.name, 'B');+ expect((await service.getContactByUserId(2))!.id, created.id);final updated = await service.setProfilePicture(created.id,@@ -121,6 +122,26 @@ void main() {expect(await database.getCachedAttachment('att_profile'), isNull);});+ test('getContactByUserId resolves cached contact without scanning all rows',+ () async {+ await service.open(+ ContactsSession(+ baseUrl: 'http://localhost:8080',+ authToken: 'token',+ userId: 1,+ accountKey: Uint8List.fromList([1, 2, 3]),+ ),+ );++ final created = await service.createContact(+ const ContactData(contactUserId: 42, name: 'Douglas'),+ );++ final cached = await service.getContactByUserId(42);+ expect(cached?.id, created.id);+ expect(cached?.data?.name, 'Douglas');+ });+test('open can resolve account key from provider', () async {await service.open(ContactsSession(