mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-24 02:54:13 +01:00
chore: Update matrix sdk
This commit is contained in:
parent
893d7fa4c9
commit
af60376479
@ -12,7 +12,6 @@ import 'package:fluffychat/utils/custom_image_resizer.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_hive_collections_database.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'famedlysdk_store.dart';
|
||||
import 'matrix_sdk_extensions.dart/fluffybox_database.dart';
|
||||
|
||||
abstract class ClientManager {
|
||||
static const String clientNamespace = 'im.fluffychat.store.clients';
|
||||
@ -105,7 +104,6 @@ abstract class ClientManager {
|
||||
},
|
||||
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
||||
databaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder,
|
||||
legacyDatabaseBuilder: FlutterFluffyBoxDatabase.databaseBuilder,
|
||||
supportedLoginTypes: {
|
||||
AuthenticationTypes.password,
|
||||
if (PlatformInfos.isMobile ||
|
||||
|
@ -1,151 +0,0 @@
|
||||
// ignore_for_file: depend_on_referenced_packages
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart' hide Key;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:fluffybox/hive.dart' as fluffybox;
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../client_manager.dart';
|
||||
import '../famedlysdk_store.dart';
|
||||
|
||||
// ignore: deprecated_member_use
|
||||
class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
|
||||
FlutterFluffyBoxDatabase(
|
||||
String name,
|
||||
String path, {
|
||||
fluffybox.HiveCipher? key,
|
||||
}) : super(
|
||||
name,
|
||||
path,
|
||||
key: key,
|
||||
);
|
||||
|
||||
static const String _cipherStorageKey = 'database_encryption_key';
|
||||
|
||||
// ignore: deprecated_member_use
|
||||
static Future<FluffyBoxDatabase> databaseBuilder(Client client) async {
|
||||
Logs().d('Open FluffyBox...');
|
||||
fluffybox.HiveAesCipher? hiverCipher;
|
||||
try {
|
||||
// Workaround for secure storage is calling Platform.operatingSystem on web
|
||||
if (kIsWeb) throw MissingPluginException();
|
||||
|
||||
const secureStorage = FlutterSecureStorage();
|
||||
final containsEncryptionKey =
|
||||
await secureStorage.read(key: _cipherStorageKey) != null;
|
||||
if (!containsEncryptionKey) {
|
||||
// do not try to create a buggy secure storage for new Linux users
|
||||
if (Platform.isLinux) throw MissingPluginException();
|
||||
final key = Hive.generateSecureKey();
|
||||
await secureStorage.write(
|
||||
key: _cipherStorageKey,
|
||||
value: base64UrlEncode(key),
|
||||
);
|
||||
}
|
||||
|
||||
// workaround for if we just wrote to the key and it still doesn't exist
|
||||
final rawEncryptionKey = await secureStorage.read(key: _cipherStorageKey);
|
||||
if (rawEncryptionKey == null) throw MissingPluginException();
|
||||
|
||||
hiverCipher = fluffybox.HiveAesCipher(base64Url.decode(rawEncryptionKey));
|
||||
} on MissingPluginException catch (_) {
|
||||
Logs().i('FluffyBox encryption is not supported on this platform');
|
||||
} catch (e, s) {
|
||||
const FlutterSecureStorage()
|
||||
.delete(key: _cipherStorageKey)
|
||||
.catchError((_) {});
|
||||
Logs().w('Unable to init FluffyBox encryption', e, s);
|
||||
}
|
||||
|
||||
// ignore: deprecated_member_use
|
||||
final db = FluffyBoxDatabase(
|
||||
'fluffybox_${client.clientName.replaceAll(' ', '_').toLowerCase()}',
|
||||
await _findDatabasePath(client),
|
||||
key: hiverCipher,
|
||||
);
|
||||
try {
|
||||
await db.open();
|
||||
} catch (_) {
|
||||
Logs().w('Unable to open FluffyBox. Delete database and storage key...');
|
||||
await Store().deleteItem(ClientManager.clientNamespace);
|
||||
const FlutterSecureStorage().delete(key: _cipherStorageKey);
|
||||
await db.clear();
|
||||
rethrow;
|
||||
}
|
||||
Logs().d('FluffyBox is ready');
|
||||
return db;
|
||||
}
|
||||
|
||||
static Future<String> _findDatabasePath(Client client) async {
|
||||
String path = client.clientName;
|
||||
if (!kIsWeb) {
|
||||
Directory directory;
|
||||
try {
|
||||
if (Platform.isLinux) {
|
||||
directory = await getApplicationSupportDirectory();
|
||||
} else {
|
||||
directory = await getApplicationDocumentsDirectory();
|
||||
}
|
||||
} catch (_) {
|
||||
try {
|
||||
directory = await getLibraryDirectory();
|
||||
} catch (_) {
|
||||
directory = Directory.current;
|
||||
}
|
||||
}
|
||||
// do not destroy your stable FluffyChat in debug mode
|
||||
if (kDebugMode) {
|
||||
directory = Directory(directory.uri.resolve('debug').toFilePath());
|
||||
directory.create(recursive: true);
|
||||
}
|
||||
path = directory.path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@override
|
||||
int get maxFileSize => supportsFileStoring ? 100 * 1024 * 1024 : 0;
|
||||
@override
|
||||
bool get supportsFileStoring => !kIsWeb;
|
||||
|
||||
Future<String> _getFileStoreDirectory() async {
|
||||
try {
|
||||
try {
|
||||
return (await getApplicationSupportDirectory()).path;
|
||||
} catch (_) {
|
||||
return (await getApplicationDocumentsDirectory()).path;
|
||||
}
|
||||
} catch (_) {
|
||||
return (await getDownloadsDirectory())!.path;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> getFile(Uri mxcUri) async {
|
||||
if (!supportsFileStoring) return null;
|
||||
final tempDirectory = await _getFileStoreDirectory();
|
||||
final file =
|
||||
File('$tempDirectory/${Uri.encodeComponent(mxcUri.toString())}');
|
||||
if (await file.exists() == false) return null;
|
||||
final bytes = await file.readAsBytes();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@override
|
||||
Future storeFile(Uri mxcUri, Uint8List bytes, int time) async {
|
||||
if (!supportsFileStoring) return null;
|
||||
final tempDirectory = await _getFileStoreDirectory();
|
||||
final file =
|
||||
File('$tempDirectory/${Uri.encodeComponent(mxcUri.toString())}');
|
||||
if (await file.exists()) return;
|
||||
await file.writeAsBytes(bytes);
|
||||
return;
|
||||
}
|
||||
}
|
11
pubspec.lock
11
pubspec.lock
@ -491,13 +491,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.8.1+3"
|
||||
fluffybox:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fluffybox
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -1040,14 +1033,14 @@ packages:
|
||||
name: matrix
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.14.1"
|
||||
version: "0.15.0"
|
||||
matrix_api_lite:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matrix_api_lite
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.7"
|
||||
version: "1.1.8"
|
||||
matrix_homeserver_recommendations:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -65,7 +65,7 @@ dependencies:
|
||||
latlong2: ^0.8.1
|
||||
localstorage: ^4.0.0+1
|
||||
lottie: ^1.2.2
|
||||
matrix: ^0.14.1
|
||||
matrix: ^0.15.0
|
||||
matrix_homeserver_recommendations: ^0.3.0
|
||||
matrix_link_text: ^1.0.2
|
||||
native_imaging: ^0.1.0
|
||||
|
Loading…
Reference in New Issue
Block a user