diff --git a/output/js/util.js b/output/js/util.js index dc17f51..d5d4152 100644 --- a/output/js/util.js +++ b/output/js/util.js @@ -11,12 +11,13 @@ class _RoomInfo { const response = await fetch(this.ROOMS_ENDPOINT); const servers = await response.json(); for (const server of servers) { + const { server_id } = server; for (const room of server.rooms) { - const identifier = `${room.token}+${server.pubkey.slice(0, 4)}`; - this.rooms[identifier] = {...room, server_key: server.pubkey}; + const identifier = `${room.token}+${server_id}`; + this.rooms[identifier] = {...room, server_id}; } delete server.rooms; - this.servers[server.pubkey] = server; + this.servers[server_id] = server; } } @@ -44,7 +45,7 @@ class _RoomInfo { */ static getRoomServer(identifier) { this.assertRoomExists(identifier); - return this.servers[this.rooms[identifier].server_key]; + return this.servers[this.rooms[identifier].server_id]; } } export class RoomInfo { diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index 08e06d6..7712c55 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -897,6 +897,7 @@ unset($details['merge_error']); unset($details['pubkey_candidates']); $details['pubkey'] = $this->get_pubkey(); + $details['server_id'] = $this->get_server_id(); return $details; } @@ -1155,6 +1156,15 @@ return count($this->pubkey_candidates) == 1; } + /** + * Returns an ID based on the server URL and public key. + */ + public function get_server_id(): string { + $pubkey_prefix = substr($this->get_pubkey(), 0, 4); + $hostname_hash_prefix = substr(md5($this->get_hostname(include_port: true)), 0, 4); + return $pubkey_prefix . $hostname_hash_prefix; + } + /** * Returns the room of the given token, or null if one does not exist. */