1
0
Fork 1

Add tag descriptions & track staff coverage

pull/38/head
gravel 3 years ago
parent 98d95efe26
commit 7c55a28944
Signed by: gravel
SSH Key Fingerprint: SHA256:p4HP49CCk4YQMkJpWJ09L8peEPQWjERtdCRAFxPfbOY

@ -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];

@ -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.
*/

@ -89,7 +89,7 @@
<?php foreach ($room->get_room_tags() as $tag): ?>
<span
class="room-label room-label-<?=$tag->get_tag_type()?> badge"
title="<?=$tag?>"
title="<?=$tag->description?>"
><?=
truncate($tag->text, 16)
?></span>