From 63964f6345cd7fc44c0032c7329e14fec12fae0a Mon Sep 17 00:00:00 2001 From: gravel Date: Thu, 21 Dec 2023 21:45:19 +0000 Subject: [PATCH] Add stickied room support --- output/index.css | 4 +++ php/servers/servers-rooms.php | 44 +++++++++++++++++++-------- php/servers/tags.php | 17 ++++++++--- sites/+components/tbl-communities.php | 10 +++++- sites/index.php | 1 + 5 files changed, 59 insertions(+), 17 deletions(-) diff --git a/output/index.css b/output/index.css index c2e340c..6d5784c 100644 --- a/output/index.css +++ b/output/index.css @@ -340,6 +340,10 @@ header { padding-block: calc( var(--cell-padding-v) ); } +.room-row-stickied > .td_name > .td_name-inner { + font-weight: bold; +} + .td_language { text-align: center; font-size: 1.5em; diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index 08fa9d9..6f2e99c 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -308,6 +308,16 @@ }); } + /** + * @param CommunityRoom[] $rooms + */ + public static function sort_stickied_rooms_first(array &$rooms) { + global $STICKIED_ROOMS; + usort($rooms, function(CommunityRoom $a, CommunityRoom $b) use ($STICKIED_ROOMS) { + return $b->matched_by_list($STICKIED_ROOMS) - $a->matched_by_list($STICKIED_ROOMS); + }); + } + /** * Return all known Community staff Session IDs. * @return string[] @@ -403,13 +413,6 @@ return "$token+$server_id"; } - /** - * Checks whether this room belongs to a Session-owned server. - */ - function is_official_room(): bool { - return $this->server->is_official_server(); - } - /** * Add string tags to the Community. * @param string[] $tags @@ -526,6 +529,13 @@ return $rooms; } + /** + * Checks whether this room belongs to a Session-owned server. + */ + function is_official_room(): bool { + return $this->server->is_official_server(); + } + /** * Check whether the Community's text fields contain adult keywords. */ @@ -562,6 +572,11 @@ return in_array("test", $this->string_tags) || $this->matched_by_list($TESTING_INCLUDE); } + public function is_stickied_room(): bool { + global $STICKIED_ROOMS; + return $this->matched_by_list($STICKIED_ROOMS); + } + /** * Determine the safety of the Community's icon. * @return 1 if safe, -1 if unsafe, 0 if unknown. @@ -627,7 +642,7 @@ * @return CommunityTag[] Array of tags. */ private function get_derived_tags(): array { - global $ROOMS_USED_BY_PROJECT, $TESTING_INCLUDE; + global $ROOMS_USED_BY_PROJECT, $TESTING_INCLUDE, $STICKIED_ROOMS; /** * @var CommunityTag[] $derived_tags @@ -636,10 +651,18 @@ $USERS_PER_STAFF_WARNING = CommunityRoom::USERS_PER_STAFF_WARNING; + if (in_array($this->get_room_identifier(), $ROOMS_USED_BY_PROJECT)) { + $derived_tags[] = ReservedTags::used_by_project(); + } + if ($this->is_official_room()) { $derived_tags[] = ReservedTags::official(); } + if ($this->is_stickied_room()) { + $derived_tags[] = ReservedTags::stickied(); + } + if ($this->rated_nsfw()) { $derived_tags[] = ReservedTags::nsfw(); } @@ -660,14 +683,11 @@ $derived_tags[] = ReservedTags::recently_created(); } - if (in_array($this->get_room_identifier(), $ROOMS_USED_BY_PROJECT)) { - $derived_tags[] = ReservedTags::used_by_project(); - } - if ($this->is_testing_room()) { $derived_tags[] = ReservedTags::testing(); } + return $derived_tags; } diff --git a/php/servers/tags.php b/php/servers/tags.php index 7fda907..c4204c9 100644 --- a/php/servers/tags.php +++ b/php/servers/tags.php @@ -242,11 +242,12 @@ "uploads off", "we're here", "test", + "pinned" ]; - private const SHOWCASED_TAGS = ["official", "new", "we're here", "nsfw", "read-only"]; + private const SHOWCASED_TAGS = ["official", "new", "we're here", "nsfw", "read-only", "pinned"]; - private const HIGHLIGHTED_TAGS = ["new", "we're here"]; + private const HIGHLIGHTED_TAGS = ["new", "we're here", "pinned"]; private const REDUNDANT_TAGS = ["session"]; @@ -294,7 +295,7 @@ ); } - public static function moderated(int $users_per_staff) { + public static function moderated(int $users_per_staff = 0) { $CHECK_MARK = "✅"; return new CommunityTag( @@ -304,7 +305,7 @@ ); } - public static function not_modded(int $users_per_staff) { + public static function not_modded(int $users_per_staff = 0) { $WARNING_ICON = "⚠️"; return new CommunityTag( @@ -354,5 +355,13 @@ "This Community is intended for testing only." ); } + + public static function stickied() { + return new CommunityTag( + "pinned", + TagType::RESERVED_TAG, + "This Community has been pinned for greater visibility. 📌" + ); + } } ?> diff --git a/sites/+components/tbl-communities.php b/sites/+components/tbl-communities.php index d0c67bf..0632d55 100644 --- a/sites/+components/tbl-communities.php +++ b/sites/+components/tbl-communities.php @@ -72,6 +72,14 @@ $pubkey = html_sanitize($pubkey); $hostname = html_sanitize($room->server->get_hostname()); + $class_list = ["room-row"]; + + if ($room->is_stickied_room()) { + $class_list[] = "room-row-stickied"; + } + + $classname = implode(" ", $class_list); + /** * Note on refactoring: * Icon is hard to move to JSON because it'd have to be generated by fetching code @@ -79,7 +87,7 @@ */ ?> -