fix: Allow joining of unpublished aliases again

This commit is contained in:
Sorunome 2021-01-19 18:09:58 +01:00
parent 2c3c0dbdb2
commit ed570a6e1e
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 24 additions and 21 deletions

View File

@ -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!

View File

@ -116,10 +116,25 @@ class _DiscoverPageState extends State<DiscoverPage> {
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(<String, dynamic>{
'aliases': [widget.alias],
'name': widget.alias,
}));
}
return res;
});
return Scaffold(
appBar: AppBar(
leading: BackButton(),