mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-18 15:00:41 +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:universal_html/html.dart' as html;
|
||||||
import 'package:vrouter/vrouter.dart';
|
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/layouts/wait_for_login.dart';
|
||||||
import 'widgets/lock_screen.dart';
|
import 'widgets/lock_screen.dart';
|
||||||
import 'widgets/matrix.dart';
|
import 'widgets/matrix.dart';
|
||||||
@ -46,7 +46,7 @@ void main() async {
|
|||||||
importantStateEvents: <String>{
|
importantStateEvents: <String>{
|
||||||
'im.ponies.room_emotes', // we want emotes to work properly
|
'im.ponies.room_emotes', // we want emotes to work properly
|
||||||
},
|
},
|
||||||
databaseBuilder: FlutterFamedlySdkHiveDatabase.hiveDatabaseBuilder,
|
databaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
|
||||||
supportedLoginTypes: {
|
supportedLoginTypes: {
|
||||||
AuthenticationTypes.password,
|
AuthenticationTypes.password,
|
||||||
if (PlatformInfos.isMobile || PlatformInfos.isWeb) AuthenticationTypes.sso
|
if (PlatformInfos.isMobile || PlatformInfos.isWeb) AuthenticationTypes.sso
|
||||||
|
@ -12,16 +12,39 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
|
|
||||||
import '../platform_infos.dart';
|
import '../platform_infos.dart';
|
||||||
|
|
||||||
class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
|
||||||
FlutterFamedlySdkHiveDatabase(String name, {HiveCipher encryptionCipher})
|
FlutterMatrixHiveStore(String name, {HiveCipher encryptionCipher})
|
||||||
: super(
|
: super(
|
||||||
name,
|
name,
|
||||||
encryptionCipher: encryptionCipher,
|
encryptionCipher: encryptionCipher,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Box _customBox;
|
||||||
|
String get _customBoxName => '$name.box.custom';
|
||||||
|
|
||||||
static bool _hiveInitialized = false;
|
static bool _hiveInitialized = false;
|
||||||
static const String _hiveCipherStorageKey = 'hive_encryption_key';
|
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(
|
static Future<FamedlySdkHiveDatabase> hiveDatabaseBuilder(
|
||||||
Client client) async {
|
Client client) async {
|
||||||
if (!kIsWeb && !_hiveInitialized) {
|
if (!kIsWeb && !_hiveInitialized) {
|
||||||
@ -59,7 +82,7 @@ class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
|||||||
} on MissingPluginException catch (_) {
|
} on MissingPluginException catch (_) {
|
||||||
Logs().i('Hive encryption is not supported on this platform');
|
Logs().i('Hive encryption is not supported on this platform');
|
||||||
}
|
}
|
||||||
final db = FlutterFamedlySdkHiveDatabase(
|
final db = FlutterMatrixHiveStore(
|
||||||
client.clientName,
|
client.clientName,
|
||||||
encryptionCipher: hiverCipher,
|
encryptionCipher: hiverCipher,
|
||||||
);
|
);
|
||||||
@ -107,9 +130,4 @@ class FlutterFamedlySdkHiveDatabase extends FamedlySdkHiveDatabase {
|
|||||||
await file.writeAsBytes(bytes);
|
await file.writeAsBytes(bytes);
|
||||||
return;
|
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/encryption/utils/key_verification.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:matrix_api_lite/fake_matrix_api.dart';
|
import 'package:matrix_api_lite/fake_matrix_api.dart';
|
||||||
@ -19,7 +19,7 @@ Future<Client> prepareTestClient({
|
|||||||
importantStateEvents: <String>{
|
importantStateEvents: <String>{
|
||||||
'im.ponies.room_emotes', // we want emotes to work properly
|
'im.ponies.room_emotes', // we want emotes to work properly
|
||||||
},
|
},
|
||||||
databaseBuilder: FlutterFamedlySdkHiveDatabase.hiveDatabaseBuilder,
|
databaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
|
||||||
supportedLoginTypes: {
|
supportedLoginTypes: {
|
||||||
AuthenticationTypes.password,
|
AuthenticationTypes.password,
|
||||||
AuthenticationTypes.sso
|
AuthenticationTypes.sso
|
||||||
|
Loading…
x
Reference in New Issue
Block a user