diff --git a/lib/pages/new_group.dart b/lib/pages/new_group.dart index 3fa0cc4a..7c074b56 100644 --- a/lib/pages/new_group.dart +++ b/lib/pages/new_group.dart @@ -17,19 +17,29 @@ class NewGroupController extends State { 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']); diff --git a/lib/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart b/lib/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart index 3e04000c..acf8cb19 100644 --- a/lib/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart +++ b/lib/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart @@ -48,7 +48,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase { static Future 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; } diff --git a/lib/widgets/profile_bottom_sheet.dart b/lib/widgets/profile_bottom_sheet.dart index 5e12cbfb..11c7a176 100644 --- a/lib/widgets/profile_bottom_sheet.dart +++ b/lib/widgets/profile_bottom_sheet.dart @@ -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( 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),