From 5705ebdaabb24942d8acb51497a22f92b1d0bd16 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Mon, 25 Oct 2021 11:51:38 +0200 Subject: [PATCH] fix: Enable E2EE by default in all start chat cases --- lib/pages/user_bottom_sheet.dart | 14 +++++++++++++- lib/pages/views/search_view.dart | 20 +++++++++++++++++--- pubspec.lock | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/pages/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet.dart index 40c33484..a534cd77 100644 --- a/lib/pages/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet.dart @@ -86,7 +86,19 @@ class UserBottomSheetController extends State { case 'message': final roomIdResult = await showFutureLoadingDialog( context: context, - future: () => widget.user.startDirectChat(), + future: () async { + final roomId = await widget.user.startDirectChat(); + final client = widget.user.room.client; + if (client.getRoomById(roomId) == null) { + await client.onSync.stream.firstWhere( + (sync) => sync.rooms?.join?.containsKey(roomId) ?? false); + } + final room = client.getRoomById(roomId); + if (client.encryptionEnabled && !room.encrypted) { + await client.getRoomById(roomId).enableEncryption(); + } + return roomId; + }, ); if (roomIdResult.error != null) return; VRouter.of(widget.outerContext) diff --git a/lib/pages/views/search_view.dart b/lib/pages/views/search_view.dart index 6dea7ab2..1d5956fa 100644 --- a/lib/pages/views/search_view.dart +++ b/lib/pages/views/search_view.dart @@ -247,9 +247,23 @@ class SearchView extends StatelessWidget { onTap: () async { final roomID = await showFutureLoadingDialog( context: context, - future: () => Matrix.of(context) - .client - .startDirectChat(foundProfile.userId), + future: () async { + final client = Matrix.of(context).client; + final roomId = await client + .startDirectChat(foundProfile.userId); + if (client.getRoomById(roomId) == null) { + await client.onSync.stream.firstWhere((sync) => + sync.rooms?.join?.containsKey(roomId) ?? + false); + } + final room = client.getRoomById(roomId); + if (client.encryptionEnabled && !room.encrypted) { + await client + .getRoomById(roomId) + .enableEncryption(); + } + return roomId; + }, ); if (roomID.error == null) { VRouter.of(context) diff --git a/pubspec.lock b/pubspec.lock index bd8228ed..d61f3c5b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -748,7 +748,7 @@ packages: name: matrix url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.6.2" matrix_api_lite: dependency: transitive description: