From 30883e57a2ad3d96068acc679f6c62e189899093 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 6 Dec 2020 14:54:58 +0100 Subject: [PATCH] fix: join public room --- lib/views/discover_view.dart | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/views/discover_view.dart b/lib/views/discover_view.dart index 4aace497..ae525f01 100644 --- a/lib/views/discover_view.dart +++ b/lib/views/discover_view.dart @@ -66,15 +66,22 @@ class _DiscoverPageState extends State { }); } - Future _joinRoomAndWait(BuildContext context, String roomId) async { - final newRoomId = await Matrix.of(context).client.joinRoomOrAlias(roomId); - if (Matrix.of(context).client.getRoomById(newRoomId) == null) { - await Matrix.of(context) - .client - .onRoomUpdate - .stream - .firstWhere((r) => r.id == newRoomId); + Future _joinRoomAndWait( + BuildContext context, + String roomId, + String alias, + ) async { + if (Matrix.of(context).client.getRoomById(roomId) != null) { + return roomId; } + final newRoomId = await Matrix.of(context) + .client + .joinRoomOrAlias(alias?.isNotEmpty ?? false ? alias : roomId); + await Matrix.of(context) + .client + .onRoomUpdate + .stream + .firstWhere((r) => r.id == newRoomId); return newRoomId; } @@ -88,8 +95,13 @@ class _DiscoverPageState extends State { OkCancelResult.cancel) { return; } - final success = await SimpleDialogs(context) - .tryRequestWithLoadingDialog(_joinRoomAndWait(context, room.roomId)); + final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( + _joinRoomAndWait( + context, + room.roomId, + room.canonicalAlias ?? room.aliases.first, + ), + ); if (success != false) { await Navigator.of(context).push( AppRoute.defaultRoute(