1
0
Fork 1

Reflect cutoff period for user counts in tooltip

pull/37/head
gravel 1 year ago
parent 6c72470636
commit 8c8f822ff2
Signed by: gravel
SSH Key Fingerprint: SHA256:p4HP49CCk4YQMkJpWJ09L8peEPQWjERtdCRAFxPfbOY

@ -1,6 +1,11 @@
<?php
include_once "$PROJECT_ROOT/languages/language_flags.php";
$MINUTE_SECONDS = 60;
$HOUR_SECONDS = 60 * $MINUTE_SECONDS;
$DAY_SECONDS = 24 * $HOUR_SECONDS;
$WEEK_SECONDS = 7 * $DAY_SECONDS;
/**
* Representation of Session Community room.
*/
@ -173,6 +178,32 @@
return time() - $this->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.
*/

@ -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 @@
><?=$desc?></td>
<td
class="td_users"
title="'<?=$name?>' has around <?=$users?> weekly active users."
title="'<?=$name?>' has had <?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview" itemprop="url">
<a href="<?=$preview_link?>" target="_blank" rel="noopener noreferrer nofollow">