π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Merge remote-tracking branch 'upstream/main' into codex/migrate-photos-sqlite-async
laurenspriem1ca28724fbc1
diff --cc mobile/apps/photos/lib/services/photos_contacts_service.dartindex f8f9c84935,8a76f94cec..b521b5b6ac--- a/mobile/apps/photos/lib/services/photos_contacts_service.dart+++ b/mobile/apps/photos/lib/services/photos_contacts_service.dart@@@ -151,27 -195,6 +195,8 @@@ class PhotosContactsService@visibleForTestingvoid debugReset({bool notify = false}) => _store.clearSession(notify: notify);+ Future<void> close() => _store.close();+- contacts.ContactsSession? _buildSession() {- final config = Configuration.instance;- final userId = config.getUserID();- final accountKey = config.getKey();- final token = config.getToken();- if (token == null || userId == null || accountKey == null) {- return null;- }- final packageInfo = ServiceLocator.instance.packageInfo;- return contacts.ContactsSession(- baseUrl: endpointConfig.endpoint,- authToken: token,- userId: userId,- accountKey: accountKey,- clientPackage: packageInfo.packageName,- clientVersion: packageInfo.version,- );- }-Future<T?> _runReadSafely<T>(Future<T?> Function() task, {required String description,diff --cc mobile/packages/contacts/lib/src/db/contacts_database.dartindex 5ca9ed50d8,9784f4ddc0..73ac5808b8--- a/mobile/packages/contacts/lib/src/db/contacts_database.dart+++ b/mobile/packages/contacts/lib/src/db/contacts_database.dart@@@ -3,11 -3,10 +3,10 @@@ import 'dart:convert'import 'dart:io';import 'dart:typed_data';- import 'package:ente_contacts/src/models/contact_data.dart';- import 'package:ente_contacts/src/models/contact_record.dart';+ import 'package:ente_frb/contacts.dart';import 'package:path/path.dart' as p;import 'package:path_provider/path_provider.dart';-import 'package:sqflite_common_ffi/sqflite_ffi.dart';+import 'package:sqlite_async/sqlite_async.dart';typedef ContactsDatabaseDirectoryResolver = Future<Directory> Function();@@@ -340,15 -307,4 +339,20 @@@ class ContactsDatabaseupdatedAt: row['updated_at']! as int,);}++ List<Object?> _contactParameters(ContactRecord contact) => [+ contact.id,+ contact.contactUserId,+ contact.email,- contact.data == null ? null : jsonEncode(contact.data!.toJson()),++ contact.name == null++ ? null++ : jsonEncode({++ 'contactUserId': contact.contactUserId,++ 'name': contact.name,++ }),+ contact.profilePictureAttachmentId,+ contact.isDeleted ? 1 : 0,+ contact.createdAt,+ contact.updatedAt,+ ];}diff --cc mobile/packages/contacts/lib/src/service/contacts_service.dartindex aa86e2b201,bd19c8e044..134cd0c64c--- a/mobile/packages/contacts/lib/src/service/contacts_service.dart+++ b/mobile/packages/contacts/lib/src/service/contacts_service.dart@@@ -269,12 -286,6 +286,12 @@@ class ContactsServiceawait _database.resetState();}+ Future<void> close() async {- _ctx = null;- _session = null;++ _userId = null;++ _wrappedRootContactKey = null;+ await _database.close();+ }+int _nextSyncCursor(List<ContactRecord> diff, int maxUpdatedAt, int limit) {if (diff.length < limit || maxUpdatedAt <= 0) {return maxUpdatedAt;diff --cc mobile/packages/contacts/pubspec.yamlindex 576874a4db,688b542687..b2b5b39e3a--- a/mobile/packages/contacts/pubspec.yaml+++ b/mobile/packages/contacts/pubspec.yaml@@@ -20,5 -22,5 +22,6 @@@ dev_dependenciesflutter_lints: 6.0.0flutter_test:sdk: flutter++ sqflite_common_ffi: 2.3.7+1flutter:diff --cc mobile/packages/contacts/test/contacts_database_test.dartindex 6b445e1d52,c6b72c6fb0..b4f37630b1--- a/mobile/packages/contacts/test/contacts_database_test.dart+++ b/mobile/packages/contacts/test/contacts_database_test.dart@@@ -48,6 -50,56 +50,58 @@@ void main()expect((await database.getContactByUserId(200))?.id, 'ct_1');});+ test('reads and updates contacts stored by older clients', () async {+ final oldDatabase = await databaseFactoryFfi.openDatabase(+ '${tempDir.path}/ente.contacts.1.db',+ options: OpenDatabaseOptions(+ version: 1,+ onCreate: (db, _) => db.execute('''+ CREATE TABLE contacts (+ id TEXT PRIMARY KEY,+ contact_user_id INTEGER NOT NULL,+ email TEXT,+ data_json TEXT,+ profile_picture_attachment_id TEXT,+ is_deleted INTEGER NOT NULL DEFAULT 0,+ created_at INTEGER NOT NULL,+ updated_at INTEGER NOT NULL+ )+ '''),+ ),+ );+ await oldDatabase.insert('contacts', {+ 'id': 'ct_old',+ 'contact_user_id': 200,+ 'email': '[email protected]',+ 'data_json': '{"contactUserId":200,"name":"A","birthDate":"2001-04-02"}',+ 'profile_picture_attachment_id': 'att_old',+ 'is_deleted': 0,+ 'created_at': 10,+ 'updated_at': 20,+ });+ await oldDatabase.close();++ await database.configure(userId: 1);+ final contact = (await database.getContact('ct_old'))!;+ expect(contact.name, 'A');+ expect(contact.profilePictureAttachmentId, 'att_old');+ await database.upsertContacts([contact]);+- final rows = await (await database.database).query('contacts');++ final rows = await (await database.database).getAll(++ 'SELECT * FROM contacts',++ );+ expect(rows.single, {+ 'id': 'ct_old',+ 'contact_user_id': 200,+ 'email': '[email protected]',+ 'data_json': '{"contactUserId":200,"name":"A"}',+ 'profile_picture_attachment_id': 'att_old',+ 'is_deleted': 0,+ 'created_at': 10,+ 'updated_at': 20,+ });+ });+test('clearTable removes all contacts databases', () async {await database.configure(userId: 1);await database.upsertContacts([