mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-28 17:12:33 +01:00
refactor: Rename store and allow storing custom values
This commit is contained in:
parent
2fe1dcf03f
commit
b1c35e5e1c
@ -18,7 +18,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'utils/matrix_sdk_extensions.dart/flutter_famedly_sdk_hive_database.dart';
|
||||
import 'utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart';
|
||||
import 'widgets/layouts/wait_for_login.dart';
|
||||
import 'widgets/lock_screen.dart';
|
||||
import 'widgets/matrix.dart';
|
||||
@ -46,7 +46,7 @@ void main() async {
|
||||
importantStateEvents: <String>{
|
||||
'im.ponies.room_emotes', // we want emotes to work properly
|
||||
},
|
||||
databaseBuilder: FlutterFamedlySdkHiveDatabase.hiveDatabaseBuilder,
|
||||
databaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
|
||||
supportedLoginTypes: {
|
||||
AuthenticationTypes.password,
|
||||
if (PlatformInfos.isMobile || PlatformInfos.isWeb) AuthenticationTypes.sso
|
||||
|
@ -12,16 +12,39 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../platform_infos.dart';
|
||||
|
||||
class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
||||
FlutterFamedlySdkHiveDatabase(String name, {HiveCipher encryptionCipher})
|
||||
class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
|
||||
FlutterMatrixHiveStore(String name, {HiveCipher encryptionCipher})
|
||||
: super(
|
||||
name,
|
||||
encryptionCipher: encryptionCipher,
|
||||
);
|
||||
|
||||
Box _customBox;
|
||||
String get _customBoxName => '$name.box.custom';
|
||||
|
||||
static bool _hiveInitialized = false;
|
||||
static const String _hiveCipherStorageKey = 'hive_encryption_key';
|
||||
|
||||
@override
|
||||
Future<void> open() async {
|
||||
await super.open();
|
||||
_customBox = await Hive.openBox(
|
||||
_customBoxName,
|
||||
encryptionCipher: encryptionCipher,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(int clientId) async {
|
||||
await super.clear(clientId);
|
||||
await _customBox.deleteAll(_customBox.keys);
|
||||
await _customBox.close();
|
||||
}
|
||||
|
||||
dynamic get(dynamic key) => _customBox.get(key);
|
||||
Future<void> put(dynamic key, dynamic value) => _customBox.put(key, value);
|
||||
|
||||
static Future<FamedlySdkHiveDatabase> hiveDatabaseBuilder(
|
||||
Client client) async {
|
||||
if (!kIsWeb && !_hiveInitialized) {
|
||||
@ -59,7 +82,7 @@ class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
||||
} on MissingPluginException catch (_) {
|
||||
Logs().i('Hive encryption is not supported on this platform');
|
||||
}
|
||||
final db = FlutterFamedlySdkHiveDatabase(
|
||||
final db = FlutterMatrixHiveStore(
|
||||
client.clientName,
|
||||
encryptionCipher: hiverCipher,
|
||||
);
|
||||
@ -107,9 +130,4 @@ class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
||||
await file.writeAsBytes(bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(int clientId) async {
|
||||
await super.clear(clientId);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_famedly_sdk_hive_database.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart';
|
||||
import 'package:matrix/encryption/utils/key_verification.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix_api_lite/fake_matrix_api.dart';
|
||||
@ -19,7 +19,7 @@ Future<Client> prepareTestClient({
|
||||
importantStateEvents: <String>{
|
||||
'im.ponies.room_emotes', // we want emotes to work properly
|
||||
},
|
||||
databaseBuilder: FlutterFamedlySdkHiveDatabase.hiveDatabaseBuilder,
|
||||
databaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
|
||||
supportedLoginTypes: {
|
||||
AuthenticationTypes.password,
|
||||
AuthenticationTypes.sso
|
||||
|
Loading…
Reference in New Issue
Block a user