Allow hiding the room directory at all

- helpful together with allow list
This commit is contained in:
felix.stupp@banananet.work 2023-07-27 17:10:34 +00:00
parent c6c22a78f3
commit 9fcb62be83
No known key found for this signature in database
GPG Key ID: 93E1BD26F6B02FB7
2 changed files with 11 additions and 0 deletions

View File

@ -26,4 +26,6 @@
//"enableAllowList": true,
// use room ids starting with a `!`, not aliases
//"roomAllowList": ["!ypQyNeReyEPUCKYjPU:matrix.org"], // e.g. room about Matrix Reputation
// Hide room directory (will enable auto redirect to first entry of allow list)
//"hideRoomDirectory": true,
}

View File

@ -14,6 +14,7 @@ const checkIfAllowed = require('../lib/matrix-utils/check-room-allowed');
const fetchAccessibleRooms = require('../lib/matrix-utils/fetch-accessible-rooms');
const renderHydrogenVmRenderScriptToPageHtml = require('../hydrogen-render/render-hydrogen-vm-render-script-to-page-html');
const setHeadersToPreloadAssets = require('../lib/set-headers-to-preload-assets');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const config = require('../lib/config');
const basePath = config.get('basePath');
@ -25,6 +26,8 @@ assert(matrixServerName);
const matrixAccessToken = config.get('matrixAccessToken');
assert(matrixAccessToken);
const matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
const router = express.Router({
caseSensitive: true,
// Preserve the req.params values from the parent router.
@ -35,6 +38,11 @@ router.get(
'/',
identifyRoute('app-room-directory-index'),
asyncHandler(async function (req, res) {
if (config.get("hideRoomDirectory")) {
res.redirect(matrixViewerURLCreator.roomUrl(config.get("roomAllowList")[0]));
return;
}
const searchTerm = req.query.search;
const homeserver = req.query.homeserver;
const paginationToken = req.query.page;
@ -84,6 +92,7 @@ router.get(
// limit to allow list
// Because filtering happens after checking the directory this may lead into a bad UX.
// Consider setting hideDirectory
if (config.get("enableAllowList")) {
const checkResults = await Promise.all(rooms.map((r) => r.room_id).map(checkIfAllowed));
rooms = rooms.filter((_v, index) => checkResults[index]);