Add stickied room support

dev
gravel 1 year ago
parent 8b1e0c217c
commit 63964f6345
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -340,6 +340,10 @@ header {
padding-block: calc( var(--cell-padding-v) ); padding-block: calc( var(--cell-padding-v) );
} }
.room-row-stickied > .td_name > .td_name-inner {
font-weight: bold;
}
.td_language { .td_language {
text-align: center; text-align: center;
font-size: 1.5em; font-size: 1.5em;

@ -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 all known Community staff Session IDs.
* @return string[] * @return string[]
@ -403,13 +413,6 @@
return "$token+$server_id"; 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. * Add string tags to the Community.
* @param string[] $tags * @param string[] $tags
@ -526,6 +529,13 @@
return $rooms; 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. * 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); 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. * Determine the safety of the Community's icon.
* @return 1 if safe, -1 if unsafe, 0 if unknown. * @return 1 if safe, -1 if unsafe, 0 if unknown.
@ -627,7 +642,7 @@
* @return CommunityTag[] Array of tags. * @return CommunityTag[] Array of tags.
*/ */
private function get_derived_tags(): array { 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 * @var CommunityTag[] $derived_tags
@ -636,10 +651,18 @@
$USERS_PER_STAFF_WARNING = CommunityRoom::USERS_PER_STAFF_WARNING; $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()) { if ($this->is_official_room()) {
$derived_tags[] = ReservedTags::official(); $derived_tags[] = ReservedTags::official();
} }
if ($this->is_stickied_room()) {
$derived_tags[] = ReservedTags::stickied();
}
if ($this->rated_nsfw()) { if ($this->rated_nsfw()) {
$derived_tags[] = ReservedTags::nsfw(); $derived_tags[] = ReservedTags::nsfw();
} }
@ -660,14 +683,11 @@
$derived_tags[] = ReservedTags::recently_created(); $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()) { if ($this->is_testing_room()) {
$derived_tags[] = ReservedTags::testing(); $derived_tags[] = ReservedTags::testing();
} }
return $derived_tags; return $derived_tags;
} }

@ -242,11 +242,12 @@
"uploads off", "uploads off",
"we're here", "we're here",
"test", "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"]; 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 = "✅"; $CHECK_MARK = "✅";
return new CommunityTag( 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 = "⚠️"; $WARNING_ICON = "⚠️";
return new CommunityTag( return new CommunityTag(
@ -354,5 +355,13 @@
"This Community is intended for testing only." "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. 📌"
);
}
} }
?> ?>

@ -72,6 +72,14 @@
$pubkey = html_sanitize($pubkey); $pubkey = html_sanitize($pubkey);
$hostname = html_sanitize($room->server->get_hostname()); $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: * Note on refactoring:
* Icon is hard to move to JSON because it'd have to be generated by fetching code * Icon is hard to move to JSON because it'd have to be generated by fetching code
@ -79,7 +87,7 @@
*/ */
?> ?>
<tr class="room-row" <tr class="<?=$classname?>"
itemscope itemscope
itemtype="https://schema.org/EntryPoint" itemtype="https://schema.org/EntryPoint"
data-id="<?=$id?>" data-id="<?=$id?>"

@ -23,6 +23,7 @@
// Sort rooms by name and then host. // Sort rooms by name and then host.
CommunityRoom::sort_rooms_str($rooms, 'name'); CommunityRoom::sort_rooms_str($rooms, 'name');
CommunityRoom::sort_rooms_by_server($rooms); CommunityRoom::sort_rooms_by_server($rooms);
CommunityRoom::sort_stickied_rooms_first($rooms);
// Set the last-updated timestamp // Set the last-updated timestamp
// to the time the server data file was last modified. // to the time the server data file was last modified.

Loading…
Cancel
Save