From ed570a6e1efed3e9fbd128664f5ff9e81d2f69d7 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 19 Jan 2021 18:09:58 +0100 Subject: [PATCH] fix: Allow joining of unpublished aliases again --- lib/utils/url_launcher.dart | 26 +++++++------------------- lib/views/discover_view.dart | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/utils/url_launcher.dart b/lib/utils/url_launcher.dart index e00e5f09..18ea09ac 100644 --- a/lib/utils/url_launcher.dart +++ b/lib/utils/url_launcher.dart @@ -35,7 +35,6 @@ class UrlLauncher { // we got a room! Let's open that one final roomIdOrAlias = identityParts.primaryIdentifier; final event = identityParts.secondaryIdentifier; - final query = identityParts.queryString; var room = matrix.client.getRoomByAlias(roomIdOrAlias) ?? matrix.client.getRoomById(roomIdOrAlias); var roomId = room?.id; @@ -49,26 +48,15 @@ class UrlLauncher { future: () => matrix.client.requestRoomAliasInformations(roomIdOrAlias), ); - if (response.error == null) { - roomId = response.result.roomId; - servers.addAll(response.result.servers); - room = matrix.client.getRoomById(roomId); + if (response.error != null) { + return; // nothing to do, the alias doesn't exist } + roomId = response.result.roomId; + servers.addAll(response.result.servers); + room = matrix.client.getRoomById(roomId); } - if (query != null) { - // the query information might hold additional servers to try, so let's try them! - // as there might be multiple "via" tags we can't just use Uri.splitQueryString, we need to do our own thing - for (final parameter in query.split('&')) { - final index = parameter.indexOf('='); - if (index == -1) { - continue; - } - if (Uri.decodeQueryComponent(parameter.substring(0, index)) != - 'via') { - continue; - } - servers.add(Uri.decodeQueryComponent(parameter.substring(index + 1))); - } + if (identityParts.via != null) { + servers.addAll(identityParts.via); } if (room != null) { // we have the room, so....just open it! diff --git a/lib/views/discover_view.dart b/lib/views/discover_view.dart index 78e1fc8d..65444ade 100644 --- a/lib/views/discover_view.dart +++ b/lib/views/discover_view.dart @@ -116,10 +116,25 @@ class _DiscoverPageState extends State { final server = _genericSearchTerm?.isValidMatrixId ?? false ? _genericSearchTerm.domain : _server; - _publicRoomsResponse ??= Matrix.of(context).client.searchPublicRooms( + _publicRoomsResponse ??= Matrix.of(context) + .client + .searchPublicRooms( server: server, genericSearchTerm: _genericSearchTerm, - ); + ) + .then((PublicRoomsResponse res) { + if (widget.alias != null && + !res.chunk.any((room) => + room.aliases.contains(widget.alias) || + room.canonicalAlias == widget.alias)) { + // we have to tack on the original alias + res.chunk.add(PublicRoom.fromJson({ + 'aliases': [widget.alias], + 'name': widget.alias, + })); + } + return res; + }); return Scaffold( appBar: AppBar( leading: BackButton(),