diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index fe287e8..89ac54d 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -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); + } } /** diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index c03841e..48c1c2f 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -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);