fix: join public room

This commit is contained in:
Christian Pauly 2020-12-06 14:54:58 +01:00
parent 36c8a8b195
commit 30883e57a2

View File

@ -66,15 +66,22 @@ class _DiscoverPageState extends State<DiscoverPage> {
}); });
} }
Future<String> _joinRoomAndWait(BuildContext context, String roomId) async { Future<String> _joinRoomAndWait(
final newRoomId = await Matrix.of(context).client.joinRoomOrAlias(roomId); BuildContext context,
if (Matrix.of(context).client.getRoomById(newRoomId) == null) { 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) await Matrix.of(context)
.client .client
.onRoomUpdate .onRoomUpdate
.stream .stream
.firstWhere((r) => r.id == newRoomId); .firstWhere((r) => r.id == newRoomId);
}
return newRoomId; return newRoomId;
} }
@ -88,8 +95,13 @@ class _DiscoverPageState extends State<DiscoverPage> {
OkCancelResult.cancel) { OkCancelResult.cancel) {
return; return;
} }
final success = await SimpleDialogs(context) final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
.tryRequestWithLoadingDialog(_joinRoomAndWait(context, room.roomId)); _joinRoomAndWait(
context,
room.roomId,
room.canonicalAlias ?? room.aliases.first,
),
);
if (success != false) { if (success != false) {
await Navigator.of(context).push( await Navigator.of(context).push(
AppRoute.defaultRoute( AppRoute.defaultRoute(