feat: Enable E2EE by default for new rooms

This commit is contained in:
Krille Fear 2021-10-10 10:43:50 +02:00
parent d75b538923
commit 92523cb7b0
3 changed files with 37 additions and 17 deletions

View file

@ -17,19 +17,29 @@ class NewGroupController extends State<NewGroup> {
void setPublicGroup(bool b) => setState(() => publicGroup = b);
void submitAction([_]) async {
final matrix = Matrix.of(context);
final client = Matrix.of(context).client;
final roomID = await showFutureLoadingDialog(
context: context,
future: () => matrix.client.createRoom(
preset: publicGroup
? sdk.CreateRoomPreset.publicChat
: sdk.CreateRoomPreset.privateChat,
visibility: publicGroup ? sdk.Visibility.public : null,
roomAliasName: publicGroup && controller.text.isNotEmpty
? controller.text.trim().toLowerCase().replaceAll(' ', '_')
: null,
name: controller.text.isNotEmpty ? controller.text : null,
),
future: () async {
final roomId = await client.createRoom(
preset: publicGroup
? sdk.CreateRoomPreset.publicChat
: sdk.CreateRoomPreset.privateChat,
visibility: publicGroup ? sdk.Visibility.public : null,
roomAliasName: publicGroup && controller.text.isNotEmpty
? controller.text.trim().toLowerCase().replaceAll(' ', '_')
: null,
name: controller.text.isNotEmpty ? controller.text : null,
);
if (client.getRoomById(roomId) == null) {
await client.onSync.stream.firstWhere(
(sync) => sync.rooms?.join?.containsKey(roomId) ?? false);
}
if (!publicGroup && client.encryptionEnabled) {
await client.getRoomById(roomId).enableEncryption();
}
return roomId;
},
);
if (roomID.error == null) {
VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);

View file

@ -48,7 +48,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
static Future<FamedlySdkHiveDatabase> hiveDatabaseBuilder(
Client client) async {
if (!kIsWeb && !_hiveInitialized) {
Logs().i('Init Hive database...');
_hiveInitialized = true;
}
HiveCipher hiverCipher;
@ -81,7 +80,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
client.clientName,
encryptionCipher: hiverCipher,
);
Logs().i('Open Hive database...');
try {
await db.open();
} catch (e, s) {
@ -89,7 +87,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
await db.clear(client.id);
await db.open();
}
Logs().i('Hive database is ready!');
return db;
}

View file

@ -20,9 +20,20 @@ class ProfileBottomSheet extends StatelessWidget {
}) : super(key: key);
void _startDirectChat(BuildContext context) async {
final client = Matrix.of(context).client;
final result = await showFutureLoadingDialog<String>(
context: context,
future: () => Matrix.of(context).client.startDirectChat(userId),
future: () async {
final roomId = await client.startDirectChat(userId);
if (client.getRoomById(roomId) == null) {
await client.onSync.stream.firstWhere(
(sync) => sync.rooms?.join?.containsKey(roomId) ?? false);
}
if (client.encryptionEnabled) {
await client.getRoomById(roomId).enableEncryption();
}
return roomId;
},
);
if (result.error == null) {
VRouter.of(context).toSegments(['rooms', result.result]);
@ -81,8 +92,10 @@ class ProfileBottomSheet extends StatelessWidget {
subtitle: Text(userId),
trailing: Icon(Icons.account_box_outlined),
),
Center(
child: FloatingActionButton.extended(
Container(
width: double.infinity,
padding: EdgeInsets.all(12),
child: ElevatedButton.icon(
onPressed: () => _startDirectChat(context),
label: Text(L10n.of(context).newChat),
icon: Icon(Icons.send_outlined),