diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index 89ac54d..8c003dd 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -1,5 +1,4 @@ $key, + $b->$key + ); + }); + } + + /** + * Sorts Community rooms in-place by their server's public key. + * @param \CommunityRoom[] $rooms Rooms to sort by server pubkey. + */ + public static function sort_rooms_by_pubkey(array &$rooms) { + usort($rooms, function(\CommunityRoom $a, \CommunityRoom $b) { + return strcmp( + $a->server->get_pubkey(), + $b->server->get_pubkey() + ); + }); + } + /** * Returns array of staff Session IDs. * @return string[] diff --git a/sites/index.php b/sites/index.php index cb205a1..50befa1 100644 --- a/sites/index.php +++ b/sites/index.php @@ -16,6 +16,10 @@ // List all rooms from the cached servers. $rooms = CommunityServer::enumerate_rooms($servers); + // Sort rooms by name and then host. + CommunityRoom::sort_rooms_str($rooms, 'name'); + CommunityRoom::sort_rooms_by_pubkey($rooms); + // Set the last-updated timestamp // to the time the server data file was last modified. $timestamp = filemtime($ROOMS_FILE);