1
0
Fork 1

Pre-sort by name and host

pull/37/head
gravel 1 year ago
parent 3b47818f6e
commit dd8b01bbb3
Signed by: gravel
SSH Key Fingerprint: SHA256:p4HP49CCk4YQMkJpWJ09L8peEPQWjERtdCRAFxPfbOY

@ -1,5 +1,4 @@
<?php
include_once "$PROJECT_ROOT/languages/language_flags.php";
$WEEK_SECONDS = 604800;
@ -131,6 +130,33 @@
}, $details);
}
/**
* Sorts Community rooms in-place by the given string property.
* @param \CommunityRoom[] $rooms Rooms to sort by given key.
* @param string $key String property of CommunityRoom to sort by.
*/
public static function sort_rooms_str(array &$rooms, string $key) {
usort($rooms, function(\CommunityRoom $a, \CommunityRoom $b) use ($key) {
return strcmp(
$a->$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[]

@ -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);