Bulk rename from "Matrix Public Archive" to "Matrix Viewer"

This commit is contained in:
Eric Eastwood 2023-07-14 15:34:54 -05:00
parent c819100d67
commit 66dad367f3
58 changed files with 566 additions and 605 deletions

View File

@ -8,11 +8,11 @@ on:
env:
REGISTRY: ghcr.io
GHCR_NAMESPACE: matrix-org/matrix-public-archive
IMAGE_NAME: matrix-public-archive
GHCR_NAMESPACE: matrix-org/matrix-viewer
IMAGE_NAME: matrix-viewer
jobs:
# Create and publish a Docker image for matrix-public-archive
# Create and publish a Docker image for matrix-viewer
#
# Based off of
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
@ -83,7 +83,7 @@ jobs:
runs-on: ubuntu-latest
services:
matrix-public-archive:
matrix-viewer:
image: ${{ needs.build-image.outputs.docker_image_name }}:sha-${{ github.sha }}
credentials:
username: ${{ github.actor }}

View File

@ -8,8 +8,8 @@ on:
env:
REGISTRY: ghcr.io
GHCR_NAMESPACE: matrix-org/matrix-public-archive
IMAGE_NAME: matrix-public-archive-test-homeserver
GHCR_NAMESPACE: matrix-org/matrix-viewer
IMAGE_NAME: matrix-viewer-test-homeserver
jobs:
# Create and publish a Docker image for a Synapse test instance that can

View File

@ -1,24 +1,24 @@
# 0.2.0 - _upcoming_
# 0.2.0 - _upcoming_ - Matrix Viewer
- Prevent Cloudflare from overriding our own 504 timeout page, https://github.com/matrix-org/matrix-public-archive/pull/228
- Catch NSFW rooms with underscores, https://github.com/matrix-org/matrix-public-archive/pull/231
- Fix `18+` false positives with NSFW check, https://github.com/matrix-org/matrix-public-archive/pull/279
- Fix room cards sorting in the wrong direction on Firefox, https://github.com/matrix-org/matrix-public-archive/pull/261
- Remove `libera.chat` as a default since their rooms are not accessible in the archive, https://github.com/matrix-org/matrix-public-archive/pull/263
- Add reason why the archive bot is joining the room, https://github.com/matrix-org/matrix-public-archive/pull/262
- Add `/faq` redirect, https://github.com/matrix-org/matrix-public-archive/pull/265
- Use `rel=canonical` link to de-duplicate event permalinks, https://github.com/matrix-org/matrix-public-archive/pull/266, https://github.com/matrix-org/matrix-public-archive/pull/269
- Prevent join event spam with stable `reason`, https://github.com/matrix-org/matrix-public-archive/pull/268
- Don't allow previewing `shared` history rooms, https://github.com/matrix-org/matrix-public-archive/pull/239
- Prevent Cloudflare from overriding our own 504 timeout page, https://github.com/matrix-org/matrix-viewer/pull/228
- Catch NSFW rooms with underscores, https://github.com/matrix-org/matrix-viewer/pull/231
- Fix `18+` false positives with NSFW check, https://github.com/matrix-org/matrix-viewer/pull/279
- Fix room cards sorting in the wrong direction on Firefox, https://github.com/matrix-org/matrix-viewer/pull/261
- Remove `libera.chat` as a default since their rooms are not accessible, https://github.com/matrix-org/matrix-viewer/pull/263
- Add reason why the bot is joining the room, https://github.com/matrix-org/matrix-viewer/pull/262
- Add `/faq` redirect, https://github.com/matrix-org/matrix-viewer/pull/265
- Use `rel=canonical` link to de-duplicate event permalinks, https://github.com/matrix-org/matrix-viewer/pull/266, https://github.com/matrix-org/matrix-viewer/pull/269
- Prevent join event spam with stable `reason`, https://github.com/matrix-org/matrix-viewer/pull/268
- Don't allow previewing `shared` history rooms, https://github.com/matrix-org/matrix-viewer/pull/239
- Contributed by [@tulir](https://github.com/tulir)
- Update FAQ to explain `world_readable` only, https://github.com/matrix-org/matrix-public-archive/pull/277
- Indicate when the room was set to `world_readable` and by who, https://github.com/matrix-org/matrix-public-archive/pull/278
- Only show `world_readable` rooms in the room directory, https://github.com/matrix-org/matrix-public-archive/pull/276
- Update FAQ to explain `world_readable` only, https://github.com/matrix-org/matrix-viewer/pull/277
- Indicate when the room was set to `world_readable` and by who, https://github.com/matrix-org/matrix-viewer/pull/278
- Only show `world_readable` rooms in the room directory, https://github.com/matrix-org/matrix-viewer/pull/276
Developer facing:
- Fix eslint trying to look at `node_modules/`, https://github.com/matrix-org/matrix-public-archive/pull/275
- Fix eslint trying to look at `node_modules/`, https://github.com/matrix-org/matrix-viewer/pull/275
# 0.1.0 - 2023-05-11
- Initial public release with good enough functionality to be generally available including: room directory homepage, room archive view with calendar jump-to-date, drill-down with the time selector, following room upgrades (tombstone/predecessor), and more. Completed milestone: https://github.com/matrix-org/matrix-public-archive/milestone/1
- Initial public release with good enough functionality to be generally available including: room directory homepage, room archive view with calendar jump-to-date, drill-down with the time selector, following room upgrades (tombstone/predecessor), and more. Completed milestone: https://github.com/matrix-org/matrix-viewer/milestone/1

View File

@ -25,14 +25,14 @@ module.exports = defineConfig({
// This doesn't seem to be necessary for the this package to work (ref
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies)
//
//'matrix-public-archive-shared'
//'matrix-viewer-shared'
],
},
resolve: {
alias: {
// The `file:` packages don't seem resolve correctly so let's add an alias as well
// See https://css-tricks.com/adding-vite-to-your-existing-web-app/#aa-aliases
'matrix-public-archive-shared': path.resolve(__dirname, '../shared'),
'matrix-viewer-shared': path.resolve(__dirname, '../shared'),
},
// This will make sure Vite/Rollup matches the original file path (i.e. the path
// without following symlinks) instead of the real file path (i.e. the path after

View File

@ -60,7 +60,7 @@ summary {
}
/* Based on .SessionView from Hydrogen */
.ArchiveRoomView {
.RoomView {
/* this takes into account whether or not the url bar is hidden on mobile
(have tested Firefox Android and Safari on iOS),
see https://developers.google.com/web/updates/2016/12/url-bar-resizing */
@ -76,7 +76,7 @@ summary {
min-width: 0;
}
.ArchiveRoomView_mainArea {
.RoomView_mainArea {
grid-area: middle;
display: flex;
flex-direction: column;
@ -105,7 +105,7 @@ summary {
display: none;
}
.ArchiveRoomView_mainBody {
.RoomView_mainBody {
flex: 1 1;
display: flex;
flex-direction: column;
@ -114,31 +114,31 @@ summary {
min-width: 0;
}
.ArchiveRoomView_mainBody > .Timeline {
.RoomView_mainBody > .Timeline {
flex: 1 0;
}
@media screen and (max-width: 800px) {
/* Only the middle needs to be visible mobile by default */
.ArchiveRoomView {
.RoomView {
grid-template:
'status' auto
'middle' 1fr /
1fr;
}
/* Which also means hiding the right-panel by default on mobile */
.ArchiveRoomView:not(.right-shown) .RightPanelView {
.RoomView:not(.right-shown) .RightPanelView {
display: none;
}
/* When the user opens the right-panel, show it */
.ArchiveRoomView.right-shown {
.RoomView.right-shown {
grid-template:
'status' auto
'right' 1fr /
1fr;
}
.ArchiveRoomView.right-shown .ArchiveRoomView_mainArea {
.RoomView.right-shown .RoomView_mainArea {
display: none;
}
/* And show the button to open the right-panel on mobile */

View File

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

@ -1,4 +1,4 @@
import 'matrix-public-archive-shared/hydrogen-vm-render-script.js';
import 'matrix-viewer-shared/hydrogen-vm-render-script.js';
// Assets
import 'hydrogen-view-sdk/assets/theme-element-light.css';

View File

@ -1,19 +1,19 @@
import assert from 'matrix-public-archive-shared/lib/assert.js';
import MatrixPublicArchiveURLCreator from 'matrix-public-archive-shared/lib/url-creator.js';
import redirectIfRoomAliasInHash from 'matrix-public-archive-shared/lib/redirect-if-room-alias-in-hash.js';
import assert from 'matrix-viewer-shared/lib/assert.js';
import MatrixViewerURLCreator from 'matrix-viewer-shared/lib/url-creator.js';
import redirectIfRoomAliasInHash from 'matrix-viewer-shared/lib/redirect-if-room-alias-in-hash.js';
// Assets
import 'hydrogen-view-sdk/assets/theme-element-light.css';
import '../css/styles.css';
const config = window.matrixPublicArchiveContext.config;
const config = window.matrixViewerContext.config;
assert(config);
assert(config.basePath);
const matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(config.basePath);
const matrixViewerURLCreator = new MatrixViewerURLCreator(config.basePath);
console.log(`Trying to redirect based on pageHash=${window.location.hash}`);
const isRedirecting = redirectIfRoomAliasInHash(matrixPublicArchiveURLCreator);
const isRedirecting = redirectIfRoomAliasInHash(matrixViewerURLCreator);
// Show the message while we're trying to redirect or if we found nothing, remove the
// message

View File

@ -1,4 +1,4 @@
import 'matrix-public-archive-shared/room-directory-vm-render-script.js';
import 'matrix-viewer-shared/room-directory-vm-render-script.js';
// Assets
import 'hydrogen-view-sdk/assets/theme-element-light.css';
@ -8,4 +8,4 @@ import '../css/room-directory.css';
// over for all
import '../img/favicon.ico';
import '../img/favicon.svg';
import '../img/matrix-public-archive-opengraph.png';
import '../img/opengraph.png';

View File

@ -7,7 +7,7 @@
"matrixServerName": "localhost",
// Set this to 100 since that is the max that Synapse will backfill even if you do a
// `/messages?limit=1000` and we don't want to miss messages in between.
"archiveMessageLimit": 100,
"messageLimit": 100,
"requestTimeoutMs": 25000,
"logOutputFromChildProcesses": false,
//"stopSearchEngineIndexing": true,

View File

@ -7,5 +7,5 @@
"testMatrixServerUrl2": "http://localhost:12008/",
// Secrets
"matrixAccessToken": "as_token_8664700429a911bbbecf7d91b9e1a74716d669f40cf32259630e38439726e29d"
"matrixAccessToken": "as_token_matrix_viewer_foobarbaz"
}

View File

@ -2,7 +2,7 @@
## Setup
If you haven't setup `matrix-public-archive` yet, see the [_Setup_ section in the root `README.md`](../README.md#setup)
If you haven't setup `matrix-viewer` yet, see the [_Setup_ section in the root `README.md`](../README.md#setup)
Then we need to setup the federation cluster of homeservers that we will test with.
Sorry, this isn't automated yet when you run the tests 🙇
@ -10,10 +10,10 @@ Sorry, this isn't automated yet when you run the tests 🙇
```sh
# Build the test homeserver image that are pre-configured to federate with each other
$ docker pull matrixdotorg/synapse:latest
$ docker build -t matrix-public-archive-test-homeserver -f test/dockerfiles/Synapse.Dockerfile test/dockerfiles/
$ docker build -t matrix-viewer-test-homeserver -f test/dockerfiles/Synapse.Dockerfile test/dockerfiles/
# Start the test homeservers
$ docker-compose --project-name matrix_public_archive_test -f test/docker-compose.yml up -d --no-recreate
$ docker-compose --project-name matrix_viewer_test -f test/docker-compose.yml up -d --no-recreate
```
## Running the tests
@ -22,7 +22,7 @@ $ docker-compose --project-name matrix_public_archive_test -f test/docker-compos
$ npm run test
```
Or if you want to keep the Matrix Public Archive server running after the tests run and
Or if you want to keep the Matrix Viewer server running after the tests run and
explore the UI from the interactive URL's printed on the screen to better debug, use:
```sh
@ -30,7 +30,7 @@ $ npm run test-interactive
```
Caveat: You might not see the same result that a test is seeing when visiting the
interactive URL. Some tests set config like the `archiveMessageLimit` which is reset
interactive URL. Some tests set config like the `messageLimit` which is reset
after each test case unless you are using `npm run test-interactive` and visiting the
interactive URL for a failed test. Otherwise, we reset config between each test case so
they don't leak and contaminate each other.
@ -41,9 +41,9 @@ Some copy-pasta to help you manage the Docker containers for the test homeserver
```sh
$ docker ps --all | grep test_hs
$ docker logs -f --tail 10 matrix_public_archive_test_hs1_1
$ docker logs -f --tail 10 matrix_public_archive_test_hs2_1
$ docker logs -f --tail 10 matrix_viewer_test_hs1_1
$ docker logs -f --tail 10 matrix_viewer_test_hs2_1
$ docker stop matrix_public_archive_test_hs1_1 matrix_public_archive_test_hs2_1
$ docker rm matrix_public_archive_test_hs1_1 matrix_public_archive_test_hs2_1
$ docker stop matrix_viewer_test_hs1_1 matrix_viewer_test_hs2_1
$ docker rm matrix_viewer_test_hs1_1 matrix_viewer_test_hs2_1
```

10
package-lock.json generated
View File

@ -1,11 +1,11 @@
{
"name": "matrix-public-archive",
"name": "matrix-viewer",
"version": "0.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "matrix-public-archive",
"name": "matrix-viewer",
"version": "0.1.0",
"license": "Apache-2.0",
"dependencies": {
@ -26,7 +26,7 @@
"hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.28.0-scratch",
"json5": "^2.2.1",
"linkedom": "^0.14.17",
"matrix-public-archive-shared": "file:./shared/",
"matrix-viewer-shared": "file:./shared/",
"nconf": "^0.11.3",
"opentelemetry-instrumentation-fetch-node": "^1.0.0",
"url-join": "^4.0.1"
@ -3706,7 +3706,7 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/matrix-public-archive-shared": {
"node_modules/matrix-viewer-shared": {
"resolved": "shared",
"link": true
},
@ -7787,7 +7787,7 @@
"semver": "^6.0.0"
}
},
"matrix-public-archive-shared": {
"matrix-viewer-shared": {
"version": "file:shared"
},
"media-typer": {

View File

@ -1,10 +1,10 @@
{
"name": "matrix-public-archive",
"name": "matrix-viewer",
"version": "0.1.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/matrix-org/matrix-public-archive"
"url": "https://github.com/matrix-org/matrix-viewer"
},
"scripts": {
"lint": "eslint \"**/*.js\"",
@ -53,7 +53,7 @@
"hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.28.0-scratch",
"json5": "^2.2.1",
"linkedom": "^0.14.17",
"matrix-public-archive-shared": "file:./shared/",
"matrix-viewer-shared": "file:./shared/",
"nconf": "^0.11.3",
"opentelemetry-instrumentation-fetch-node": "^1.0.0",
"url-join": "^4.0.1"

View File

@ -96,7 +96,7 @@ async function _renderHydrogenToStringUnsafe(renderOptions) {
}
// Define this for the SSR context
dom.window.matrixPublicArchiveContext = {
dom.window.matrixViewerContext = {
...renderOptions.vmRenderContext,
};

View File

@ -23,7 +23,7 @@ function getAssetUrls() {
_assetUrls = {
faviconIco: getAssetUrl('client/img/favicon.ico'),
faviconSvg: getAssetUrl('client/img/favicon.svg'),
opengraphImage: getAssetUrl('client/img/matrix-public-archive-opengraph.png'),
opengraphImage: getAssetUrl('client/img/opengraph.png'),
};
return _assetUrls;
}
@ -45,7 +45,7 @@ function renderPageHtml({
// Serialize the state for when we run the Hydrogen render again client-side to
// re-hydrate the DOM
const serializedMatrixPublicArchiveContext = JSON.stringify({
const serializedMatrixViewerContext = JSON.stringify({
...vmRenderContext,
});
@ -123,7 +123,7 @@ if (atEventId) {
</script>
<script type="text/javascript" nonce="${pageOptions.cspNonce}">
window.matrixPublicArchiveContext = ${safeJson(serializedMatrixPublicArchiveContext)}
window.matrixViewerContext = ${safeJson(serializedMatrixViewerContext)}
</script>
${scripts

View File

@ -6,7 +6,7 @@ const urlJoin = require('url-join');
const StatusError = require('../errors/status-error');
const { fetchEndpointAsJson } = require('../fetch-endpoint');
const getServerNameFromMatrixRoomIdOrAlias = require('./get-server-name-from-matrix-room-id-or-alias');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const config = require('../config');
const basePath = config.get('basePath');
@ -14,7 +14,7 @@ assert(basePath);
const matrixServerUrl = config.get('matrixServerUrl');
assert(matrixServerUrl);
const matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
const matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
async function ensureRoomJoined(
accessToken,
@ -52,9 +52,9 @@ async function ensureRoomJoined(
reason:
`Joining room to check history visibility. ` +
`If your room is public with shared or world readable history visibility, ` +
`it will be accessible on ${matrixPublicArchiveURLCreator.roomDirectoryUrl()}. ` +
`it will be accessible on ${matrixViewerURLCreator.roomDirectoryUrl()}. ` +
`See the FAQ for more details: ` +
`https://github.com/matrix-org/matrix-public-archive/blob/main/docs/faq.md#why-did-the-archive-bot-join-my-room`,
`https://github.com/matrix-org/matrix-viewer/blob/main/docs/faq.md#why-did-the-bot-join-my-room`,
},
});
assert(
@ -63,7 +63,7 @@ async function ensureRoomJoined(
);
return joinData.room_id;
} catch (err) {
throw new StatusError(403, `Archiver is unable to join room: ${err.message}`);
throw new StatusError(403, `Bot is unable to join room: ${err.message}`);
}
}

View File

@ -3,7 +3,7 @@
const assert = require('assert');
const urlJoin = require('url-join');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const { fetchEndpointAsJson } = require('../fetch-endpoint');
const { traceFunction } = require('../../tracing/trace-utilities');
@ -110,7 +110,7 @@ async function fetchAccessibleRooms(
const fetchedRoomsInDirection =
direction === DIRECTION.forward ? fetchedRooms : fetchedRooms.reverse();
// We only want to see world_readable rooms in the archive
// We only want to see world_readable rooms
let index = 0;
for (let room of fetchedRoomsInDirection) {
if (room.world_readable) {

View File

@ -3,7 +3,7 @@
const assert = require('assert');
const { traceFunction } = require('../../tracing/trace-utilities');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const timestampToEvent = require('./timestamp-to-event');
const getMessagesResponseFromEventId = require('./get-messages-response-from-event-id');

View File

@ -3,7 +3,7 @@
const assert = require('assert');
const urlJoin = require('url-join');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const { fetchEndpointAsJson } = require('../fetch-endpoint');
const config = require('../config');

View File

@ -2,7 +2,7 @@
const assert = require('assert');
const { getUtcStartOfDayTs } = require('matrix-public-archive-shared/lib/timestamp-utilities');
const { getUtcStartOfDayTs } = require('matrix-viewer-shared/lib/timestamp-utilities');
// `X-Date-Temporal-Context` indicates the temporal context of the content, whether it
// is related to past, present, or future *day*.

View File

@ -8,7 +8,7 @@ const basePath = config.get('basePath');
assert(basePath);
const {
VALID_SIGIL_TO_ENTITY_DESCRIPTOR_MAP,
} = require('matrix-public-archive-shared/lib/reference-values');
} = require('matrix-viewer-shared/lib/reference-values');
// Create a regex string that will match a normal string or the URI encoded string or
// any combination of some characters being URI encoded. Only worries about characters
@ -28,7 +28,7 @@ function uriEncodedMatrixCompatibleRegex(inputString) {
// - `/!xxx:my.synapse.server` -> `/roomid/xxx:my.synapse.server`
// - `/%23xxx%3Amy.synapse.server` -> `/r/xxx:my.synapse.server`
// - `/roomid/%23xxx%3Amy.synapse.server/date/2022/09/20?via=my.synapse.server` -> `/r/xxx:my.synapse.server/date/2022/09/20`
function redirectToCorrectArchiveUrlIfBadSigilMiddleware(req, res, next) {
function redirectToCorrectRoomUrlIfBadSigilMiddleware(req, res, next) {
// This could be with or with our without the sigil. Although the correct thing here
// is to have no sigil. We will try to correct it for them in any case.
const roomIdOrAliasDirty = req.params.roomIdOrAliasDirty;
@ -45,7 +45,7 @@ function redirectToCorrectArchiveUrlIfBadSigilMiddleware(req, res, next) {
const entityDescriptor = VALID_SIGIL_TO_ENTITY_DESCRIPTOR_MAP[sigil];
if (!entityDescriptor) {
throw new Error(
`Unknown sigil=${sigil} has no entityDescriptor. This is an error with the Matrix Public Archive itself (please open an issue).`
`Unknown sigil=${sigil} has no entityDescriptor. This is an error with the Matrix Viewer itself (please open an issue).`
);
}
@ -67,4 +67,4 @@ function redirectToCorrectArchiveUrlIfBadSigilMiddleware(req, res, next) {
next();
}
module.exports = redirectToCorrectArchiveUrlIfBadSigilMiddleware;
module.exports = redirectToCorrectRoomUrlIfBadSigilMiddleware;

View File

@ -83,7 +83,7 @@ async function timeoutMiddleware(req, res, next) {
`;
const pageOptions = {
title: `Server timeout - Matrix Public Archive`,
title: `Server timeout - Matrix Viewer`,
description: `Unable to respond in time (${requestTimeoutMs / 1000}s)`,
entryPoint: 'client/js/entry-client-timeout.js',
locationUrl: urlJoin(basePath, req.originalUrl),
@ -104,7 +104,7 @@ async function timeoutMiddleware(req, res, next) {
});
// The most semantic HTTP status code to return here is a 504 Gateway timeout but if
// you use Cloudflare in front of the archive, it will serve its own
// you use Cloudflare in front of the viewer, it will serve its own
// Cloudflare-branded 504 page if your own origin server responds with a 504. And
// the only way to disable this functionality is to have an Enterprise Cloudflare
// plan. So to workaround this, we return a 500 instead. Relevant Cloudflare docs:

View File

@ -14,7 +14,7 @@ assert(basePath);
// `/r/#room-alias:server/date/2022/10/27` -> `/r/room-alias:server/date/2022/10/27`
function clientSideRoomAliasHashRedirectRoute(req, res) {
const pageOptions = {
title: `Page not found - Matrix Public Archive`,
title: `Page not found - Matrix Viewer`,
description: `This page does not exist but we may be able to redirect you to the right place.`,
entryPoint: 'client/js/entry-client-room-alias-hash-redirect.js',
locationUrl: urlJoin(basePath, req.originalUrl),

View File

@ -12,7 +12,7 @@ const preventClickjackingMiddleware = require('../middleware/prevent-clickjackin
const contentSecurityPolicyMiddleware = require('../middleware/content-security-policy-middleware');
const identifyRoute = require('../middleware/identify-route-middleware');
const clientSideRoomAliasHashRedirectRoute = require('./client-side-room-alias-hash-redirect-route');
const redirectToCorrectArchiveUrlIfBadSigil = require('../middleware/redirect-to-correct-archive-url-if-bad-sigil-middleware');
const redirectToCorrectRoomUrlIfBadSigil = require('../middleware/redirect-to-correct-room-url-if-bad-sigil-middleware');
function installRoutes(app) {
app.use(handleTracingMiddleware);
@ -43,11 +43,11 @@ function installRoutes(app) {
'/faq',
identifyRoute('faq'),
asyncHandler(async function (req, res) {
res.redirect('https://github.com/matrix-org/matrix-public-archive/blob/main/docs/faq.md');
res.redirect('https://github.com/matrix-org/matrix-viewer/blob/main/docs/faq.md');
})
);
// Our own archive app styles and scripts
// Our own viewer app styles and scripts
app.use('/assets', express.static(path.join(__dirname, '../../dist/assets')));
app.use('/', timeoutMiddleware, require('./room-directory-routes'));
@ -72,8 +72,8 @@ function installRoutes(app) {
// redirect them to the correct URL without the sigil to the correct path above.
app.get(
'/:roomIdOrAliasDirty',
identifyRoute('redirect-to-correct-archive-url-if-bad-sigil'),
redirectToCorrectArchiveUrlIfBadSigil
identifyRoute('redirect-to-correct-room-url-if-bad-sigil'),
redirectToCorrectRoomUrlIfBadSigil
);
}

View File

@ -6,7 +6,7 @@ const urlJoin = require('url-join');
const express = require('express');
const asyncHandler = require('../lib/express-async-handler');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const RouteTimeoutAbortError = require('../lib/errors/route-timeout-abort-error');
const UserClosedConnectionAbortError = require('../lib/errors/user-closed-connection-abort-error');
const identifyRoute = require('../middleware/identify-route-middleware');
@ -86,7 +86,7 @@ router.get(
const shouldIndex = !stopSearchEngineIndexingFromConfig;
const pageOptions = {
title: `Matrix Public Archive`,
title: `Matrix Viewer`,
description:
'Browse thousands of rooms using Matrix. The new portal into the Matrix ecosystem.',
entryPoint: 'client/js/entry-client-room-directory.js',

View File

@ -7,7 +7,7 @@ const express = require('express');
const asyncHandler = require('../lib/express-async-handler');
const StatusError = require('../lib/errors/status-error');
const redirectToCorrectArchiveUrlIfBadSigil = require('../middleware/redirect-to-correct-archive-url-if-bad-sigil-middleware');
const redirectToCorrectRoomUrlIfBadSigil = require('../middleware/redirect-to-correct-room-url-if-bad-sigil-middleware');
const identifyRoute = require('../middleware/identify-route-middleware');
const { HTTPResponseError } = require('../lib/fetch-endpoint');
@ -25,15 +25,15 @@ const getMessagesResponseFromEventId = require('../lib/matrix-utils/get-messages
const renderHydrogenVmRenderScriptToPageHtml = require('../hydrogen-render/render-hydrogen-vm-render-script-to-page-html');
const setHeadersToPreloadAssets = require('../lib/set-headers-to-preload-assets');
const setHeadersForDateTemporalContext = require('../lib/set-headers-for-date-temporal-context');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const { mxcUrlToHttpThumbnail } = require('matrix-public-archive-shared/lib/mxc-url-to-http');
const checkTextForNsfw = require('matrix-public-archive-shared/lib/check-text-for-nsfw');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const { mxcUrlToHttpThumbnail } = require('matrix-viewer-shared/lib/mxc-url-to-http');
const checkTextForNsfw = require('matrix-viewer-shared/lib/check-text-for-nsfw');
const {
MS_LOOKUP,
TIME_PRECISION_VALUES,
DIRECTION,
VALID_ENTITY_DESCRIPTOR_TO_SIGIL_MAP,
} = require('matrix-public-archive-shared/lib/reference-values');
} = require('matrix-viewer-shared/lib/reference-values');
const { ONE_DAY_IN_MS, ONE_HOUR_IN_MS, ONE_MINUTE_IN_MS, ONE_SECOND_IN_MS } = MS_LOOKUP;
const {
roundUpTimestampToUtcDay,
@ -48,7 +48,7 @@ const {
areTimestampsFromSameUtcHour,
areTimestampsFromSameUtcMinute,
areTimestampsFromSameUtcSecond,
} = require('matrix-public-archive-shared/lib/timestamp-utilities');
} = require('matrix-viewer-shared/lib/timestamp-utilities');
const config = require('../lib/config');
const basePath = config.get('basePath');
@ -58,7 +58,7 @@ assert(matrixServerUrl);
const matrixAccessToken = config.get('matrixAccessToken');
assert(matrixAccessToken);
const matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
const matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
const router = express.Router({
caseSensitive: true,
@ -69,10 +69,10 @@ const router = express.Router({
const validSigilList = Object.values(VALID_ENTITY_DESCRIPTOR_TO_SIGIL_MAP);
const sigilRe = new RegExp(`^(${validSigilList.join('|')})`);
function getErrorStringForTooManyMessages(archiveMessageLimit) {
function getErrorStringForTooManyMessages(messageLimit) {
const message =
`Too many messages were sent all within a second for us to display ` +
`(more than ${archiveMessageLimit} in one second). We're unable to redirect you to ` +
`(more than ${messageLimit} in one second). We're unable to redirect you to ` +
`a smaller time range to view them without losing a few between each page. ` +
`Since this is probably pretty rare, we've decided not to support it for now.`;
return message;
@ -88,7 +88,7 @@ function getRoomIdOrAliasFromReq(req) {
const sigil = VALID_ENTITY_DESCRIPTOR_TO_SIGIL_MAP[entityDescriptor];
if (!sigil) {
throw new Error(
`Unknown entityDescriptor=${entityDescriptor} has no sigil. This is an error with the Matrix Public Archive itself (please open an issue).`
`Unknown entityDescriptor=${entityDescriptor} has no sigil. This is an error with the Matrix Viewer itself (please open an issue).`
);
}
@ -96,7 +96,7 @@ function getRoomIdOrAliasFromReq(req) {
}
// eslint-disable-next-line max-statements, complexity
function parseArchiveRangeFromReq(req) {
function parseDateTimeInfoFromReq(req) {
const yyyy = parseInt(req.params.yyyy, 10);
// Month is the only zero-based index in this group
const mm = parseInt(req.params.mm, 10) - 1;
@ -165,11 +165,11 @@ function parseArchiveRangeFromReq(req) {
};
}
router.use(redirectToCorrectArchiveUrlIfBadSigil);
router.use(redirectToCorrectRoomUrlIfBadSigil);
router.get(
'/',
identifyRoute('app-archive-room-index'),
identifyRoute('app-room-index'),
asyncHandler(async function (req, res) {
const roomIdOrAlias = getRoomIdOrAliasFromReq(req);
@ -199,7 +199,7 @@ router.get(
// Redirect to a day with messages
res.redirect(
matrixPublicArchiveURLCreator.archiveUrlForDate(roomIdOrAlias, new Date(originServerTs), {
matrixViewerURLCreator.roomUrlForDate(roomIdOrAlias, new Date(originServerTs), {
// We can avoid passing along the `via` query parameter because we already
// joined the room above (see `ensureRoomJoined`).
//
@ -211,7 +211,7 @@ router.get(
router.get(
'/event/:eventId',
identifyRoute('app-archive-room-event'),
identifyRoute('app-room-event'),
asyncHandler(async function (req, res) {
// TODO: Fetch event to get `origin_server_ts` and redirect to
// /!roomId/2022/01/01?at=$eventId
@ -221,7 +221,7 @@ router.get(
router.get(
'/jump',
identifyRoute('app-archive-room-jump'),
identifyRoute('app-room-jump'),
// eslint-disable-next-line max-statements, complexity
asyncHandler(async function (req, res) {
const roomIdOrAlias = getRoomIdOrAliasFromReq(req);
@ -289,7 +289,7 @@ router.get(
try {
// We pull this fresh from the config for each request to ensure we have an
// updated value between each e2e test
const archiveMessageLimit = config.get('archiveMessageLimit');
const messageLimit = config.get('messageLimit');
let roomCreateEventId;
// Find the closest event to the given timestamp
@ -348,9 +348,9 @@ router.get(
// the next chunk in the desired direction.
// ==============================
//
// When jumping backwards, since a given room archive URL represents the end of
// the day/time-period looking backward (scroll is also anchored to the bottom),
// we just need to move the user to the time-period just prior the current one.
// When jumping backwards, since a given room URL represents the end of the
// day/time-period looking backward (scroll is also anchored to the bottom), we
// just need to move the user to the time-period just prior the current one.
//
// We are trying to avoid sending the user to the same time period they were just
// viewing. i.e, if they were visiting `/2020/01/02T16:00:00` (displays messages
@ -364,7 +364,7 @@ router.get(
// We choose `currentRangeStartTs` instead of `ts` (the jump point) because
// TODO: why? and we don't choose `currentRangeEndTs` because TODO: why? - I
// feel like I can't justify this, see
// https://github.com/matrix-org/matrix-public-archive/pull/167#discussion_r1170850432
// https://github.com/matrix-org/matrix-viewer/pull/167#discussion_r1170850432
const fromSameDay =
tsForClosestEvent && areTimestampsFromSameUtcDay(currentRangeStartTs, tsForClosestEvent);
const fromSameHour =
@ -414,7 +414,7 @@ router.get(
// We don't need to do anything. The next closest event is far enough away
// (greater than 1 day) where we don't need to worry about the URL at all and
// can just render whatever day that the closest event is from because the
// archives biggest time-period represented in the URL is a day.
// viewers biggest time-period represented in the URL is a day.
//
// We can display more than a day of content at a given URL (imagine lots of a
// quiet days in a room), but the URL will never represent a time-period
@ -426,7 +426,7 @@ router.get(
}
// When jumping forwards, the goal is to go forward 100 messages, so that when we
// view the room at that point going backwards 100 messages (which is how the
// archive works for any given date from the archive URL), we end up at the
// viewer works for any given date from the viewer URL), we end up at the
// perfect continuation spot in the room (seamless).
//
// XXX: This is flawed in the fact that when we go `/messages?dir=b` later, it
@ -446,7 +446,7 @@ router.get(
roomId,
eventId: eventIdForClosestEvent,
dir: DIRECTION.forward,
limit: archiveMessageLimit,
limit: messageLimit,
abortSignal: req.abortSignal,
});
@ -500,7 +500,7 @@ router.get(
// Back-track from the last message timestamp to the nearest date boundary.
// Because we're back-tracking a couple events here, when we paginate back out
// by the `archiveMessageLimit` later in the room route, it will gurantee some
// by the `messageLimit` later in the room route, it will gurantee some
// overlap with the previous page we jumped from so we don't lose any messages
// in the gap.
//
@ -511,11 +511,11 @@ router.get(
// the same timestamp and we will lose messages in the gap because it displays
// more than we thought.
//
// If the `/messages` response returns less than the `archiveMessageLimit`
// If the `/messages` response returns less than the `messageLimit`
// looking forwards, it means we're looking at the latest events in the room. We
// can simply just display the day that the latest event occured on or the given
// rangeEnd (whichever is later).
const haveReachedLatestMessagesInRoom = messageResData.chunk?.length < archiveMessageLimit;
const haveReachedLatestMessagesInRoom = messageResData.chunk?.length < messageLimit;
if (haveReachedLatestMessagesInRoom) {
const latestDesiredTs = Math.max(currentRangeEndTs, tsOfLastMessage);
const latestDesiredDate = new Date(latestDesiredTs);
@ -561,9 +561,7 @@ router.get(
// 501 Not Implemented: the server does not support the functionality required
// to fulfill the request
res.status(501);
res.send(
`/jump ran into a problem: ${getErrorStringForTooManyMessages(archiveMessageLimit)}`
);
res.send(`/jump ran into a problem: ${getErrorStringForTooManyMessages(messageLimit)}`);
return;
}
}
@ -661,7 +659,7 @@ router.get(
// Since we're going backwards, we already know where to go so we can navigate
// straight there.
res.redirect(
matrixPublicArchiveURLCreator.archiveUrlForDate(
matrixViewerURLCreator.roomUrlForDate(
predecessorRoomId,
// XXX: We should probably go fetch and use the timestamp from
// `predecessorLastKnownEventId` here but that requires an extra
@ -688,7 +686,7 @@ router.get(
if (successorRoomId) {
// Jump to the successor room and continue at the first event of the room
res.redirect(
matrixPublicArchiveURLCreator.archiveJumpUrlForRoom(successorRoomId, {
matrixViewerURLCreator.jumpUrlForRoom(successorRoomId, {
dir: DIRECTION.forward,
currentRangeStartTs: 0,
currentRangeEndTs: 0,
@ -731,7 +729,7 @@ router.get(
}
// Redirect to a day with messages
const archiveUrlToRedirecTo = matrixPublicArchiveURLCreator.archiveUrlForDate(
const urlToRedirecTo = matrixViewerURLCreator.roomUrlForDate(
roomIdOrAlias,
new Date(newOriginServerTs),
{
@ -740,7 +738,7 @@ router.get(
preferredPrecision,
}
);
res.redirect(archiveUrlToRedirecTo);
res.redirect(urlToRedirecTo);
})
);
@ -750,7 +748,7 @@ router.get(
// `path-to-regex` bug where the `?` wasn't attaching to the capture group, see
// https://github.com/pillarjs/path-to-regexp/issues/287
'/date/:yyyy(\\d{4})/:mm(\\d{2})/:dd(\\d{2}):time(T\\d\\d?:\\d\\d?((:\\d\\d?)?))?',
identifyRoute('app-archive-room-date'),
identifyRoute('app-room-date'),
// eslint-disable-next-line max-statements, complexity
asyncHandler(async function (req, res) {
const nowTs = Date.now();
@ -758,16 +756,16 @@ router.get(
// We pull this fresh from the config for each request to ensure we have an
// updated value between each e2e test
const archiveMessageLimit = config.get('archiveMessageLimit');
assert(archiveMessageLimit);
const messageLimit = config.get('messageLimit');
assert(messageLimit);
// Synapse has a max `/messages` limit of 1000
assert(
archiveMessageLimit <= 999,
'archiveMessageLimit needs to be in range [1, 999]. We can only get 1000 messages at a time from Synapse and we need a buffer of at least one to see if there are too many messages on a given day so you can only configure a max of 999. If you need more messages, we will have to implement pagination'
messageLimit <= 999,
'messageLimit needs to be in range [1, 999]. We can only get 1000 messages at a time from Synapse and we need a buffer of at least one to see if there are too many messages on a given day so you can only configure a max of 999. If you need more messages, we will have to implement pagination'
);
const { toTimestamp, yyyy, mm, dd, timeDefined, secondsDefined } =
parseArchiveRangeFromReq(req);
parseDateTimeInfoFromReq(req);
let precisionFromUrl = TIME_PRECISION_VALUES.none;
if (secondsDefined) {
@ -795,7 +793,7 @@ router.get(
// this for all places we `ensureRoomJoined`). But we need the `roomId` for use with
// the various Matrix API's anyway and `/join/{roomIdOrAlias}` -> `{ room_id }` is a
// great way to get it (see
// https://github.com/matrix-org/matrix-public-archive/issues/50).
// https://github.com/matrix-org/matrix-viewer/issues/50).
const viaServers = parseViaServersFromUserInput(req.query.via);
const roomId = await ensureRoomJoined(matrixAccessToken, roomIdOrAlias, {
viaServers,
@ -803,7 +801,7 @@ router.get(
});
// Do these in parallel to avoid the extra time in sequential round-trips
// (we want to display the archive page faster)
// (we want to display the page faster)
const [roomData, { events, stateEventMap }] = await Promise.all([
fetchRoomData(matrixAccessToken, roomId, { abortSignal: req.abortSignal }),
// We over-fetch messages outside of the range of the given day so that we
@ -816,24 +814,24 @@ router.get(
accessToken: matrixAccessToken,
roomId,
ts: toTimestamp,
// We fetch one more than the `archiveMessageLimit` so that we can see if there
// We fetch one more than the `messageLimit` so that we can see if there
// are too many messages from the given day. If we have over the
// `archiveMessageLimit` number of messages fetching from the given day, it's
// `messageLimit` number of messages fetching from the given day, it's
// acceptable to have them be from surrounding days. But if all 500 messages
// (for example) are from the same day, let's redirect to a smaller hour range
// to display.
limit: archiveMessageLimit + 1,
limit: messageLimit + 1,
abortSignal: req.abortSignal,
}),
]);
// Only `world_readable` rooms are viewable in the archive
// Only `world_readable` rooms are viewable
const allowedToViewRoom = roomData.historyVisibility === 'world_readable';
if (!allowedToViewRoom) {
throw new StatusError(
403,
`Only \`world_readable\` rooms can be viewed in the archive. ` +
`Only \`world_readable\` rooms can be viewed with Matrix Viewer. ` +
`${roomData.id} has m.room.history_visiblity=${roomData.historyVisibility} ` +
`(set by ${roomData.historyVisibilityEventMeta?.sender} on ` +
`${new Date(roomData.historyVisibilityEventMeta?.originServerTs).toISOString()})`
@ -848,15 +846,11 @@ router.get(
if (hasNavigatedBeforeStartOfRoom && roomData.predecessorRoomId) {
// Jump to the predecessor room at the date/time the user is trying to visit at
res.redirect(
matrixPublicArchiveURLCreator.archiveUrlForDate(
roomData.predecessorRoomId,
new Date(toTimestamp),
{
preferredPrecision: precisionFromUrl,
// XXX: Should we also try combining `viaServers` we used to get to this room?
viaServers: Array.from(roomData.predecessorViaServers || []),
}
)
matrixViewerURLCreator.roomUrlForDate(roomData.predecessorRoomId, new Date(toTimestamp), {
preferredPrecision: precisionFromUrl,
// XXX: Should we also try combining `viaServers` we used to get to this room?
viaServers: Array.from(roomData.predecessorViaServers || []),
})
);
return;
}
@ -876,15 +870,11 @@ router.get(
if (roomData.successorRoomId && isNavigatedPastSuccessor && !isNewestEventFromSameDay) {
// Jump to the successor room at the date/time the user is trying to visit at
res.redirect(
matrixPublicArchiveURLCreator.archiveUrlForDate(
roomData.successorRoomId,
new Date(toTimestamp),
{
preferredPrecision: precisionFromUrl,
// Just try to pass on the `viaServers` the user was using to get to this room
viaServers: Array.from(viaServers || []),
}
)
matrixViewerURLCreator.roomUrlForDate(roomData.successorRoomId, new Date(toTimestamp), {
preferredPrecision: precisionFromUrl,
// Just try to pass on the `viaServers` the user was using to get to this room
viaServers: Array.from(viaServers || []),
})
);
return;
}
@ -906,8 +896,8 @@ router.get(
);
const pageOptions = {
title: `${roomData.name} - Matrix Public Archive`,
description: `View the history of the ${roomData.name} room in the Matrix Public Archive`,
title: `${roomData.name} - Matrix Viewer`,
description: `View the history of the ${roomData.name} room in the Matrix Viewer`,
imageUrl:
roomData.avatarUrl &&
mxcUrlToHttpThumbnail({
@ -918,7 +908,7 @@ router.get(
blockedBySafeSearch: isNsfw,
entryPoint: 'client/js/entry-client-hydrogen.js',
locationUrl: urlJoin(basePath, req.originalUrl),
canonicalUrl: matrixPublicArchiveURLCreator.archiveUrlForDate(
canonicalUrl: matrixViewerURLCreator.roomUrlForDate(
roomData.canonicalAlias || roomIdOrAlias,
new Date(toTimestamp),
{
@ -954,7 +944,7 @@ router.get(
config: {
basePath,
matrixServerUrl,
archiveMessageLimit,
messageLimit,
},
},
abortSignal: req.abortSignal,

View File

@ -3,35 +3,35 @@
// Isomorphic script that runs in the browser and on the server for SSR (needs
// browser context) that renders Hydrogen to the `document.body`.
//
// Data is passed in via `window.matrixPublicArchiveContext`
// Data is passed in via `window.matrixViewerContext`
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
const { Platform, MediaRepository, createNavigation, createRouter } = require('hydrogen-view-sdk');
const { TIME_PRECISION_VALUES } = require('matrix-public-archive-shared/lib/reference-values');
const ArchiveRoomView = require('matrix-public-archive-shared/views/ArchiveRoomView');
const ArchiveHistory = require('matrix-public-archive-shared/lib/archive-history');
const supressBlankAnchorsReloadingThePage = require('matrix-public-archive-shared/lib/supress-blank-anchors-reloading-the-page');
const ArchiveRoomViewModel = require('matrix-public-archive-shared/viewmodels/ArchiveRoomViewModel');
const stubPowerLevelsObservable = require('matrix-public-archive-shared/lib/stub-powerlevels-observable');
const { TIME_PRECISION_VALUES } = require('matrix-viewer-shared/lib/reference-values');
const RoomView = require('matrix-viewer-shared/views/RoomView');
const MatrixViewerHistory = require('matrix-viewer-shared/lib/matrix-viewer-history');
const supressBlankAnchorsReloadingThePage = require('matrix-viewer-shared/lib/supress-blank-anchors-reloading-the-page');
const RoomViewModel = require('matrix-viewer-shared/viewmodels/RoomViewModel');
const stubPowerLevelsObservable = require('matrix-viewer-shared/lib/stub-powerlevels-observable');
const toTimestamp = window.matrixPublicArchiveContext.toTimestamp;
const toTimestamp = window.matrixViewerContext.toTimestamp;
assert(toTimestamp);
const precisionFromUrl = window.matrixPublicArchiveContext.precisionFromUrl;
const precisionFromUrl = window.matrixViewerContext.precisionFromUrl;
assert(Object.values(TIME_PRECISION_VALUES).includes(precisionFromUrl));
const roomData = window.matrixPublicArchiveContext.roomData;
const roomData = window.matrixViewerContext.roomData;
assert(roomData);
const events = window.matrixPublicArchiveContext.events;
const events = window.matrixViewerContext.events;
assert(events);
const stateEventMap = window.matrixPublicArchiveContext.stateEventMap;
const stateEventMap = window.matrixViewerContext.stateEventMap;
assert(stateEventMap);
const shouldIndex = window.matrixPublicArchiveContext.shouldIndex;
const shouldIndex = window.matrixViewerContext.shouldIndex;
assert(shouldIndex !== undefined);
const config = window.matrixPublicArchiveContext.config;
const config = window.matrixViewerContext.config;
assert(config);
assert(config.matrixServerUrl);
assert(config.basePath);
assert(config.archiveMessageLimit);
assert(config.messageLimit);
function addSupportClasses() {
const input = document.createElement('input');
@ -65,7 +65,7 @@ async function mountHydrogen() {
const navigation = createNavigation();
platform.setNavigation(navigation);
const archiveHistory = new ArchiveHistory(
const matrixViewerHistory = new MatrixViewerHistory(
// We just have to match what Hydrogen is doing here.
`#/session/123/room/${encodeURIComponent(roomData.id)}`
);
@ -75,7 +75,7 @@ async function mountHydrogen() {
// room and not include the session/room.
//
// Normally, people use `history: platform.history,`
history: archiveHistory,
history: matrixViewerHistory,
});
// Make it listen to changes from the history instance. And populate the
// `Navigation` with path segments to work from so `href`'s rendered on the
@ -101,15 +101,15 @@ async function mountHydrogen() {
},
};
const archiveRoomViewModel = new ArchiveRoomViewModel({
const roomViewModel = new RoomViewModel({
// Hydrogen options
platform: platform,
navigation: navigation,
urlRouter: urlRouter,
history: archiveHistory,
history: matrixViewerHistory,
// Our options
homeserverUrl: config.matrixServerUrl,
archiveMessageLimit: config.archiveMessageLimit,
messageLimit: config.messageLimit,
room,
// The timestamp from the URL that was originally visited
dayTimestampTo: toTimestamp,
@ -126,7 +126,7 @@ async function mountHydrogen() {
// ---------------------------------------------------------------------
// Render what we actually care about
const view = new ArchiveRoomView(archiveRoomViewModel);
const view = new RoomView(roomViewModel);
appElement.replaceChildren(view.mount());
addSupportClasses();

View File

@ -4,16 +4,16 @@
const { tileClassForEntry, viewClassForTile } = require('hydrogen-view-sdk');
const JumpToPreviousActivitySummaryTileViewModel = require('matrix-public-archive-shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel');
const JumpToPreviousActivitySummaryTileView = require('matrix-public-archive-shared/views/JumpToPreviousActivitySummaryTileView');
const JumpToNextActivitySummaryTileViewModel = require('matrix-public-archive-shared/viewmodels/JumpToNextActivitySummaryTileViewModel');
const JumpToNextActivitySummaryTileView = require('matrix-public-archive-shared/views/JumpToNextActivitySummaryTileView');
const JumpToPreviousActivitySummaryTileViewModel = require('matrix-viewer-shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel');
const JumpToPreviousActivitySummaryTileView = require('matrix-viewer-shared/views/JumpToPreviousActivitySummaryTileView');
const JumpToNextActivitySummaryTileViewModel = require('matrix-viewer-shared/viewmodels/JumpToNextActivitySummaryTileViewModel');
const JumpToNextActivitySummaryTileView = require('matrix-viewer-shared/views/JumpToNextActivitySummaryTileView');
function customTileClassForEntry(entry) {
switch (entry.eventType) {
case 'org.matrix.archive.jump_to_previous_activity_summary':
case 'org.matrix.viewer.jump_to_previous_activity_summary':
return JumpToPreviousActivitySummaryTileViewModel;
case 'org.matrix.archive.jump_to_next_activity_summary':
case 'org.matrix.viewer.jump_to_next_activity_summary':
return JumpToNextActivitySummaryTileViewModel;
default:
return tileClassForEntry(entry);
@ -22,9 +22,9 @@ function customTileClassForEntry(entry) {
function customViewClassForTile(vm) {
switch (vm.shape) {
case 'org.matrix.archive.jump_to_previous_activity_summary:shape':
case 'org.matrix.viewer.jump_to_previous_activity_summary:shape':
return JumpToPreviousActivitySummaryTileView;
case 'org.matrix.archive.jump_to_next_activity_summary:shape':
case 'org.matrix.viewer.jump_to_next_activity_summary:shape':
return JumpToNextActivitySummaryTileView;
default:
return viewClassForTile(vm);

View File

@ -6,7 +6,7 @@ const assert = require('./assert');
// Mock a full hash whenever someone asks via `history.get()` but when
// constructing URL's for use `href` etc, they should relative to the room
// (remove session and room from the hash).
class ArchiveHistory extends History {
class MatrixViewerHistory extends History {
constructor(baseHash) {
assert(baseHash);
super();
@ -34,7 +34,7 @@ class ArchiveHistory extends History {
replacingUrl = url;
}
// Hydrogen hash routing: This is the sign that Hydrogen is navigating back to the
// root. Because of our custom archive logic, the `#` is removed before it gets
// root. Because of our custom Matrix Viewer logic, the `#` is removed before it gets
// here. But we just want to make sure the hash gets cleared out while maintaining
// our path and query parameters.
//
@ -60,7 +60,7 @@ class ArchiveHistory extends History {
replacingUrl = url;
}
// Hydrogen hash routing: This is the sign that Hydrogen is navigating back to the
// root. Because of our custom archive logic, the `#` is removed before it gets
// root. Because of our custom Matrix Viewer logic, the `#` is removed before it gets
// here. But we just want to make sure the hash gets cleared out while maintaining
// our path and query parameters.
//
@ -94,4 +94,4 @@ class ArchiveHistory extends History {
}
}
module.exports = ArchiveHistory;
module.exports = MatrixViewerHistory;

View File

@ -6,14 +6,14 @@
const BASIC_ROOM_ALIAS_REGEX = /^(#(?:[^/:]+):(?:[^/]+))/;
// Returns `true` if redirecting, otherwise `false`
function redirectIfRoomAliasInHash(matrixPublicArchiveURLCreator, redirectCallback) {
function redirectIfRoomAliasInHash(matrixViewerURLCreator, redirectCallback) {
function handleHashChange() {
const pageHash = window.location.hash;
const match = pageHash.match(BASIC_ROOM_ALIAS_REGEX);
if (match) {
const roomAlias = match[0];
const newLocation = matrixPublicArchiveURLCreator.archiveUrlForRoom(roomAlias);
const newLocation = matrixViewerURLCreator.roomUrl(roomAlias);
console.log(`Saw room alias in hash, redirecting to newLocation=${newLocation}`);
window.location = newLocation;
if (redirectCallback) {

View File

@ -1,7 +1,7 @@
'use strict';
const assert = require('matrix-public-archive-shared/lib/assert');
const { MS_LOOKUP } = require('matrix-public-archive-shared/lib/reference-values');
const assert = require('matrix-viewer-shared/lib/assert');
const { MS_LOOKUP } = require('matrix-viewer-shared/lib/reference-values');
const { ONE_DAY_IN_MS, ONE_HOUR_IN_MS, ONE_MINUTE_IN_MS, ONE_SECOND_IN_MS } = MS_LOOKUP;
function roundUpTimestampToUtcDay(ts) {

View File

@ -2,11 +2,8 @@
const urlJoin = require('url-join');
const assert = require('matrix-public-archive-shared/lib/assert');
const {
DIRECTION,
TIME_PRECISION_VALUES,
} = require('matrix-public-archive-shared/lib/reference-values');
const assert = require('matrix-viewer-shared/lib/assert');
const { DIRECTION, TIME_PRECISION_VALUES } = require('matrix-viewer-shared/lib/reference-values');
function qsToUrlPiece(qs) {
if (qs.toString()) {
@ -55,7 +52,7 @@ class URLCreator {
return `${this._basePath}${qsToUrlPiece(qs)}`;
}
_getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias) {
_getUrlPathForRoomIdOrAlias(roomIdOrAlias) {
let urlPath;
// We don't `encodeURIComponent(...)` because the URL looks nicer without encoded things
if (roomIdOrAlias.startsWith('#')) {
@ -64,14 +61,14 @@ class URLCreator {
urlPath = `/roomid/${roomIdOrAlias.replace(/^!/, '')}`;
} else {
throw new Error(
'URLCreator._getArchiveUrlPathForRoomIdOrAlias(...): roomIdOrAlias should start with # (alias) or ! (room ID)'
'URLCreator._getUrlPathForRoomIdOrAlias(...): roomIdOrAlias should start with # (alias) or ! (room ID)'
);
}
return urlPath;
}
archiveUrlForRoom(roomIdOrAlias, { viaServers = [] } = {}) {
roomUrl(roomIdOrAlias, { viaServers = [] } = {}) {
assert(roomIdOrAlias);
assert(Array.isArray(viaServers));
let qs = new URLSearchParams();
@ -79,12 +76,12 @@ class URLCreator {
qs.append('via', viaServer);
});
const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias);
const urlPath = this._getUrlPathForRoomIdOrAlias(roomIdOrAlias);
return `${urlJoin(this._basePath, `${urlPath}`)}${qsToUrlPiece(qs)}`;
}
archiveUrlForDate(
roomUrlForDate(
roomIdOrAlias,
date,
{ preferredPrecision = null, viaServers = [], scrollStartEventId } = {}
@ -110,7 +107,7 @@ class URLCreator {
qs.append('at', scrollStartEventId);
}
const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias);
const urlPath = this._getUrlPathForRoomIdOrAlias(roomIdOrAlias);
// Gives the date in YYYY/mm/dd format.
// date.toISOString() -> 2022-02-16T23:20:04.709Z
@ -134,7 +131,7 @@ class URLCreator {
)}${qsToUrlPiece(qs)}`;
}
archiveJumpUrlForRoom(
jumpUrlForRoom(
roomIdOrAlias,
{
dir,
@ -168,7 +165,7 @@ class URLCreator {
qs.append('via', viaServer);
});
const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias);
const urlPath = this._getUrlPathForRoomIdOrAlias(roomIdOrAlias);
return `${urlJoin(this._basePath, `${urlPath}/jump`)}${qsToUrlPiece(qs)}`;
}

View File

@ -3,38 +3,38 @@
// Isomorphic script that runs in the browser and on the server for SSR (needs
// browser context) that renders Hydrogen to the `document.body`.
//
// Data is passed in via `window.matrixPublicArchiveContext`
// Data is passed in via `window.matrixViewerContext`
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
const { Platform, Navigation, createRouter } = require('hydrogen-view-sdk');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const ArchiveHistory = require('matrix-public-archive-shared/lib/archive-history');
const supressBlankAnchorsReloadingThePage = require('matrix-public-archive-shared/lib/supress-blank-anchors-reloading-the-page');
const redirectIfRoomAliasInHash = require('matrix-public-archive-shared/lib/redirect-if-room-alias-in-hash');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const MatrixViewerHistory = require('matrix-viewer-shared/lib/matrix-viewer-history');
const supressBlankAnchorsReloadingThePage = require('matrix-viewer-shared/lib/supress-blank-anchors-reloading-the-page');
const redirectIfRoomAliasInHash = require('matrix-viewer-shared/lib/redirect-if-room-alias-in-hash');
const RoomDirectoryView = require('matrix-public-archive-shared/views/RoomDirectoryView');
const RoomDirectoryViewModel = require('matrix-public-archive-shared/viewmodels/RoomDirectoryViewModel');
const RoomDirectoryView = require('matrix-viewer-shared/views/RoomDirectoryView');
const RoomDirectoryViewModel = require('matrix-viewer-shared/viewmodels/RoomDirectoryViewModel');
const rooms = window.matrixPublicArchiveContext.rooms;
const rooms = window.matrixViewerContext.rooms;
assert(rooms);
const roomFetchError = window.matrixPublicArchiveContext.roomFetchError;
const nextPaginationToken = window.matrixPublicArchiveContext.nextPaginationToken;
const prevPaginationToken = window.matrixPublicArchiveContext.prevPaginationToken;
const pageSearchParameters = window.matrixPublicArchiveContext.pageSearchParameters;
const config = window.matrixPublicArchiveContext.config;
const roomFetchError = window.matrixViewerContext.roomFetchError;
const nextPaginationToken = window.matrixViewerContext.nextPaginationToken;
const prevPaginationToken = window.matrixViewerContext.prevPaginationToken;
const pageSearchParameters = window.matrixViewerContext.pageSearchParameters;
const config = window.matrixViewerContext.config;
assert(config);
assert(config.matrixServerUrl);
assert(config.matrixServerName);
assert(config.basePath);
const matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(config.basePath);
const matrixViewerURLCreator = new MatrixViewerURLCreator(config.basePath);
supressBlankAnchorsReloadingThePage();
let roomDirectoryViewModel;
let isRedirecting = false;
isRedirecting = redirectIfRoomAliasInHash(matrixPublicArchiveURLCreator, () => {
isRedirecting = redirectIfRoomAliasInHash(matrixViewerURLCreator, () => {
isRedirecting = true;
if (roomDirectoryViewModel) {
roomDirectoryViewModel.setPageRedirectingFromUrlHash(true);
@ -69,10 +69,10 @@ async function mountHydrogen() {
const navigation = new Navigation(allowsChild);
platform.setNavigation(navigation);
const archiveHistory = new ArchiveHistory(`#`);
const matrixViewerHistory = new MatrixViewerHistory(`#`);
const urlRouter = createRouter({
navigation,
history: archiveHistory,
history: matrixViewerHistory,
});
// Make it listen to changes from the history instance. And populate the
// `Navigation` with path segments to work from so `href`'s rendered on the
@ -83,12 +83,12 @@ async function mountHydrogen() {
// Hydrogen options
navigation: navigation,
urlRouter: urlRouter,
history: archiveHistory,
history: matrixViewerHistory,
// Our options
basePath: config.basePath,
homeserverUrl: config.matrixServerUrl,
homeserverName: config.matrixServerName,
matrixPublicArchiveURLCreator,
matrixViewerURLCreator,
rooms,
roomFetchError,
pageSearchParameters,

View File

@ -2,8 +2,8 @@
const { ViewModel, avatarInitials, getIdentifierColorNumber } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const { mxcUrlToHttpThumbnail } = require('matrix-public-archive-shared/lib/mxc-url-to-http');
const assert = require('matrix-viewer-shared/lib/assert');
const { mxcUrlToHttpThumbnail } = require('matrix-viewer-shared/lib/mxc-url-to-http');
class AvatarViewModel extends ViewModel {
constructor(options) {

View File

@ -2,23 +2,23 @@
const { ViewModel } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
class CalendarViewModel extends ViewModel {
constructor(options) {
super(options);
const { activeDate, calendarDate, room, matrixPublicArchiveURLCreator } = options;
const { activeDate, calendarDate, room, matrixViewerURLCreator } = options;
assert(activeDate);
assert(calendarDate);
assert(room);
assert(matrixPublicArchiveURLCreator);
assert(matrixViewerURLCreator);
// The day being shown in the archive
// The day being shown
this._activeDate = activeDate;
// The month displayed in the calendar
this._calendarDate = calendarDate;
this._room = room;
this._matrixPublicArchiveURLCreator = matrixPublicArchiveURLCreator;
this._matrixViewerURLCreator = matrixViewerURLCreator;
}
get activeDate() {
@ -37,8 +37,8 @@ class CalendarViewModel extends ViewModel {
this.emitChange('calendarDate');
}
archiveUrlForDate(date) {
return this._matrixPublicArchiveURLCreator.archiveUrlForDate(
roomUrlForDate(date) {
return this._matrixViewerURLCreator.roomUrlForDate(
this._room.canonicalAlias || this._room.id,
date
);

View File

@ -2,7 +2,7 @@
const { ViewModel } = require('hydrogen-view-sdk');
const LOCAL_STORAGE_KEYS = require('matrix-public-archive-shared/lib/local-storage-keys');
const LOCAL_STORAGE_KEYS = require('matrix-viewer-shared/lib/local-storage-keys');
class DeveloperOptionsContentViewModel extends ViewModel {
constructor(options) {

View File

@ -2,8 +2,8 @@
const { SimpleTile } = require('hydrogen-view-sdk');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const assert = require('../lib/assert');
class JumpToNextActivitySummaryTileViewModel extends SimpleTile {
@ -13,11 +13,11 @@ class JumpToNextActivitySummaryTileViewModel extends SimpleTile {
const basePath = this._entry?.content?.['basePath'];
assert(basePath);
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
this._matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
}
get shape() {
return 'org.matrix.archive.jump_to_next_activity_summary:shape';
return 'org.matrix.viewer.jump_to_next_activity_summary:shape';
}
get daySummaryKind() {
@ -49,7 +49,7 @@ class JumpToNextActivitySummaryTileViewModel extends SimpleTile {
}
get jumpToNextActivityUrl() {
return this._matrixPublicArchiveURLCreator.archiveJumpUrlForRoom(
return this._matrixViewerURLCreator.jumpUrlForRoom(
this._entry?.content?.['canonicalAlias'] || this._entry.roomId,
{
dir: DIRECTION.forward,

View File

@ -2,8 +2,8 @@
const { SimpleTile } = require('hydrogen-view-sdk');
const { DIRECTION } = require('matrix-public-archive-shared/lib/reference-values');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const { DIRECTION } = require('matrix-viewer-shared/lib/reference-values');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const assert = require('../lib/assert');
class JumpToPreviousActivitySummaryTileViewModel extends SimpleTile {
@ -13,11 +13,11 @@ class JumpToPreviousActivitySummaryTileViewModel extends SimpleTile {
const basePath = this._entry?.content?.['basePath'];
assert(basePath);
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
this._matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
}
get shape() {
return 'org.matrix.archive.jump_to_previous_activity_summary:shape';
return 'org.matrix.viewer.jump_to_previous_activity_summary:shape';
}
// The start of the range to use as a jumping off point to the previous activity
@ -41,7 +41,7 @@ class JumpToPreviousActivitySummaryTileViewModel extends SimpleTile {
}
get jumpToPreviousActivityUrl() {
return this._matrixPublicArchiveURLCreator.archiveJumpUrlForRoom(
return this._matrixViewerURLCreator.jumpUrlForRoom(
this._entry?.content?.['canonicalAlias'] || this._entry.roomId,
{
dir: DIRECTION.backward,

View File

@ -2,8 +2,8 @@
const { ViewModel } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const assert = require('matrix-viewer-shared/lib/assert');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
class RoomCardViewModel extends ViewModel {
constructor(options) {
@ -14,7 +14,7 @@ class RoomCardViewModel extends ViewModel {
assert(homeserverUrlToPullMediaFrom);
assert(viaServers);
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
this._matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
this._roomId = room.room_id;
this._canonicalAlias = room.canonical_alias;
@ -57,14 +57,11 @@ class RoomCardViewModel extends ViewModel {
return this._topic;
}
get archiveRoomUrl() {
return this._matrixPublicArchiveURLCreator.archiveUrlForRoom(
this._canonicalAlias || this._roomId,
{
// Only include via servers when we have to fallback to the room ID
viaServers: this._canonicalAlias ? undefined : this._viaServers,
}
);
get roomUrl() {
return this._matrixViewerURLCreator.roomUrl(this._canonicalAlias || this._roomId, {
// Only include via servers when we have to fallback to the room ID
viaServers: this._canonicalAlias ? undefined : this._viaServers,
});
}
get blockedBySafeSearch() {

View File

@ -2,13 +2,13 @@
const { ViewModel, ObservableMap, ApplyMap } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
const LOCAL_STORAGE_KEYS = require('matrix-public-archive-shared/lib/local-storage-keys');
const ModalViewModel = require('matrix-public-archive-shared/viewmodels/ModalViewModel');
const HomeserverSelectionModalContentViewModel = require('matrix-public-archive-shared/viewmodels/HomeserverSelectionModalContentViewModel');
const RoomCardViewModel = require('matrix-public-archive-shared/viewmodels/RoomCardViewModel');
const checkTextForNsfw = require('matrix-public-archive-shared/lib/check-text-for-nsfw');
const LOCAL_STORAGE_KEYS = require('matrix-viewer-shared/lib/local-storage-keys');
const ModalViewModel = require('matrix-viewer-shared/viewmodels/ModalViewModel');
const HomeserverSelectionModalContentViewModel = require('matrix-viewer-shared/viewmodels/HomeserverSelectionModalContentViewModel');
const RoomCardViewModel = require('matrix-viewer-shared/viewmodels/RoomCardViewModel');
const checkTextForNsfw = require('matrix-viewer-shared/lib/check-text-for-nsfw');
const { DIRECTION } = require('../lib/reference-values');
const DEFAULT_SERVER_LIST = ['matrix.org', 'gitter.im'];
@ -20,7 +20,7 @@ class RoomDirectoryViewModel extends ViewModel {
basePath,
homeserverUrl,
homeserverName,
matrixPublicArchiveURLCreator,
matrixViewerURLCreator,
rooms,
roomFetchError,
pageSearchParameters,
@ -30,14 +30,14 @@ class RoomDirectoryViewModel extends ViewModel {
assert(basePath);
assert(homeserverUrl);
assert(homeserverName);
assert(matrixPublicArchiveURLCreator);
assert(matrixViewerURLCreator);
assert(rooms);
this._roomFetchError = roomFetchError;
this._homeserverUrl = homeserverUrl;
this._homeserverName = homeserverName;
this._matrixPublicArchiveURLCreator = matrixPublicArchiveURLCreator;
this._matrixViewerURLCreator = matrixViewerURLCreator;
this._isPageRedirectingFromUrlHash = false;
@ -142,7 +142,7 @@ class RoomDirectoryViewModel extends ViewModel {
}
get roomDirectoryUrl() {
return this._matrixPublicArchiveURLCreator.roomDirectoryUrl();
return this._matrixViewerURLCreator.roomDirectoryUrl();
}
get pageSearchParameters() {
@ -301,7 +301,7 @@ class RoomDirectoryViewModel extends ViewModel {
get nextPageUrl() {
if (this._nextPaginationToken) {
return this._matrixPublicArchiveURLCreator.roomDirectoryUrl({
return this._matrixViewerURLCreator.roomDirectoryUrl({
homeserver: this.homeserverSelection,
searchTerm: this.searchTerm,
paginationToken: this._nextPaginationToken,
@ -314,7 +314,7 @@ class RoomDirectoryViewModel extends ViewModel {
get prevPageUrl() {
if (this._prevPaginationToken) {
return this._matrixPublicArchiveURLCreator.roomDirectoryUrl({
return this._matrixViewerURLCreator.roomDirectoryUrl({
homeserver: this.homeserverSelection,
searchTerm: this.searchTerm,
paginationToken: this._prevPaginationToken,

View File

@ -11,23 +11,19 @@ const {
encodeEventIdKey,
} = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
const ModalViewModel = require('matrix-public-archive-shared/viewmodels/ModalViewModel');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const CalendarViewModel = require('matrix-public-archive-shared/viewmodels/CalendarViewModel');
const TimeSelectorViewModel = require('matrix-public-archive-shared/viewmodels/TimeSelectorViewModel');
const DeveloperOptionsContentViewModel = require('matrix-public-archive-shared/viewmodels/DeveloperOptionsContentViewModel');
const RightPanelContentView = require('matrix-public-archive-shared/views/RightPanelContentView');
const AvatarViewModel = require('matrix-public-archive-shared/viewmodels/AvatarViewModel');
const {
customTileClassForEntry,
} = require('matrix-public-archive-shared/lib/custom-tile-utilities');
const stubPowerLevelsObservable = require('matrix-public-archive-shared/lib/stub-powerlevels-observable');
const { TIME_PRECISION_VALUES } = require('matrix-public-archive-shared/lib/reference-values');
const {
areTimestampsFromSameUtcDay,
} = require('matrix-public-archive-shared/lib/timestamp-utilities');
const ModalViewModel = require('matrix-viewer-shared/viewmodels/ModalViewModel');
const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator');
const CalendarViewModel = require('matrix-viewer-shared/viewmodels/CalendarViewModel');
const TimeSelectorViewModel = require('matrix-viewer-shared/viewmodels/TimeSelectorViewModel');
const DeveloperOptionsContentViewModel = require('matrix-viewer-shared/viewmodels/DeveloperOptionsContentViewModel');
const RightPanelContentView = require('matrix-viewer-shared/views/RightPanelContentView');
const AvatarViewModel = require('matrix-viewer-shared/viewmodels/AvatarViewModel');
const { customTileClassForEntry } = require('matrix-viewer-shared/lib/custom-tile-utilities');
const stubPowerLevelsObservable = require('matrix-viewer-shared/lib/stub-powerlevels-observable');
const { TIME_PRECISION_VALUES } = require('matrix-viewer-shared/lib/reference-values');
const { areTimestampsFromSameUtcDay } = require('matrix-viewer-shared/lib/timestamp-utilities');
let txnCount = 0;
function getFakeEventId() {
@ -61,13 +57,13 @@ function makeEventEntryFromEventJson(eventJson, memberEvent) {
return eventEntry;
}
class ArchiveRoomViewModel extends ViewModel {
class RoomViewModel extends ViewModel {
// eslint-disable-next-line max-statements, complexity
constructor(options) {
super(options);
const {
homeserverUrl,
archiveMessageLimit,
messageLimit,
room,
dayTimestampTo,
precisionFromUrl,
@ -79,7 +75,7 @@ class ArchiveRoomViewModel extends ViewModel {
basePath,
} = options;
assert(homeserverUrl);
assert(archiveMessageLimit);
assert(messageLimit);
assert(room);
assert(dayTimestampTo);
assert(Object.values(TIME_PRECISION_VALUES).includes(precisionFromUrl));
@ -94,7 +90,7 @@ class ArchiveRoomViewModel extends ViewModel {
this._room = room;
this._dayTimestampTo = dayTimestampTo;
this._currentTopPositionEventEntry = null;
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
this._matrixViewerURLCreator = new MatrixViewerURLCreator(basePath);
this._basePath = basePath;
const navigation = this.navigation;
@ -139,12 +135,12 @@ class ArchiveRoomViewModel extends ViewModel {
const initialActiveDate = bottomMostEventDate || initialDate;
this._calendarViewModel = new CalendarViewModel({
// The day being shown in the archive
// The day being shown
activeDate: initialActiveDate,
// The month displayed in the calendar
calendarDate: initialActiveDate,
room,
matrixPublicArchiveURLCreator: this._matrixPublicArchiveURLCreator,
matrixViewerURLCreator: this._matrixViewerURLCreator,
});
const shouldShowTimeSelector =
@ -154,7 +150,7 @@ class ArchiveRoomViewModel extends ViewModel {
(precisionFromUrl !== TIME_PRECISION_VALUES.none && !events.length) ||
// Only show the time selector when we're showing events all from the same day and
// there are more events than the limit
(events.length > archiveMessageLimit &&
(events.length > messageLimit &&
areTimestampsFromSameUtcDay(timelineRangeStartTimestamp, timelineRangeEndTimestamp));
this._timeSelectorViewModel = new TimeSelectorViewModel({
@ -162,7 +158,7 @@ class ArchiveRoomViewModel extends ViewModel {
// The time (within the given date) being displayed in the time scrubber.
activeDate: initialActiveDate,
// Prevent extra precision if it's not needed. We only need to show seconds if
// the page-loaded archive URL is worried about seconds.
// the page-loaded URL is worried about seconds.
preferredPrecision:
// Default to minutes for the time selector otherwise use whatever more fine
// grained precision that the URL is using
@ -171,7 +167,7 @@ class ArchiveRoomViewModel extends ViewModel {
: precisionFromUrl,
timelineRangeStartTimestamp,
timelineRangeEndTimestamp,
matrixPublicArchiveURLCreator: this._matrixPublicArchiveURLCreator,
matrixViewerURLCreator: this._matrixViewerURLCreator,
});
this._developerOptionsContentViewModel = new DeveloperOptionsContentViewModel(
@ -334,11 +330,11 @@ class ArchiveRoomViewModel extends ViewModel {
}
get roomDirectoryUrl() {
return this._matrixPublicArchiveURLCreator.roomDirectoryUrl();
return this._matrixViewerURLCreator.roomDirectoryUrl();
}
get roomPermalink() {
return this._matrixPublicArchiveURLCreator.permalinkForRoom(this._room.id);
return this._matrixViewerURLCreator.permalinkForRoom(this._room.id);
}
get roomName() {
@ -396,7 +392,7 @@ class ArchiveRoomViewModel extends ViewModel {
if (daySummaryKind !== 'no-events-at-all') {
events.unshift({
event_id: getFakeEventId(),
type: 'org.matrix.archive.jump_to_previous_activity_summary',
type: 'org.matrix.viewer.jump_to_previous_activity_summary',
room_id: this._room.id,
// Even though this isn't used for sort, just using the time where the event
// would logically be (before any of the other events in the timeline)
@ -418,7 +414,7 @@ class ArchiveRoomViewModel extends ViewModel {
// on the day requested. Also allow the user to jump to the next activity in the room.
events.push({
event_id: getFakeEventId(),
type: 'org.matrix.archive.jump_to_next_activity_summary',
type: 'org.matrix.viewer.jump_to_next_activity_summary',
room_id: this._room.id,
// Even though this isn't used for sort, just using the time where the event
// would logically be (at the end of the day)
@ -514,4 +510,4 @@ class ArchiveRoomViewModel extends ViewModel {
}
}
module.exports = ArchiveRoomViewModel;
module.exports = RoomViewModel;

View File

@ -1,8 +1,8 @@
'use strict';
const { ViewModel } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const { TIME_PRECISION_VALUES } = require('matrix-public-archive-shared/lib/reference-values');
const assert = require('matrix-viewer-shared/lib/assert');
const { TIME_PRECISION_VALUES } = require('matrix-viewer-shared/lib/reference-values');
class TimeSelectorViewModel extends ViewModel {
constructor(options) {
@ -13,11 +13,11 @@ class TimeSelectorViewModel extends ViewModel {
preferredPrecision = TIME_PRECISION_VALUES.minutes,
timelineRangeStartTimestamp,
timelineRangeEndTimestamp,
matrixPublicArchiveURLCreator,
matrixViewerURLCreator,
} = options;
assert(room);
assert(activeDate);
assert(matrixPublicArchiveURLCreator);
assert(matrixViewerURLCreator);
assert(
Object.values(TIME_PRECISION_VALUES).includes(preferredPrecision),
`TimeSelectorViewModel: options.preferredPrecision must be one of ${JSON.stringify(
@ -33,7 +33,7 @@ class TimeSelectorViewModel extends ViewModel {
this._timelineRangeStartTimestamp = timelineRangeStartTimestamp;
this._timelineRangeEndTimestamp = timelineRangeEndTimestamp;
this._matrixPublicArchiveURLCreator = matrixPublicArchiveURLCreator;
this._matrixViewerURLCreator = matrixViewerURLCreator;
this._isDragging = false;
}
@ -49,7 +49,7 @@ class TimeSelectorViewModel extends ViewModel {
}
get goToActiveDateUrl() {
return this._matrixPublicArchiveURLCreator.archiveUrlForDate(
return this._matrixViewerURLCreator.roomUrlForDate(
this._room.canonicalAlias || this._room.id,
this.activeDate,
{ preferredPrecision: this.preferredPrecision }

View File

@ -1,11 +1,9 @@
'use strict';
// Be mindful to do all date operations in UTC (the archive is all in UTC date/times)
// Be mindful to do all date operations in UTC (Matrix Viewer is all in UTC date/times)
const { TemplateView } = require('hydrogen-view-sdk');
const {
areTimestampsFromSameUtcDay,
} = require('matrix-public-archive-shared/lib/timestamp-utilities');
const { areTimestampsFromSameUtcDay } = require('matrix-viewer-shared/lib/timestamp-utilities');
// Get the number of days in the given month where the `inputDate` lies.
//
@ -156,7 +154,7 @@ class CalendarView extends TemplateView {
dayNumberDate.setUTCDate(i + 1);
const isDayInFuture = dayNumberDate.getTime() - todayTs > 0;
// The current day displayed in the archive
// The current day displayed
const isActive = areTimestampsFromSameUtcDay(
dayNumberDate.getTime(),
vm.activeDate.getTime()
@ -184,7 +182,7 @@ class CalendarView extends TemplateView {
CalendarView_dayLink_disabled: isDayInFuture,
},
// Disable navigation to future days
href: isDayInFuture ? null : vm.archiveUrlForDate(dayNumberDate),
href: isDayInFuture ? null : vm.roomUrlForDate(dayNumberDate),
},
[String(dayNumberDate.getUTCDate())]
),

View File

@ -2,9 +2,9 @@
const { TemplateView } = require('hydrogen-view-sdk');
const assert = require('matrix-public-archive-shared/lib/assert');
const CalendarView = require('matrix-public-archive-shared/views/CalendarView');
const TimeSelectorView = require('matrix-public-archive-shared/views/TimeSelectorView');
const assert = require('matrix-viewer-shared/lib/assert');
const CalendarView = require('matrix-viewer-shared/views/CalendarView');
const TimeSelectorView = require('matrix-viewer-shared/views/TimeSelectorView');
class RightPanelContentView extends TemplateView {
render(t, vm) {
@ -50,7 +50,7 @@ class RightPanelContentView extends TemplateView {
},
[
t.p([
`This room is accessible in the archive because it was set to ` +
`This room is accessible because it was set to ` +
`${historyVisibilityDisplayValue} by ${historyVisibilitySender} on ${historyVisibilitySetDatePiece}.`,
]),
t.p([
@ -59,7 +59,7 @@ class RightPanelContentView extends TemplateView {
t.a(
{
className: 'external-link RightPanelContentView_footerLink',
href: 'https://github.com/matrix-org/matrix-public-archive/blob/main/docs/faq.md#how-do-i-opt-out-and-keep-my-room-from-being-indexed-by-search-engines',
href: 'https://github.com/matrix-org/matrix-viewer/blob/main/docs/faq.md#how-do-i-opt-out-and-keep-my-room-from-being-indexed-by-search-engines',
target: '_blank',
},
'more info'

View File

@ -57,7 +57,7 @@ class RoomCardView extends TemplateView {
return false;
}
return vm.archiveRoomUrl;
return vm.roomUrl;
},
// Since this is the same button as the "View" link, just tab to
// that instead
@ -107,7 +107,7 @@ class RoomCardView extends TemplateView {
t.a(
{
className: 'RoomCardView_alias',
href: vm.archiveRoomUrl,
href: vm.roomUrl,
// Since this is the same button as the "View" link, just tab to
// that instead
tabindex: -1,
@ -145,7 +145,7 @@ class RoomCardView extends TemplateView {
return false;
}
return vm.archiveRoomUrl;
return vm.roomUrl;
},
title: (vm) => {
if (vm.blockedBySafeSearch) {

View File

@ -2,7 +2,7 @@
const { TemplateView, ListView, text } = require('hydrogen-view-sdk');
const ModalView = require('matrix-public-archive-shared/views/ModalView');
const ModalView = require('matrix-viewer-shared/views/ModalView');
const HomeserverSelectionModalContentView = require('./HomeserverSelectionModalContentView');
const MatrixLogoView = require('./MatrixLogoView');
const RoomCardView = require('./RoomCardView');
@ -117,7 +117,7 @@ class RoomDirectoryView extends TemplateView {
t.a(
{
className: 'RoomDirectoryView_matrixLogo',
title: 'Matrix Public Archive',
title: 'Matrix Viewer',
href: vm.roomDirectoryUrl,
},
[t.view(new MatrixLogoView(vm))]
@ -217,9 +217,9 @@ class RoomDirectoryView extends TemplateView {
[
t.h3('❗ Unable to fetch rooms from room directory'),
t.p({}, [
`This may be a temporary problem with the homeserver where the room directory lives (${vm.pageSearchParameters.homeserver}) or the homeserver that the archive is pulling from (${vm.homeserverName}). You can try adjusting your search or select a different homeserver to look at. If this problem persists, please check the homeserver status and with a homeserver admin first, then open a `,
`This may be a temporary problem with the homeserver where the room directory lives (${vm.pageSearchParameters.homeserver}) or the remote homeserver that we are pulling from (${vm.homeserverName}). You can try adjusting your search or select a different homeserver to look at. If this problem persists, please check the homeserver status and with a homeserver admin first, then open a `,
t.a(
{ href: 'https://github.com/matrix-org/matrix-public-archive/issues/new' },
{ href: 'https://github.com/matrix-org/matrix-viewer/issues/new' },
'bug report'
),
` with this whole section copy-pasted into the issue.`,
@ -248,7 +248,7 @@ class RoomDirectoryView extends TemplateView {
t.p({}, [
`We're showing as much detail as we know so you're not frustrated by a generic message with no feedback on how to move forward. This also makes it easier for you to write a `,
t.a(
{ href: 'https://github.com/matrix-org/matrix-public-archive/issues/new' },
{ href: 'https://github.com/matrix-org/matrix-viewer/issues/new' },
'bug report'
),
` with all the details necessary for us to triage it.`,
@ -256,10 +256,7 @@ class RoomDirectoryView extends TemplateView {
t.p({}, t.strong(`Isn't this a security risk?`)),
t.p({}, [
`Not really. Usually, people are worried about returning details because it makes it easier for people to probe the system by getting better feedback about what's going wrong to craft exploits. But the `,
t.a(
{ href: 'https://github.com/matrix-org/matrix-public-archive' },
'Matrix Public Archive'
),
t.a({ href: 'https://github.com/matrix-org/matrix-viewer' }, 'Matrix Viewer'),
` is already open source so the details of the app are already public and you can run your own instance against the same homeservers that we are to find problems.`,
]),
t.p({}, [
@ -273,7 +270,7 @@ class RoomDirectoryView extends TemplateView {
t.p({}, [
`If you have ideas on how we can better present these errors, please `,
t.a(
{ href: 'https://github.com/matrix-org/matrix-public-archive/issues' },
{ href: 'https://github.com/matrix-org/matrix-viewer/issues' },
'create an issue'
),
`.`,

View File

@ -8,12 +8,10 @@ const {
LightboxView,
} = require('hydrogen-view-sdk');
const {
customViewClassForTile,
} = require('matrix-public-archive-shared/lib/custom-tile-utilities');
const { customViewClassForTile } = require('matrix-viewer-shared/lib/custom-tile-utilities');
const DeveloperOptionsContentView = require('matrix-public-archive-shared/views/DeveloperOptionsContentView');
const ModalView = require('matrix-public-archive-shared/views/ModalView');
const DeveloperOptionsContentView = require('matrix-viewer-shared/views/DeveloperOptionsContentView');
const ModalView = require('matrix-viewer-shared/views/ModalView');
class RoomHeaderView extends TemplateView {
render(t, vm) {
@ -90,13 +88,13 @@ class DisabledComposerView extends TemplateView {
(vm) => vm.currentTopPositionEventEntry,
(_currentTopPositionEventEntry, t, vm) => {
const activeDate = new Date(
// If the date from our `archiveRoomViewModel` is available, use that
// If the date from our `roomViewModel` is available, use that
vm?.currentTopPositionEventEntry?.timestamp ||
// Otherwise, use our initial `dayTimestampTo`
vm.dayTimestampTo
);
const dateString = activeDate.toISOString().split('T')[0];
return t.span(`You're viewing an archive of events from ${dateString}. Use a `);
return t.span(`You're viewing a snapshot of events from ${dateString}. Use a `);
}
),
t.a(
@ -113,7 +111,7 @@ class DisabledComposerView extends TemplateView {
}
}
class ArchiveRoomView extends TemplateView {
class RoomView extends TemplateView {
constructor(vm) {
super(vm);
@ -131,7 +129,7 @@ class ArchiveRoomView extends TemplateView {
const rootElement = t.div(
{
className: {
ArchiveRoomView: true,
RoomView: true,
'right-shown': (vm) => vm.shouldShowRightPanel,
},
},
@ -156,9 +154,9 @@ class ArchiveRoomView extends TemplateView {
});
}
),
t.main({ className: 'ArchiveRoomView_mainArea' }, [
t.main({ className: 'RoomView_mainArea' }, [
t.view(new RoomHeaderView(vm)),
t.main({ className: 'ArchiveRoomView_mainBody' }, [
t.main({ className: 'RoomView_mainBody' }, [
t.view(new TimelineView(vm.timelineViewModel, customViewClassForTile)),
t.view(new DisabledComposerView(vm)),
]),
@ -218,4 +216,4 @@ class ArchiveRoomView extends TemplateView {
}
}
module.exports = ArchiveRoomView;
module.exports = RoomView;

View File

@ -1,13 +1,10 @@
'use strict';
const assert = require('matrix-public-archive-shared/lib/assert');
const assert = require('matrix-viewer-shared/lib/assert');
const { TemplateView } = require('hydrogen-view-sdk');
const {
MS_LOOKUP,
TIME_PRECISION_VALUES,
} = require('matrix-public-archive-shared/lib/reference-values');
const { MS_LOOKUP, TIME_PRECISION_VALUES } = require('matrix-viewer-shared/lib/reference-values');
const { ONE_DAY_IN_MS, ONE_HOUR_IN_MS, ONE_MINUTE_IN_MS, ONE_SECOND_IN_MS } = MS_LOOKUP;
const { getUtcStartOfDayTs } = require('matrix-public-archive-shared/lib/timestamp-utilities');
const { getUtcStartOfDayTs } = require('matrix-viewer-shared/lib/timestamp-utilities');
function clamp(input, min, max) {
assert(input !== undefined);

View File

@ -2,14 +2,14 @@ version: '3'
services:
hs1:
image: matrix-public-archive-test-homeserver:latest
image: matrix-viewer-test-homeserver:latest
ports:
- '11008:8008'
environment:
- SERVER_NAME=hs1
hs2:
image: matrix-public-archive-test-homeserver:latest
image: matrix-viewer-test-homeserver:latest
ports:
- '12008:8008'
environment:

View File

@ -1,10 +1,10 @@
id: 6527ecdd6b8fe61c645d9d412222d75b
hs_token: hs_token_1f5d7675517072f0c0b5b684ca23f9ffad5a0cfc32e1ca824c0600ee74e105d7
id: matrix_viewer_foobarbaz
hs_token: hs_token_as_token_matrix_viewer_foobarbaz
# We use this as a consistent acccess token to use in our tests
as_token: as_token_8664700429a911bbbecf7d91b9e1a74716d669f40cf32259630e38439726e29d
as_token: as_token_matrix_viewer_foobarbaz
# This doesn't relate to anything else
url: 'http://localhost:0000'
sender_localpart: archiver
sender_localpart: view
namespaces:
users:
- exclusive: false

View File

@ -14,7 +14,7 @@ allow_public_rooms_over_federation: true
tls_certificate_path: /conf/server.tls.crt
tls_private_key_path: /conf/server.tls.key
bcrypt_rounds: 4
registration_shared_secret: matrix_public_archive
registration_shared_secret: matrix_viewer
listeners:
- port: 8448

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,8 @@ describe('getServerNameFromMatrixRoomIdOrAlias', () => {
},
{
name: 'can parse sub-domain',
input: '!foo:archive.matrix.org',
expected: 'archive.matrix.org',
input: '!foo:view.matrix.org',
expected: 'view.matrix.org',
},
{
name: 'can parse domain with port',

View File

@ -2,7 +2,7 @@
const assert = require('assert');
const checkTextForNsfw = require('matrix-public-archive-shared/lib/check-text-for-nsfw');
const checkTextForNsfw = require('matrix-viewer-shared/lib/check-text-for-nsfw');
describe('checkTextForNsfw', () => {
Object.entries({

View File

@ -15,7 +15,7 @@ const {
areTimestampsFromSameUtcHour,
areTimestampsFromSameUtcMinute,
areTimestampsFromSameUtcSecond,
} = require('matrix-public-archive-shared/lib/timestamp-utilities');
} = require('matrix-viewer-shared/lib/timestamp-utilities');
describe('timestamp-utilities', () => {
describe('roundUpTimestampToUtcX', () => {

View File

@ -4,7 +4,7 @@ const assert = require('assert');
const urlJoin = require('url-join');
const { fetchEndpointAsJson, fetchEndpoint } = require('../../server/lib/fetch-endpoint');
const getServerNameFromMatrixRoomIdOrAlias = require('../../server/lib/matrix-utils/get-server-name-from-matrix-room-id-or-alias');
const { MS_LOOKUP } = require('matrix-public-archive-shared/lib/reference-values');
const { MS_LOOKUP } = require('matrix-viewer-shared/lib/reference-values');
const { ONE_SECOND_IN_MS } = MS_LOOKUP;
const config = require('../../server/lib/config');
@ -52,7 +52,7 @@ async function getTestClientForAs() {
return {
homeserverUrl: testMatrixServerUrl1,
accessToken: matrixAccessToken,
userId: '@archiver:hs1',
userId: '@view:hs1',
};
}
@ -212,7 +212,7 @@ async function upgradeTestRoom({
}
// TODO: Pass `timestamp` massaging option to `createTestRoom()` when it supports it,
// see https://github.com/matrix-org/matrix-public-archive/issues/169
// see https://github.com/matrix-org/matrix-viewer/issues/169
const newRoomid = await createTestRoom(client, createOptions);
// Now send the tombstone event pointing from the old room to the new room

View File

@ -2,11 +2,11 @@
const {
VALID_ENTITY_DESCRIPTOR_TO_SIGIL_MAP,
} = require('matrix-public-archive-shared/lib/reference-values');
} = require('matrix-viewer-shared/lib/reference-values');
// http://archive.matrix.org/r/some-room:matrix.org/date/2022/11/16T23:59:59?at=$xxx
function parseArchiveUrlForRoom(archiveUrlForRoom) {
const urlObj = new URL(archiveUrlForRoom);
// http://view.matrix.org/r/some-room:matrix.org/date/2022/11/16T23:59:59?at=$xxx
function parseMatrixViewerUrlForRoom(roomUrl) {
const urlObj = new URL(roomUrl);
const urlPathname = urlObj.pathname;
const [_match, roomIdOrAliasDescriptor, roomIdOrAliasUrlPart, urlDateTime] = urlPathname.match(
@ -26,4 +26,4 @@ function parseArchiveUrlForRoom(archiveUrlForRoom) {
};
}
module.exports = parseArchiveUrlForRoom;
module.exports = parseMatrixViewerUrlForRoom;