1
0
Fork 1

Re-normalize active user counts

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

@ -2,6 +2,7 @@
include_once "$PROJECT_ROOT/languages/language_flags.php";
$WEEK_SECONDS = 604800;
/**
* Representation of Session Community room.
*/
@ -199,6 +200,28 @@
$pubkey_4 = substr($this->server->pubkey, 0, 4);
return "$token+$pubkey_4";
}
/**
* Returns an estimate for the weekly active users of a CommunityRoom.
* @return int Active user count normalized by tracked timespan of active users.
*/
function get_weekly_active_users(): int {
global $WEEK_SECONDS;
$active_users = $this->active_users;
if ($active_users == null) {
return 0;
}
$active_users_cutoff = $this->active_users_cutoff;
if ($active_users_cutoff == null) {
return $active_users;
}
return floor($active_users * $WEEK_SECONDS / $active_users_cutoff);
}
}
/**

@ -57,7 +57,7 @@
$language = html_sanitize($room->language_flag);
$name = html_sanitize($room->name);
$desc = html_sanitize($room->description);
$users = html_sanitize($room->active_users);
$users = html_sanitize($room->get_weekly_active_users());
$preview_link = html_sanitize($room->get_preview_url());
$join_link = html_sanitize($room->get_join_url());
$pubkey = html_sanitize($pubkey);