refactor: sdk 1.0

This commit is contained in:
Christian Kußowski 2025-06-01 17:12:25 +02:00
commit e548d8f895
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
23 changed files with 1775 additions and 175 deletions

View file

@ -25,7 +25,7 @@ extension ClientDownloadContentExtension on Client {
)
: mxc;
final cachedData = await database?.getFile(cacheKey);
final cachedData = await database.getFile(cacheKey);
if (cachedData != null) return cachedData;
final httpUri = isThumbnail
@ -55,7 +55,7 @@ extension ClientDownloadContentExtension on Client {
}
}
await database?.storeFile(cacheKey, imageData, 0);
await database.storeFile(cacheKey, imageData, 0);
return imageData;
}

View file

@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:collection/collection.dart';
import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_vodozemac/flutter_vodozemac.dart' as vod;
import 'package:hive_flutter/hive_flutter.dart';
import 'package:matrix/encryption/utils/key_verification.dart';
import 'package:matrix/matrix.dart';
@ -46,7 +47,7 @@ abstract class ClientManager {
await store.setStringList(clientNamespace, clientNames.toList());
}
final clients =
clientNames.map((name) => createClient(name, store)).toList();
await Future.wait(clientNames.map((name) => createClient(name, store)));
if (initialize) {
await Future.wait(
clients.map(
@ -98,9 +99,15 @@ abstract class ClientManager {
static NativeImplementations get nativeImplementations => kIsWeb
? const NativeImplementationsDummy()
: NativeImplementationsIsolate(compute);
: NativeImplementationsIsolate(
compute,
vodozemacInit: vod.init,
);
static Client createClient(String clientName, SharedPreferences store) {
static Future<Client> createClient(
String clientName,
SharedPreferences store,
) async {
final shareKeysWith = AppSettings.shareKeysWith.getItem(store);
final enableSoftLogout = AppSettings.enableSoftLogout.getItem(store);
@ -118,7 +125,7 @@ abstract class ClientManager {
'im.ponies.room_emotes',
},
logLevel: kReleaseMode ? Level.warning : Level.verbose,
databaseBuilder: flutterMatrixSdkDatabaseBuilder,
database: await flutterMatrixSdkDatabaseBuilder(clientName),
supportedLoginTypes: {
AuthenticationTypes.password,
AuthenticationTypes.sso,

View file

@ -32,11 +32,11 @@ extension LocalizedBody on Event {
bool get isAttachmentSmallEnough =>
infoMap['size'] is int &&
infoMap['size'] < room.client.database!.maxFileSize;
infoMap['size'] < room.client.database.maxFileSize;
bool get isThumbnailSmallEnough =>
thumbnailInfoMap['size'] is int &&
thumbnailInfoMap['size'] < room.client.database!.maxFileSize;
thumbnailInfoMap['size'] < room.client.database.maxFileSize;
bool get showThumbnail =>
[MessageTypes.Image, MessageTypes.Sticker, MessageTypes.Video]

View file

@ -17,10 +17,10 @@ import 'cipher.dart';
import 'sqlcipher_stub.dart'
if (dart.library.io) 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(String clientName) async {
MatrixSdkDatabase? database;
try {
database = await _constructDatabase(client);
database = await _constructDatabase(clientName);
await database.open();
return database;
} catch (e, s) {
@ -36,7 +36,7 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
// Delete database file:
if (database == null && !kIsWeb) {
final dbFile = File(await _getDatabasePath(client.clientName));
final dbFile = File(await _getDatabasePath(clientName));
if (await dbFile.exists()) await dbFile.delete();
}
@ -58,10 +58,10 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
}
}
Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
Future<MatrixSdkDatabase> _constructDatabase(String clientName) async {
if (kIsWeb) {
html.window.navigator.storage?.persist();
return MatrixSdkDatabase(client.clientName);
return await MatrixSdkDatabase.init(clientName);
}
final cipher = await getDatabaseCipher();
@ -75,7 +75,7 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
);
}
final path = await _getDatabasePath(client.clientName);
final path = await _getDatabasePath(clientName);
// fix dlopen for old Android
await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
@ -84,7 +84,7 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
createDatabaseFactoryFfi(ffiInit: SQfLiteEncryptionHelper.ffiInit);
// migrate from potential previous SQLite database path to current one
await _migrateLegacyLocation(path, client.clientName);
await _migrateLegacyLocation(path, clientName);
// required for [getDatabasesPath]
databaseFactory = factory;
@ -111,8 +111,8 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
),
);
return MatrixSdkDatabase(
client.clientName,
return await MatrixSdkDatabase.init(
clientName,
database: database,
maxFileSize: 1000 * 1000 * 10,
fileStorageLocation: fileStorageLocation?.uri,