diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index f79ac4a3..dfa90d2f 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -288,6 +288,22 @@ return false; } + public const USERS_PER_STAFF = 50; + public const USERS_PER_STAFF_WARNING = 200; + + private function has_good_staff_rating(): bool { + $recommended_staff_count = $this->active_users / CommunityRoom::USERS_PER_STAFF; + return count($this->get_staff()) >= $recommended_staff_count; + } + + private function has_poor_staff_rating(): bool { + if ($this->active_users <= 3) { + return false; + } + $minimal_staff_count = $this->active_users / CommunityRoom::USERS_PER_STAFF_WARNING; + return count($this->get_staff()) < $minimal_staff_count; + } + /** * Return the tags associated with this room. * @return \CommunityTag[] Tags as string array. @@ -300,12 +316,44 @@ */ $derived_tags = []; + $CHECK_MARK = CommunityTag::CHECK_MARK; + $WARNING = CommunityTag::WARNING_ICON; + $USERS_PER_STAFF = CommunityRoom::USERS_PER_STAFF; + $USERS_PER_STAFF_WARNING = CommunityRoom::USERS_PER_STAFF_WARNING; + if ($this->is_official_room()) { - $derived_tags[] = new CommunityTag("official", TagType::RESERVED_TAG); + $derived_tags[] = new CommunityTag( + "official", + TagType::RESERVED_TAG, + "This Community is maintained by the Session team. $CHECK_MARK" + ); } if ($this->has_nsfw_keywords()) { - $derived_tags[] = new CommunityTag("nsfw", TagType::WARNING_TAG); + $derived_tags[] = + new CommunityTag( + "nsfw", + TagType::WARNING_TAG, + "This Community may contain adult material. $WARNING" + ); + } + + if ($this->write && $this->has_good_staff_rating()) { + $derived_tags[] = + new CommunityTag( + "modded", + TagType::RESERVED_TAG, + "This Community has at least 1 staff per $USERS_PER_STAFF active users. $CHECK_MARK" + ); + } + + if ($this->write && $this->has_poor_staff_rating()) { + $derived_tags[] = + new CommunityTag( + "not modded", + TagType::WARNING_TAG, + "This Community has less than 1 staff per $USERS_PER_STAFF_WARNING active users. $WARNING" + ); } return [...$derived_tags, ...$user_tags]; diff --git a/php/utils/tags.php b/php/utils/tags.php index b7ea3366..e446f3cd 100644 --- a/php/utils/tags.php +++ b/php/utils/tags.php @@ -9,15 +9,23 @@ } class CommunityTag implements JsonSerializable { - public function __construct(string $text, int $tag_type = TagType::USER_TAG) { + public function __construct( + string $text, + int $tag_type = TagType::USER_TAG, + string $description = "" + ) { $this->text = $text; $this->type = $tag_type; + $this->description = + empty($description) ? "Tag: $text" : $description; } public readonly int $type; public readonly string $text; + public readonly string $description; + /** * Returns a lowercase representation of the tag for purposes of de-duping. */ @@ -124,12 +132,16 @@ * @var string[] RESERVED_TAGS * Array of derived tags unavailable for manual tagging. */ - private const RESERVED_TAGS = ["official", "nsfw"]; + private const RESERVED_TAGS = ["official", "nsfw", "modded", "not modded"]; private const REDUNDANT_TAGS = ["session"]; public const NSFW_KEYWORDS = ["nsfw", "porn", "erotic", "18+"]; + public const CHECK_MARK = "✅"; + + public const WARNING_ICON = "⚠️"; + /** * Checks whether the given manual tag can be accepted. */ diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index 8c3b6e32..d81e668e 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -89,7 +89,7 @@ get_room_tags() as $tag): ?> text, 16) ?>