diff --git a/config/config.default.json b/config/config.default.json index 1f4e57f..5e8a70d 100644 --- a/config/config.default.json +++ b/config/config.default.json @@ -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, } diff --git a/server/routes/room-directory-routes.js b/server/routes/room-directory-routes.js index bf1f126..d92bee2 100644 --- a/server/routes/room-directory-routes.js +++ b/server/routes/room-directory-routes.js @@ -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]);