feat: Test FluffyBox store

This commit is contained in:
Krille Fear 2021-11-17 19:17:40 +01:00
parent d9263e775d
commit db013043a7
3 changed files with 38 additions and 24 deletions

View File

@ -5,8 +5,8 @@ import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:matrix/encryption/utils/key_verification.dart'; import 'package:matrix/encryption/utils/key_verification.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:sembast/sembast.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:sembast/sembast.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'famedlysdk_store.dart'; import 'famedlysdk_store.dart';
@ -80,7 +80,7 @@ abstract class ClientManager {
KeyVerificationMethod.emoji, KeyVerificationMethod.emoji,
}, },
importantStateEvents: <String>{'im.ponies.room_emotes'}, importantStateEvents: <String>{'im.ponies.room_emotes'},
databaseBuilder: FluffyBoxDatabase.databaseBuilder, databaseBuilder: FlutterFluffyBoxDatabase.databaseBuilder,
legacyDatabaseBuilder: FlutterMatrixSembastDatabase.databaseBuilder, legacyDatabaseBuilder: FlutterMatrixSembastDatabase.databaseBuilder,
supportedLoginTypes: { supportedLoginTypes: {
AuthenticationTypes.password, AuthenticationTypes.password,

View File

@ -3,27 +3,23 @@ import 'dart:typed_data';
import 'package:flutter/foundation.dart' hide Key; import 'package:flutter/foundation.dart' hide Key;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:idb_shim/idb_browser.dart';
import 'package:idb_shim/idb.dart' hide Event;
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:encrypt/encrypt.dart'; import 'package:encrypt/encrypt.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:idb_sqflite/idb_sqflite.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import '../platform_infos.dart'; import '../platform_infos.dart';
class FluffyBoxDatabase extends MatrixIndexedDatabase { class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
FluffyBoxDatabase( FlutterFluffyBoxDatabase(
String name, { String name, {
String path, String path,
IdbFactory dbFactory, Future<sqflite.Database> Function() openSqlDatabase,
}) : super( }) : super(
name, name,
path, openSqlDatabase: openSqlDatabase,
factory: dbFactory,
); );
static const String _cipherStorageKey = 'database_encryption_key'; static const String _cipherStorageKey = 'database_encryption_key';
@ -54,21 +50,17 @@ class FluffyBoxDatabase extends MatrixIndexedDatabase {
} }
final db = FluffyBoxDatabase( final db = FluffyBoxDatabase(
'FluffyBox-${client.clientName}', 'fluffybox_${client.clientName.replaceAll(' ', '_').toLowerCase()}',
path: await _findDatabasePath(client), openSqlDatabase: () => _openSqlDatabase(client),
dbFactory: factory,
); );
await db.open(); await db.open();
Logs().d('FluffyBox is ready'); Logs().d('FluffyBox is ready');
return db; return db;
} }
static IdbFactory get factory { static Future<sqflite.Database> _openSqlDatabase(Client client) async {
if (kIsWeb) return idbFactoryBrowser; final path = await _findDatabasePath(client);
if (Platform.isAndroid || Platform.isIOS) { return await sqflite.openDatabase(path);
return getIdbFactorySqflite(sqflite.databaseFactory);
}
return idbFactoryNative;
} }
static Future<String> _findDatabasePath(Client client) async { static Future<String> _findDatabasePath(Client client) async {
@ -84,7 +76,8 @@ class FluffyBoxDatabase extends MatrixIndexedDatabase {
directory = Directory.current; directory = Directory.current;
} }
} }
path = '${directory.path}${client.clientName}.db'; path =
'${directory.path}${client.clientName.replaceAll(' ', '-')}.sqflite';
} }
return path; return path;
} }

View File

@ -351,6 +351,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.2" version: "0.0.2"
fluffybox:
dependency: transitive
description:
name: fluffybox
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -782,7 +789,7 @@ packages:
description: description:
path: "." path: "."
ref: "krille/idb" ref: "krille/idb"
resolved-ref: "5996f6bb01ba1110c1f8fb84c39dd6bcf0d2900a" resolved-ref: aee9bbf8afd1114a25ad547822d2e3eda6c73c83
url: "https://gitlab.com/famedly/company/frontend/famedlysdk.git" url: "https://gitlab.com/famedly/company/frontend/famedlysdk.git"
source: git source: git
version: "0.7.0-nullsafety.6" version: "0.7.0-nullsafety.6"
@ -1317,7 +1324,14 @@ packages:
name: sqflite_common name: sqflite_common
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0+2" version: "2.0.1+1"
sqflite_common_ffi:
dependency: transitive
description:
name: sqflite_common_ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
sqflite_sqlcipher: sqflite_sqlcipher:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1325,6 +1339,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
sqlite3:
dependency: transitive
description:
name: sqlite3
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -1669,5 +1690,5 @@ packages:
source: hosted source: hosted
version: "3.1.0" version: "3.1.0"
sdks: sdks:
dart: ">=2.14.0 <3.0.0" dart: ">=2.14.4 <3.0.0"
flutter: ">=2.5.0" flutter: ">=2.5.0"