From 8c8f822ff2d4dead1d9fc4b405a8b4425b6f9b98 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 18 Apr 2023 16:01:12 +0200 Subject: [PATCH] Reflect cutoff period for user counts in tooltip --- php/utils/servers-rooms.php | 31 +++++++++++++++++++++++++++ sites/+components/tbl_communities.php | 5 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index 1c1226ee..67e33dbe 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -1,6 +1,11 @@ created; } + /** + * Formats the period over which active users are counted as a duration string. + * @return string Active user cutoff period for this room, expressed in days. + */ + function format_user_cutoff_period(): ?string { + global $WEEK_SECONDS, $DAY_SECONDS, $HOUR_SECONDS, $MINUTE_SECONDS; + + $active_users_cutoff = $this->active_users_cutoff; + + if ($active_users_cutoff >= $WEEK_SECONDS) { + return floor($active_users_cutoff / $WEEK_SECONDS) . ' week(s)'; + } + if ($active_users_cutoff >= $DAY_SECONDS) { + return floor($active_users_cutoff / $DAY_SECONDS) . ' day(s)'; + } + if ($active_users_cutoff >= $HOUR_SECONDS) { + return floor($active_users_cutoff / $HOUR_SECONDS) . ' hour(s)'; + } + if ($active_users_cutoff >= $MINUTE_SECONDS) { + return floor($active_users_cutoff / $MINUTE_SECONDS) . 'minute(s)'; + } + + return floor($active_users_cutoff) . 's'; + + } + /** * Return the browser preview URL for this room. */ diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index d49d1393..59b34018 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -28,7 +28,7 @@ ['id' => "language", 'name' => "L", 'name_long' => "Language"], ['id' => "name", 'name' => "Name"], ['id' => "description", 'name' => "About", 'name_long' => "Description"], - ['id' => "users", 'name' => "#", 'name_long' => "Weekly Active Users"], + ['id' => "users", 'name' => "#", 'name_long' => "Active Users"], ['id' => "preview", 'name' => "Preview"], ['id' => "qr_code", 'name' => "QR", 'name_long' => "QR Code (for use in-app)"], ['id' => "server_icon", 'name' => "Host", 'name_long' => "Server host"], @@ -58,6 +58,7 @@ $name = html_sanitize($room->name); $desc = html_sanitize($room->description); $users = html_sanitize($room->active_users); + $users_cutoff = html_sanitize($room->format_user_cutoff_period()); $preview_link = html_sanitize($room->get_preview_url()); $join_link = html_sanitize($room->get_join_url()); $pubkey = html_sanitize($pubkey); @@ -86,7 +87,7 @@ >