From 55c7a8b49494b904332f3d963fec94b2f2ebf3c2 Mon Sep 17 00:00:00 2001 From: gravel Date: Wed, 20 Dec 2023 17:27:33 +0000 Subject: [PATCH] fix: prefer expected join link for pubkey --- php/servers/servers-rooms.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index 55f7865..08e06d6 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -353,13 +353,22 @@ return "$base_url/r/$token/invite.png"; } + /** + * Return a string used to match the in-app join URL for this room. + */ + function _get_join_url_match(): string { + $hostname = $this->server->get_hostname(include_port: true); + $token = $this->token; + return "$hostname/$token?public_key="; + } + /** * Return the in-app join URL for this room. */ function get_join_url(): string { $base_url = $this->server->base_url; - $pubkey = $this->server->get_pubkey(); $token = $this->token; + $pubkey = $this->server->get_pubkey(); return "$base_url/$token?public_key=$pubkey"; } @@ -1351,10 +1360,12 @@ } // This is ugly. 'RoomBuilder' would be better. - $preview_url = CommunityRoom::_from_intermediate_data( + $room_intermediate = CommunityRoom::_from_intermediate_data( $this, $this->_intermediate_room_data[0] - )->get_preview_url(); + ); + + $preview_url = $room_intermediate->get_preview_url(); log_info("Fetching pubkey from $preview_url"); $room_view_response = yield from FetchingCoroutine @@ -1372,7 +1383,11 @@ } $links = parse_join_links($room_view); - $link = $links[0]; + + $join_link_part = $room_intermediate->_get_join_url_match(); + $link = array_values(array_filter($links, function (string $link) use ($join_link_part) { + return str_contains($link, $join_link_part); + }))[0] ?? $links[0]; if (!isset($link)) { log_debug("Could not locate join link in preview at $preview_url.");