Introduce server ID

dev
gravel 1 year ago
parent e1b086f0b8
commit 9866d1dc91
Signed by: gravel
GPG Key ID: C0538F3C906B308F

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

@ -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.
*/

Loading…
Cancel
Save