From 64f77da0d1f4ace73a3021798573cd60e2862e0c Mon Sep 17 00:00:00 2001 From: gravel Date: Fri, 26 May 2023 14:24:38 +0000 Subject: [PATCH 1/7] Move systemd into etc --- CONTRIBUTING.md | 4 +++- {systemd => etc/systemd}/session_sudoers | 0 {systemd => etc/systemd}/sessioncommunities.service | 0 {systemd => etc/systemd}/sessioncommunities.timer | 0 4 files changed, 3 insertions(+), 1 deletion(-) rename {systemd => etc/systemd}/session_sudoers (100%) rename {systemd => etc/systemd}/sessioncommunities.service (100%) rename {systemd => etc/systemd}/sessioncommunities.timer (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 540e87b..70f1049 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,12 +35,14 @@ Run at least once: `make fetch` to query servers. This can take around 5 minutes Run when developing: `make dev` to watch for changes & serve HTML locally in browser. +Symlink the commit hook provided in [`etc/hooks`](etc/hooks/) to `.git/hooks/` to run a full test cycle when committing to main. + See [`Makefile`](Makefile) for more details. ### Running your own copy - point your webserver at the [`output`](output/) folder -- install and enable systemd services from the [`systemd`](systemd/) folder or an equivalent timer +- install and enable systemd services from the [`etc/systemd`](etc/systemd/) folder or an equivalent timer ## Code style guidelines diff --git a/systemd/session_sudoers b/etc/systemd/session_sudoers similarity index 100% rename from systemd/session_sudoers rename to etc/systemd/session_sudoers diff --git a/systemd/sessioncommunities.service b/etc/systemd/sessioncommunities.service similarity index 100% rename from systemd/sessioncommunities.service rename to etc/systemd/sessioncommunities.service diff --git a/systemd/sessioncommunities.timer b/etc/systemd/sessioncommunities.timer similarity index 100% rename from systemd/sessioncommunities.timer rename to etc/systemd/sessioncommunities.timer From 6eaf63bb94e3d994358eba6d1d146beeeb079a24 Mon Sep 17 00:00:00 2001 From: gravel Date: Sat, 27 May 2023 13:52:05 +0000 Subject: [PATCH 2/7] Use hash in URL to open modal --- output/js/constants.js | 2 +- output/main.js | 37 ++++++++++++++++++++++++--- sites/+components/tbl_communities.php | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/output/js/constants.js b/output/js/constants.js index f715f86..3891348 100644 --- a/output/js/constants.js +++ b/output/js/constants.js @@ -7,7 +7,7 @@ export const dom = { tbl_communities: () => document.getElementById("tbl_communities"), tbl_communities_content_rows: () => Array.from(dom.tbl_communities()?.rows)?.filter(row => !row.querySelector('th')), - community_row: (communityID) => document.getElementById(communityID), + community_row: (communityID) => document.querySelector(`.room-row[${ATTRIBUTES.ROW.IDENTIFIER}="${communityID}"]`), row_info: (row) => { const dateCreated = new Date(row.getAttribute(ATTRIBUTES.ROW.DATE_CREATED) * 1000); /** @type {string[]} */ diff --git a/output/main.js b/output/main.js index a9eeaa8..6b6b6d2 100644 --- a/output/main.js +++ b/output/main.js @@ -76,6 +76,26 @@ function getTimestamp() { return timestamp; } +/** + * Processes URL hash and parameter to trigger actions on the page. + */ +function reactToURLParameters() { + const hash = location.hash; + if (hash == "") return; + const communityID = hash.slice(1); + const row = dom.community_row(communityID); + if (row == null || !(row instanceof HTMLTableRowElement)) { + return; + } + + try { + displayQRModal(communityID); + } catch (e) { + console.error("Could not navigate to community " + communityID); + console.error(e); + } +} + /** * Triggers all actions dependent on page load. */ @@ -92,6 +112,7 @@ function onLoad() { addQRModalHandlers(); addServerIconInteractions(); preloadImages(); + reactToURLParameters(); } /** @@ -160,6 +181,14 @@ function displayQRModal(communityID, pane = 0) { document.getElementById('details-modal-panes').setAttribute('data-pane', pane); + location.hash=`#${communityID}`; + + // manual scrolling to prevent jumping after every modal open + + row.scrollIntoView({ + behavior: "smooth" + }); + modal.showModal(); } @@ -310,7 +339,7 @@ function hideBadCommunities() { for (const category of ['tests', 'offensive']) { numberOfHiddenCommunities += filteredCommunities[category] - .map(hideElementByID) + .map(hideCommunity) .reduce((a, b) => a + b); } @@ -319,10 +348,10 @@ function hideBadCommunities() { } /** - * Removes an element by its ID and returns the number of elements removed. + * Removes a Community by its ID and returns the number of elements removed. */ -function hideElementByID(id) { - const element = document.getElementById(id); +function hideCommunity(communityID) { + const element = dom.community_row(communityID); element?.remove(); return element ? 1 : 0; } diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index 436cd42..231f5bb 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -71,7 +71,7 @@ $tags_json = json_encode($room->get_room_tags()); ?> - Date: Sat, 27 May 2023 15:19:10 +0000 Subject: [PATCH 3/7] Lower icon refetch rate to 1 day --- php/utils/room-icons.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/utils/room-icons.php b/php/utils/room-icons.php index 9f135dc..d4a0c57 100644 --- a/php/utils/room-icons.php +++ b/php/utils/room-icons.php @@ -47,7 +47,7 @@ $room_id = $room->get_room_identifier(); $icon_cached = room_icon_path($room_id); $icon_resized = room_icon_path_resized($room_id, $size); - $icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 hour"); + $icon_expired = file_exists($icon_cached) && filemtime($icon_cached) < strtotime("-1 day"); // Re-fetch icons periodically. if (!file_exists($icon_cached) || $icon_expired) { From b044f99a478ff3ad28f3259074cc7ae50bc543cb Mon Sep 17 00:00:00 2001 From: gravel Date: Sat, 27 May 2023 15:27:31 +0000 Subject: [PATCH 4/7] Add button to share room details link --- output/js/constants.js | 2 ++ output/main.js | 9 ++++++++- sites/+components/qr_modals.php | 17 +++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/output/js/constants.js b/output/js/constants.js index 3891348..c6a3b02 100644 --- a/output/js/constants.js +++ b/output/js/constants.js @@ -49,6 +49,8 @@ export const STAFF_ID_PASTE = "Copied staff ping to clipboard. Use it in the sel export const IDENTIFIER_PASTE = "Copied internal room identifier. Use it to identify a room, such as when contributing language labels." +export const DETAILS_LINK_PASTE = "Copied link to Community details."; + export const communityQRCodeURL = (communityID) => `qr-codes/${communityID}.png` export const COLUMN = { diff --git a/output/main.js b/output/main.js index 6b6b6d2..aee8b9c 100644 --- a/output/main.js +++ b/output/main.js @@ -17,7 +17,7 @@ import { dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES, columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION, - element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE + element, JOIN_URL_PASTE, communityQRCodeURL, STAFF_ID_PASTE, IDENTIFIER_PASTE, DETAILS_LINK_PASTE } from './js/constants.js'; // Hidden communities for transparency. @@ -283,6 +283,13 @@ function addQRModalHandlers() { } ) + document.querySelector('#details-modal-copy-room-details-link')?.addEventListener( + 'click', + function() { + copyToClipboard(location.href, DETAILS_LINK_PASTE); + } + ) + for (const anchor of dom.qr_code_buttons()) { // Disable QR code links anchor.setAttribute("href", "#"); diff --git a/sites/+components/qr_modals.php b/sites/+components/qr_modals.php index c1f609e..acc6639 100644 --- a/sites/+components/qr_modals.php +++ b/sites/+components/qr_modals.php @@ -99,11 +99,20 @@ Copy mod ping + + title="Copy link to show details about this Community" + > + Share +
(Esc to close.) -
+
@@ -23,7 +23,7 @@ width="64" height="64" data-hydrate-with="icon:src;icon_safety:data-icon-safety" - />

Server: -

diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index 231f5bb..c7e62c3 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -66,7 +66,7 @@ $join_link = html_sanitize($room->get_join_url()); $pubkey = html_sanitize($pubkey); $hostname = html_sanitize($hostname); - + $staff_json = json_encode(array_map('html_sanitize', $room->get_staff())); $tags_json = json_encode($room->get_room_tags()); ?> @@ -118,10 +118,10 @@ title="'' has had active users in the last ." > - diff --git a/sites/index.php b/sites/index.php index e66b6fb..0dce2ab 100644 --- a/sites/index.php +++ b/sites/index.php @@ -58,7 +58,7 @@
-