diff --git a/.github/workflows/containerize.yaml b/.github/workflows/containerize.yaml index 7de3e74..ea78c48 100644 --- a/.github/workflows/containerize.yaml +++ b/.github/workflows/containerize.yaml @@ -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 }} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bc3de58..b182049 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c83771..f6ec7d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 401d15f..00bc5a0 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,28 @@ -# Matrix Public Archive +# Matrix Viewer -Join the community and get support at #matrix-public-archive:matrix.org +Join the community and get support at #matrix-viewer:matrix.org + +> **Note** +> The Matrix Public Archive has been renamed to Matrix Viewer to better reflect what it +> actually does and doesn't do. It's a viewer for world-readable Matrix rooms and +> doesn't actually archive anything. In the vein of [feature parity with -Gitter](https://github.com/vector-im/roadmap/issues/26), the goal is to make a -public archive site for `world_readable` Matrix rooms like Gitter's archives +Gitter](https://github.com/vector-im/roadmap/issues/26), the goal is to make an +accessible public site for `world_readable` Matrix rooms like Gitter's archives which search engines can index and keep all of the content accessible/available. -#### Try it out: [archive.matrix.org](https://archive.matrix.org/) 🌌 +#### Try it out: [view.matrix.org](https://view.matrix.org/) 🌌 -Room directory homepage | Archive room view +Room directory homepage | Room view --- | --- -A reference for how the Matrix Public Archive homepage looks. Search bar where you can find thousands of rooms using Matrix and homeserver selector. Grid of room cards showing the results. | ![A reference for how the Matrix Public Archive looks. Showing off a day of messages in `#gitter:matrix.org` on 2021-08-06. There is a date picker calendar in the right sidebar and a traditional chat app layout on the left.](https://user-images.githubusercontent.com/558581/234765275-28c70c49-c27f-473a-88ba-f4392ddae871.png) +A reference for how the Matrix Viewer homepage looks. Search bar where you can find thousands of rooms using Matrix and homeserver selector. Grid of room cards showing the results. | ![A reference for how the Matrix Viewer looks. Showing off a day of messages in `#gitter:matrix.org` on 2021-08-06. There is a date picker calendar in the right sidebar and a traditional chat app layout on the left.](https://user-images.githubusercontent.com/558581/234765275-28c70c49-c27f-473a-88ba-f4392ddae871.png) ## Demo videos +The demo's refer to this project as the "Matrix Public Archive" which has now been renamed to "Matrix Viewer". + - [![](https://user-images.githubusercontent.com/558581/206083768-d18456de-caa3-463f-a891-96eed8054686.png) May 2023](https://www.youtube.com/watch?v=4KlNILNItGQ&t=1046s): Introducing [archive.matrix.org](https://archive.matrix.org/), the shiny new public instance of the Matrix Public Archive that everyone can share and link to. - [![](https://user-images.githubusercontent.com/558581/206083768-d18456de-caa3-463f-a891-96eed8054686.png) Aug 2022](https://www.youtube.com/watch?v=6KHQSeJTXm0&t=583s) ([blog post](https://matrix.org/blog/2022/08/05/this-week-in-matrix-2022-08-05#matrix-public-archive-website)): A quick intro of what the project looks like, the goals, what it accomplishes, and how it's a new portal into the Matrix ecosystem. - [![](https://user-images.githubusercontent.com/558581/206083768-d18456de-caa3-463f-a891-96eed8054686.png) Oct 2022](https://www.youtube.com/watch?v=UT6KSEqDUf8&t=548s): Showing off the room directory landing page used to browse everything available in the archive. @@ -25,7 +32,7 @@ Room directory homepage | Archive room view We server-side render (SSR) the [Hydrogen](https://github.com/vector-im/hydrogen-web) Matrix client on a Node.js server (since both use JavaScript) and serve pages on the fly (with some Cloudflare caching on top) when someone requests -`/archives/r/matrixhq:matrix.org/${year}/${month}/${day}`. To fetch the events for a +`/r/matrixhq:matrix.org/${year}/${month}/${day}`. To fetch the events for a given day/time, we use [MSC3030](https://github.com/matrix-org/matrix-doc/pull/3030)'s `/timestamp_to_event` endpoint to jump to a given day in the timeline and fetch the messages from a Matrix homeserver. @@ -70,9 +77,9 @@ $ npm run start ## Development ```sh -# Clone and install the `matrix-public-archive` project -$ git clone git@github.com:matrix-org/matrix-public-archive.git -$ cd matrix-public-archive +# Clone and install the `matrix-viewer` project +$ git clone git@github.com:matrix-org/matrix-viewer.git +$ cd matrix-viewer $ npm install # Edit `config/config.user-overrides.json` so that `matrixServerUrl` points to @@ -88,7 +95,7 @@ it into this project with the following instructions: ```sh # We need to use a draft branch of Hydrogen to get the custom changes needed for -# `matrix-public-archive` to run. Hopefully soon, we can get all of the custom +# `matrix-viewer` to run. Hopefully soon, we can get all of the custom # changes mainlined so this isn't necessary. $ git clone git@github.com:vector-im/hydrogen-web.git $ cd hydrogen-web @@ -98,7 +105,7 @@ $ yarn build:sdk $ cd target/ && npm link && cd .. $ cd .. -$ cd matrix-public-archive +$ cd matrix-viewer $ npm link hydrogen-view-sdk ``` diff --git a/build-scripts/vite.config.js b/build-scripts/vite.config.js index 0b8ee64..234e115 100644 --- a/build-scripts/vite.config.js +++ b/build-scripts/vite.config.js @@ -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 diff --git a/client/css/styles.css b/client/css/styles.css index 1b05f76..ff3851a 100644 --- a/client/css/styles.css +++ b/client/css/styles.css @@ -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 */ diff --git a/client/img/matrix-public-archive-opengraph.png b/client/img/opengraph.png similarity index 100% rename from client/img/matrix-public-archive-opengraph.png rename to client/img/opengraph.png diff --git a/client/js/entry-client-hydrogen.js b/client/js/entry-client-hydrogen.js index 5caa91d..cb8e70c 100644 --- a/client/js/entry-client-hydrogen.js +++ b/client/js/entry-client-hydrogen.js @@ -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'; diff --git a/client/js/entry-client-room-alias-hash-redirect.js b/client/js/entry-client-room-alias-hash-redirect.js index b68568f..b4f3b83 100644 --- a/client/js/entry-client-room-alias-hash-redirect.js +++ b/client/js/entry-client-room-alias-hash-redirect.js @@ -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 diff --git a/client/js/entry-client-room-directory.js b/client/js/entry-client-room-directory.js index 72645f9..87e5471 100644 --- a/client/js/entry-client-room-directory.js +++ b/client/js/entry-client-room-directory.js @@ -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'; diff --git a/config/config.default.json b/config/config.default.json index 742fdc4..3af9d99 100644 --- a/config/config.default.json +++ b/config/config.default.json @@ -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, diff --git a/config/config.test.json b/config/config.test.json index b78954f..0a8d1f6 100644 --- a/config/config.test.json +++ b/config/config.test.json @@ -7,5 +7,5 @@ "testMatrixServerUrl2": "http://localhost:12008/", // Secrets - "matrixAccessToken": "as_token_8664700429a911bbbecf7d91b9e1a74716d669f40cf32259630e38439726e29d" + "matrixAccessToken": "as_token_matrix_viewer_foobarbaz" } diff --git a/docs/faq.md b/docs/faq.md index 6725558..78c94f3 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -2,14 +2,14 @@ ## Can I run my own instance? -Yes! We host a public canonical version of the Matrix Public Archive at -[archive.matrix.org](https://archive.matrix.org/) that everyone can use but feel free to +Yes! We host a public canonical version of the Matrix Viewer at +_(incoming)_ that everyone can use but feel free to also run your own instance (setup instructions in the [readme](../README.md)). -## How is this different from [`view.matrix.org`](https://view.matrix.org/)? +## How is this different from the `matrix-static` project? -https://view.matrix.org/ (https://github.com/matrix-org/matrix-static) already existed -before the Matrix Public Archive but there was some desire to make something with more +[Matrix Static](https://github.com/matrix-org/matrix-static) already existed +before the Matrix Viewer but there was some desire to make something with more Element-feeling polish and loading faster (avoid the slow 502's errors that are frequent on `view.matrix.org`). @@ -17,19 +17,22 @@ And with the introduction of the jump to date API via [MSC3030](https://github.com/matrix-org/matrix-spec-proposals/pull/3030), we could show messages from any given date and day-by-day navigation. -## Why did the archive bot join my room? +The Matrix Viewer project has since replaced the `matrix-static` project on +[`view.matrix.org`](https://view.matrix.org/). + +## Why did the bot join my room? Only Matrix rooms with `world_readable` [history visibility](https://spec.matrix.org/latest/client-server-api/#room-history-visibility) -are accessible in the Matrix Public Archive and indexed by search engines. +are accessible in the Matrix Viewer and indexed by search engines. -But the archive bot (`@archive:matrix.org`) will join any public room because it doesn't +But the bot (`@view:matrix.org`) will join any public room because it doesn't know the history visibility without first joining. Any room that doesn't have `world_readable` history visibility will lead a `403 Forbidden`. -The Matrix Public Archive doesn't hold onto any data (it's +The Matrix Viewer hold onto any data (it's stateless) and requests the messages from the homeserver every time. The -[archive.matrix.org](https://archive.matrix.org/) instance has some caching in place, 5 +[view.matrix.org](https://view.matrix.org/) instance has some caching in place, 5 minutes for the current day, and 2 days for past content. See the [opt out @@ -40,22 +43,21 @@ for more details. Only Matrix rooms with `world_readable` [history visibility](https://spec.matrix.org/latest/client-server-api/#room-history-visibility) -are accessible in the Matrix Public Archive and indexed by search engines. One easy way +are accessible in the Matrix Viewer and indexed by search engines. One easy way to opt-out is to change your rooms history visibility to something else if you don't intend for your room be world readable. Dedicated opt-out controls are being tracked in -[#47](https://github.com/matrix-org/matrix-public-archive/issues/47). +[#47](https://github.com/matrix-org/matrix-viewer/issues/47). -As a workaround for [archive.matrix.org](https://archive.matrix.org/), you can ban the -`@archive:matrix.org` user if you don't want your room content to be shown in the -archive at all. +As a workaround for [view.matrix.org](https://view.matrix.org/), you can ban the +`@view:matrix.org` user if you don't want your room content to be shown at all. -### Why does the archive user join rooms instead peeking in the room or using guests? +### Why does the bot user join rooms instead peeking in the room or using guests? -Since the archive only displays rooms with `world_readable` history visibility, we could +Since Matrix Viewer only displays rooms with `world_readable` history visibility, we could peek into the rooms without joining. This is being explored in -[#272](https://github.com/matrix-org/matrix-public-archive/pull/272). But peeking +[#272](https://github.com/matrix-org/matrix-viewer/pull/272). But peeking doesn't work when the server doesn't know about the room already (this is commonly referred to as federated peeking) which is why we have to fallback to joining the room in any case. We could solve the federated peeking problem and avoid the join with @@ -64,7 +66,7 @@ to check whether the room is `world_readable` even over federation. Guests are completely separate concept and controlled by the `m.room.guest_access` state event in the room. Guest access is also a much different ask than read-only access since -guests can also send messages in the room which isn't always desirable. The archive bot +guests can also send messages in the room which isn't always desirable. The bot is read-only and does not send messages. ## Technical details @@ -72,7 +74,7 @@ is read-only and does not send messages. The main readme has a [technical overview](../README.md#technical-overview) of the project. Here are a few more details. -### How do I figure out what version of the Matrix Public Archive is running? +### How do I figure out what version of the Matrix Viewer is running? Just visit the `/health-check` endpoint which will return information like the following: @@ -86,11 +88,11 @@ Just visit the `/health-check` endpoint which will return information like the f } ``` -### How does the archive room URL relate to what is displayed on the page? +### How does the room URL relate to what is displayed on the page? We start the end of the date/time specified in the URL looking backward up to the limit. ### Why does the time selector only appear for some pages? The time selector only appears for pages that have a lot of messages on a given -day/hour/minute/second (more than the configured `archiveMessageLimit`). +day/hour/minute/second (more than the configured `messageLimit`). diff --git a/docs/testing.md b/docs/testing.md index 320abdf..db9e4c2 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -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 ``` diff --git a/package-lock.json b/package-lock.json index a645bb7..ab0f62b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 434c86a..143e50b 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/server/hydrogen-render/render-hydrogen-to-string-unsafe.js b/server/hydrogen-render/render-hydrogen-to-string-unsafe.js index a34c384..0776f6e 100644 --- a/server/hydrogen-render/render-hydrogen-to-string-unsafe.js +++ b/server/hydrogen-render/render-hydrogen-to-string-unsafe.js @@ -96,7 +96,7 @@ async function _renderHydrogenToStringUnsafe(renderOptions) { } // Define this for the SSR context - dom.window.matrixPublicArchiveContext = { + dom.window.matrixViewerContext = { ...renderOptions.vmRenderContext, }; diff --git a/server/hydrogen-render/render-page-html.js b/server/hydrogen-render/render-page-html.js index af1d60a..49fad49 100644 --- a/server/hydrogen-render/render-page-html.js +++ b/server/hydrogen-render/render-page-html.js @@ -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) { ${scripts diff --git a/server/lib/matrix-utils/ensure-room-joined.js b/server/lib/matrix-utils/ensure-room-joined.js index f192d76..ee3b964 100644 --- a/server/lib/matrix-utils/ensure-room-joined.js +++ b/server/lib/matrix-utils/ensure-room-joined.js @@ -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}`); } } diff --git a/server/lib/matrix-utils/fetch-accessible-rooms.js b/server/lib/matrix-utils/fetch-accessible-rooms.js index cc24bd7..7ebd115 100644 --- a/server/lib/matrix-utils/fetch-accessible-rooms.js +++ b/server/lib/matrix-utils/fetch-accessible-rooms.js @@ -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) { diff --git a/server/lib/matrix-utils/fetch-events-from-timestamp-backwards.js b/server/lib/matrix-utils/fetch-events-from-timestamp-backwards.js index 196dabc..17c5331 100644 --- a/server/lib/matrix-utils/fetch-events-from-timestamp-backwards.js +++ b/server/lib/matrix-utils/fetch-events-from-timestamp-backwards.js @@ -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'); diff --git a/server/lib/matrix-utils/get-messages-response-from-event-id.js b/server/lib/matrix-utils/get-messages-response-from-event-id.js index 7d636df..2d4f2b9 100644 --- a/server/lib/matrix-utils/get-messages-response-from-event-id.js +++ b/server/lib/matrix-utils/get-messages-response-from-event-id.js @@ -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'); diff --git a/server/lib/set-headers-for-date-temporal-context.js b/server/lib/set-headers-for-date-temporal-context.js index a72f63f..8383647 100644 --- a/server/lib/set-headers-for-date-temporal-context.js +++ b/server/lib/set-headers-for-date-temporal-context.js @@ -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*. diff --git a/server/middleware/redirect-to-correct-archive-url-if-bad-sigil-middleware.js b/server/middleware/redirect-to-correct-room-url-if-bad-sigil-middleware.js similarity index 90% rename from server/middleware/redirect-to-correct-archive-url-if-bad-sigil-middleware.js rename to server/middleware/redirect-to-correct-room-url-if-bad-sigil-middleware.js index efcbf9b..2fa4f0f 100644 --- a/server/middleware/redirect-to-correct-archive-url-if-bad-sigil-middleware.js +++ b/server/middleware/redirect-to-correct-room-url-if-bad-sigil-middleware.js @@ -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; diff --git a/server/middleware/timeout-middleware.js b/server/middleware/timeout-middleware.js index 6a592e8..393e323 100644 --- a/server/middleware/timeout-middleware.js +++ b/server/middleware/timeout-middleware.js @@ -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: diff --git a/server/routes/client-side-room-alias-hash-redirect-route.js b/server/routes/client-side-room-alias-hash-redirect-route.js index d28152c..ccf828e 100644 --- a/server/routes/client-side-room-alias-hash-redirect-route.js +++ b/server/routes/client-side-room-alias-hash-redirect-route.js @@ -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), diff --git a/server/routes/install-routes.js b/server/routes/install-routes.js index 316fbc7..1bf0fed 100644 --- a/server/routes/install-routes.js +++ b/server/routes/install-routes.js @@ -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 ); } diff --git a/server/routes/room-directory-routes.js b/server/routes/room-directory-routes.js index fde1467..84f15a5 100644 --- a/server/routes/room-directory-routes.js +++ b/server/routes/room-directory-routes.js @@ -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', diff --git a/server/routes/room-routes.js b/server/routes/room-routes.js index a168b8e..2414665 100644 --- a/server/routes/room-routes.js +++ b/server/routes/room-routes.js @@ -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, diff --git a/shared/hydrogen-vm-render-script.js b/shared/hydrogen-vm-render-script.js index 4ef5cbe..67ff99d 100644 --- a/shared/hydrogen-vm-render-script.js +++ b/shared/hydrogen-vm-render-script.js @@ -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(); diff --git a/shared/lib/custom-tile-utilities.js b/shared/lib/custom-tile-utilities.js index e7c7b16..9cc6124 100644 --- a/shared/lib/custom-tile-utilities.js +++ b/shared/lib/custom-tile-utilities.js @@ -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); diff --git a/shared/lib/archive-history.js b/shared/lib/matrix-viewer-history.js similarity index 92% rename from shared/lib/archive-history.js rename to shared/lib/matrix-viewer-history.js index cc9207c..8efe2ad 100644 --- a/shared/lib/archive-history.js +++ b/shared/lib/matrix-viewer-history.js @@ -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; diff --git a/shared/lib/redirect-if-room-alias-in-hash.js b/shared/lib/redirect-if-room-alias-in-hash.js index b68f7e5..afc511c 100644 --- a/shared/lib/redirect-if-room-alias-in-hash.js +++ b/shared/lib/redirect-if-room-alias-in-hash.js @@ -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) { diff --git a/shared/lib/timestamp-utilities.js b/shared/lib/timestamp-utilities.js index 1990add..15c1929 100644 --- a/shared/lib/timestamp-utilities.js +++ b/shared/lib/timestamp-utilities.js @@ -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) { diff --git a/shared/lib/url-creator.js b/shared/lib/url-creator.js index f8b9b3d..2167c5a 100644 --- a/shared/lib/url-creator.js +++ b/shared/lib/url-creator.js @@ -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)}`; } diff --git a/shared/room-directory-vm-render-script.js b/shared/room-directory-vm-render-script.js index d93f6b0..5e18db0 100644 --- a/shared/room-directory-vm-render-script.js +++ b/shared/room-directory-vm-render-script.js @@ -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, diff --git a/shared/viewmodels/AvatarViewModel.js b/shared/viewmodels/AvatarViewModel.js index 63c4786..98d4dbe 100644 --- a/shared/viewmodels/AvatarViewModel.js +++ b/shared/viewmodels/AvatarViewModel.js @@ -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) { diff --git a/shared/viewmodels/CalendarViewModel.js b/shared/viewmodels/CalendarViewModel.js index 72e552b..377ea8e 100644 --- a/shared/viewmodels/CalendarViewModel.js +++ b/shared/viewmodels/CalendarViewModel.js @@ -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 ); diff --git a/shared/viewmodels/DeveloperOptionsContentViewModel.js b/shared/viewmodels/DeveloperOptionsContentViewModel.js index 170a271..f038625 100644 --- a/shared/viewmodels/DeveloperOptionsContentViewModel.js +++ b/shared/viewmodels/DeveloperOptionsContentViewModel.js @@ -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) { diff --git a/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js b/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js index 7876985..df21c39 100644 --- a/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js +++ b/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js @@ -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, diff --git a/shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel.js b/shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel.js index 6f2d684..1c5e662 100644 --- a/shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel.js +++ b/shared/viewmodels/JumpToPreviousActivitySummaryTileViewModel.js @@ -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, diff --git a/shared/viewmodels/RoomCardViewModel.js b/shared/viewmodels/RoomCardViewModel.js index 4732375..5f1ffc6 100644 --- a/shared/viewmodels/RoomCardViewModel.js +++ b/shared/viewmodels/RoomCardViewModel.js @@ -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() { diff --git a/shared/viewmodels/RoomDirectoryViewModel.js b/shared/viewmodels/RoomDirectoryViewModel.js index 3268b6b..e5df392 100644 --- a/shared/viewmodels/RoomDirectoryViewModel.js +++ b/shared/viewmodels/RoomDirectoryViewModel.js @@ -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, diff --git a/shared/viewmodels/ArchiveRoomViewModel.js b/shared/viewmodels/RoomViewModel.js similarity index 89% rename from shared/viewmodels/ArchiveRoomViewModel.js rename to shared/viewmodels/RoomViewModel.js index 3ae2f7e..552f65f 100644 --- a/shared/viewmodels/ArchiveRoomViewModel.js +++ b/shared/viewmodels/RoomViewModel.js @@ -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; diff --git a/shared/viewmodels/TimeSelectorViewModel.js b/shared/viewmodels/TimeSelectorViewModel.js index d3818af..dc3e308 100644 --- a/shared/viewmodels/TimeSelectorViewModel.js +++ b/shared/viewmodels/TimeSelectorViewModel.js @@ -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 } diff --git a/shared/views/CalendarView.js b/shared/views/CalendarView.js index 3b7709d..74b9bf6 100644 --- a/shared/views/CalendarView.js +++ b/shared/views/CalendarView.js @@ -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())] ), diff --git a/shared/views/RightPanelContentView.js b/shared/views/RightPanelContentView.js index 3ebab71..ca1acf6 100644 --- a/shared/views/RightPanelContentView.js +++ b/shared/views/RightPanelContentView.js @@ -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' diff --git a/shared/views/RoomCardView.js b/shared/views/RoomCardView.js index ca1a8dd..4b7a93a 100644 --- a/shared/views/RoomCardView.js +++ b/shared/views/RoomCardView.js @@ -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) { diff --git a/shared/views/RoomDirectoryView.js b/shared/views/RoomDirectoryView.js index 61157d1..776051c 100644 --- a/shared/views/RoomDirectoryView.js +++ b/shared/views/RoomDirectoryView.js @@ -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' ), `.`, diff --git a/shared/views/ArchiveRoomView.js b/shared/views/RoomView.js similarity index 92% rename from shared/views/ArchiveRoomView.js rename to shared/views/RoomView.js index d7b791e..cfd503a 100644 --- a/shared/views/ArchiveRoomView.js +++ b/shared/views/RoomView.js @@ -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; diff --git a/shared/views/TimeSelectorView.js b/shared/views/TimeSelectorView.js index 4874e6f..03d0dea 100644 --- a/shared/views/TimeSelectorView.js +++ b/shared/views/TimeSelectorView.js @@ -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); diff --git a/test/docker-compose.yml b/test/docker-compose.yml index ec66d59..72e9fde 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -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: diff --git a/test/dockerfiles/synapse/as_registration.yaml b/test/dockerfiles/synapse/as_registration.yaml index 8b6a612..77d7d30 100644 --- a/test/dockerfiles/synapse/as_registration.yaml +++ b/test/dockerfiles/synapse/as_registration.yaml @@ -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 diff --git a/test/dockerfiles/synapse/homeserver.yaml b/test/dockerfiles/synapse/homeserver.yaml index c00184f..1d62af5 100644 --- a/test/dockerfiles/synapse/homeserver.yaml +++ b/test/dockerfiles/synapse/homeserver.yaml @@ -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 diff --git a/test/e2e-tests.js b/test/e2e-tests.js index 2e26ece..c8d18c2 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -12,7 +12,7 @@ const { readFile } = require('fs').promises; const chalk = require('chalk'); const RethrownError = require('../server/lib/errors/rethrown-error'); -const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator'); +const MatrixViewerURLCreator = require('matrix-viewer-shared/lib/url-creator'); const { fetchEndpointAsText, fetchEndpointAsJson } = require('../server/lib/fetch-endpoint'); const ensureRoomJoined = require('../server/lib/matrix-utils/ensure-room-joined'); const config = require('../server/lib/config'); @@ -20,12 +20,12 @@ const { MS_LOOKUP, TIME_PRECISION_VALUES, DIRECTION, -} = 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, getUtcStartOfDayTs, -} = require('matrix-public-archive-shared/lib/timestamp-utilities'); +} = require('matrix-viewer-shared/lib/timestamp-utilities'); const { getTestClientForAs, @@ -44,7 +44,7 @@ const { } = require('./test-utils/client-utils'); const TestError = require('./test-utils/test-error'); const parseRoomDayMessageStructure = require('./test-utils/parse-room-day-message-structure'); -const parseArchiveUrlForRoom = require('./test-utils/parse-archive-url-for-room'); +const parseMatrixViewerUrlForRoom = require('./test-utils/parse-matrix-viewer-url-for-room'); const testMatrixServerUrl1 = config.get('testMatrixServerUrl1'); const testMatrixServerUrl2 = config.get('testMatrixServerUrl2'); @@ -54,7 +54,7 @@ const basePath = config.get('basePath'); assert(basePath); const interactive = config.get('interactive'); -const matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath); +const matrixViewerURLCreator = new MatrixViewerURLCreator(basePath); const HOMESERVER_URL_TO_PRETTY_NAME_MAP = { [testMatrixServerUrl1]: 'hs1', @@ -82,10 +82,10 @@ function assertExpectedTimePrecisionAgainstUrl(expectedTimePrecision, url) { } } -describe('matrix-public-archive', () => { +describe('matrix-viewer', () => { let server; before(() => { - // Start the archive server + // Start the app server server = require('../server/server'); }); @@ -148,18 +148,18 @@ describe('matrix-public-archive', () => { }); }); - describe('Archive', () => { + describe('Matrix Viewer', () => { // Use a fixed date at the start of the UTC day so that the tests are // consistent. Otherwise, the tests could fail when they start close to // midnight and it rolls over to the next day. // January 15th, 2022 - const archiveDate = new Date(Date.UTC(2022, 0, 15)); - let archiveUrl; + const FIXED_VIEW_DATE = new Date(Date.UTC(2022, 0, 15)); + let testUrl; let numMessagesSent = 0; afterEach(function () { if (interactive) { // eslint-disable-next-line no-console - console.log('Interactive URL for test', archiveUrl); + console.log('Interactive URL for test', testUrl); } // Reset `numMessagesSent` between tests so each test starts from the @@ -181,37 +181,35 @@ describe('matrix-public-archive', () => { }); // Sends a message and makes sure that a timestamp was provided - async function sendMessageOnArchiveDate(options) { + async function sendMessageOnFixedViewDate(options) { const minute = 1000 * 60; // Adjust the timestamp by a minute each time so there is some visual difference. - options.timestamp = archiveDate.getTime() + minute * numMessagesSent; + options.timestamp = FIXED_VIEW_DATE.getTime() + minute * numMessagesSent; numMessagesSent++; return sendMessage(options); } // Sends a message and makes sure that a timestamp was provided - async function sendEventOnArchiveDate(options) { + async function sendEventOnFixedViewDate(options) { const minute = 1000 * 60; // Adjust the timestamp by a minute each time so there is some visual difference. - options.timestamp = archiveDate.getTime() + minute * numMessagesSent; + options.timestamp = FIXED_VIEW_DATE.getTime() + minute * numMessagesSent; numMessagesSent++; return sendEvent(options); } - describe('Archive room view', () => { + describe('Room view', () => { it('shows all events in a given day', async () => { const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); - // Just render the page initially so that the archiver user is already + // Just render the page initially so that the bot user is already // joined to the page. We don't want their join event masking the one-off // problem where we're missing the latest message in the room. We just use the date now // because it will find whatever events backwards no matter when they were sent. - await fetchEndpointAsText( - matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, new Date()) - ); + await fetchEndpointAsText(matrixViewerURLCreator.roomUrlForDate(roomId, new Date())); const messageTextList = [ `Amontons' First Law: The force of friction is directly proportional to the applied load.`, @@ -223,7 +221,7 @@ describe('matrix-public-archive', () => { // TODO: Can we use `createMessagesInRoom` here instead? const eventIds = []; for (const messageText of messageTextList) { - const eventId = await sendMessageOnArchiveDate({ + const eventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -237,10 +235,10 @@ describe('matrix-public-archive', () => { // Sanity check that we actually sent some messages assert.strictEqual(eventIds.length, 3); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the messages are visible for (let i = 0; i < eventIds.length; i++) { @@ -290,7 +288,7 @@ describe('matrix-public-archive', () => { data: imageBuffer, fileName: imageFileName, }); - const imageEventId = await sendMessageOnArchiveDate({ + const imageEventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -310,7 +308,7 @@ describe('matrix-public-archive', () => { // A normal text message const normalMessageText1 = '^ Figure 1: Simulated blocks with fractal rough surfaces, exhibiting static frictional interactions'; - const normalMessageEventId1 = await sendMessageOnArchiveDate({ + const normalMessageEventId1 = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -322,7 +320,7 @@ describe('matrix-public-archive', () => { // Another normal text message const normalMessageText2 = 'The topography of the Moon has been measured with laser altimetry and stereo image analysis.'; - const normalMessageEventId2 = await sendMessageOnArchiveDate({ + const normalMessageEventId2 = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -333,7 +331,7 @@ describe('matrix-public-archive', () => { // Test replies const replyMessageText = `The concentration of maria on the near side likely reflects the substantially thicker crust of the highlands of the Far Side, which may have formed in a slow-velocity impact of a second moon of Earth a few tens of millions of years after the Moon's formation.`; - const replyMessageEventId = await sendMessageOnArchiveDate({ + const replyMessageEventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -363,7 +361,7 @@ describe('matrix-public-archive', () => { // event it's replying to (the relation). const replyMissingRelationMessageText = `While the giant-impact theory explains many lines of evidence, some questions are still unresolved, most of which involve the Moon's composition.`; const missingRelationEventId = '$someMissingEvent'; - const replyMissingRelationMessageEventId = await sendMessageOnArchiveDate({ + const replyMissingRelationMessageEventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -391,7 +389,7 @@ describe('matrix-public-archive', () => { // Test reactions const reactionText = '😅'; - await sendEventOnArchiveDate({ + await sendEventOnFixedViewDate({ client, roomId, eventType: 'm.reaction', @@ -404,11 +402,11 @@ describe('matrix-public-archive', () => { }, }); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the user display name is visible on the message assert.match( @@ -484,18 +482,18 @@ describe('matrix-public-archive', () => { roomId: hs2RoomId, numMessages: 3, prefix: HOMESERVER_URL_TO_PRETTY_NAME_MAP[hs2Client.homeserverUrl], - timestamp: archiveDate.getTime(), + timestamp: FIXED_VIEW_DATE.getTime(), }); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(hs2RoomId, archiveDate, { + testUrl = matrixViewerURLCreator.roomUrlForDate(hs2RoomId, FIXED_VIEW_DATE, { // Since hs1 doesn't know about this room on hs2 yet, we have to provide // a via server to ask through. viaServers: [HOMESERVER_URL_TO_PRETTY_NAME_MAP[testMatrixServerUrl2]], }); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the messages are visible assert.deepStrictEqual( @@ -513,7 +511,7 @@ describe('matrix-public-archive', () => { const roomId = await createTestRoom(client); // Send an event in the room so we have some day of history to redirect to - const eventId = await sendMessageOnArchiveDate({ + const eventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -524,10 +522,10 @@ describe('matrix-public-archive', () => { const expectedEventIdsOnDay = [eventId]; // Visit `/:roomIdOrAlias` and expect to be redirected to the most recent day with events - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForRoom(roomId); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + testUrl = matrixViewerURLCreator.roomUrl(roomId); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the messages from the day we expect to get redirected to are visible assert.deepStrictEqual( @@ -547,7 +545,7 @@ describe('matrix-public-archive', () => { // Send an event in the room so there is some history to display in the // surroundings and everything doesn't just 404 because we can't find // any event. - const eventId = await sendMessageOnArchiveDate({ + const eventId = await sendMessageOnFixedViewDate({ client, roomId, content: { @@ -557,16 +555,16 @@ describe('matrix-public-archive', () => { }); const expectedEventIdsToBeDisplayed = [eventId]; - // Visit the archive on the day ahead of where there are messages - const visitArchiveDate = new Date(Date.UTC(2022, 0, 20)); + // Visit on the day ahead of where there are messages + const visitDate = new Date(Date.UTC(2022, 0, 20)); assert( - visitArchiveDate > archiveDate, - 'The date we visit the archive (`visitArchiveDate`) should be after where the messages were sent (`archiveDate`)' + visitDate > FIXED_VIEW_DATE, + 'The date we visit (`visitDate`) should be after where the messages were sent (`FIXED_VIEW_DATE`)' ); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, visitArchiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, visitDate); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the summary exists on the page assert( @@ -592,10 +590,10 @@ describe('matrix-public-archive', () => { // We purposely send no events in the room - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); - const dom = parseHTML(archivePageHtml); + const dom = parseHTML(pageHtml); // Make sure the summary exists on the page assert( @@ -612,14 +610,11 @@ describe('matrix-public-archive', () => { try { const TWO_DAYS_IN_MS = 2 * ONE_DAY_IN_MS; await fetchEndpointAsText( - matrixPublicArchiveURLCreator.archiveUrlForDate( - roomId, - new Date(Date.now() + TWO_DAYS_IN_MS) - ) + matrixViewerURLCreator.roomUrlForDate(roomId, new Date(Date.now() + TWO_DAYS_IN_MS)) ); assert.fail( new TestError( - `We expect the request to fail with a 404 since you can't view the future in the archive but it succeeded` + `We expect the request to fail with a 404 since you can't view a date in the future but it succeeded` ) ); } catch (err) { @@ -655,9 +650,9 @@ describe('matrix-public-archive', () => { const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client, testCase.createRoomOptions); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the `` tag exists on the page // telling search engines that this is an adult page. @@ -677,9 +672,9 @@ describe('matrix-public-archive', () => { const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the `` tag does NOT exist on the // page telling search engines that this is an adult page. @@ -690,7 +685,7 @@ describe('matrix-public-archive', () => { describe('time selector', () => { it('shows time selector when there are too many messages from the same day', async () => { // Set this low so it's easy to hit the limit - config.set('archiveMessageLimit', 3); + config.set('messageLimit', 3); const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); @@ -698,18 +693,18 @@ describe('matrix-public-archive', () => { await createMessagesInRoom({ client, roomId, - // This should be greater than the `archiveMessageLimit` + // This should be greater than the `messageLimit` numMessages: 10, prefix: `foo`, - timestamp: archiveDate.getTime(), + timestamp: FIXED_VIEW_DATE.getTime(), // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging increment: ONE_HOUR_IN_MS, }); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the time selector is visible const timeSelectorElement = dom.document.querySelector(`[data-testid="time-selector"]`); @@ -718,7 +713,7 @@ describe('matrix-public-archive', () => { it('shows time selector when there are too many messages from the same day but paginated forward into days with no messages', async () => { // Set this low so it's easy to hit the limit - config.set('archiveMessageLimit', 3); + config.set('messageLimit', 3); const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); @@ -726,24 +721,24 @@ describe('matrix-public-archive', () => { await createMessagesInRoom({ client, roomId, - // This should be greater than the `archiveMessageLimit` + // This should be greater than the `messageLimit` numMessages: 10, prefix: `foo`, - timestamp: archiveDate.getTime(), + timestamp: FIXED_VIEW_DATE.getTime(), // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging increment: ONE_HOUR_IN_MS, }); // Visit a day after when the messages were sent but there weren't - const visitArchiveDate = new Date(Date.UTC(2022, 0, 20)); + const visitDate = new Date(Date.UTC(2022, 0, 20)); assert( - visitArchiveDate > archiveDate, - 'The date we visit the archive (`visitArchiveDate`) should be after where the messages were sent (`archiveDate`)' + visitDate > FIXED_VIEW_DATE, + 'The date we visit (`visitDate`) should be after where the messages were sent (`FIXED_VIEW_DATE`)' ); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, visitArchiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, visitDate); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the time selector is visible const timeSelectorElement = dom.document.querySelector(`[data-testid="time-selector"]`); @@ -754,7 +749,7 @@ describe('matrix-public-archive', () => { // Set this low so we don't have to deal with many messages in the tests But // high enough to encompass all of the primoridial room creation events + // whatever messages we send in the room for this test. - config.set('archiveMessageLimit', 15); + config.set('messageLimit', 15); const client = await getTestClientForHs(testMatrixServerUrl1); // FIXME: This test is flawed and needs MSC3997 to timestamp massage the @@ -766,18 +761,18 @@ describe('matrix-public-archive', () => { await createMessagesInRoom({ client, roomId, - // This should be lesser than the `archiveMessageLimit` + // This should be lesser than the `messageLimit` numMessages: 1, prefix: `foo`, - timestamp: archiveDate.getTime(), + timestamp: FIXED_VIEW_DATE.getTime(), // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging increment: ONE_HOUR_IN_MS, }); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the time selector is *NOT* visible const timeSelectorElement = dom.document.querySelector(`[data-testid="time-selector"]`); @@ -786,25 +781,25 @@ describe('matrix-public-archive', () => { it('does not show time selector when showing events from multiple days', async () => { // Set this low so we don't have to deal with many messages in the tests - config.set('archiveMessageLimit', 5); + config.set('messageLimit', 5); const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); - // Create more messages than the archiveMessageLimit across many days but we + // Create more messages than the messageLimit across many days but we // should not go over the limit on a daily basis - const dayBeforeArchiveDateTs = Date.UTC( - archiveDate.getUTCFullYear(), - archiveDate.getUTCMonth(), - archiveDate.getUTCDate() - 1 + const dayBeforeFixedViewDateTs = Date.UTC( + FIXED_VIEW_DATE.getUTCFullYear(), + FIXED_VIEW_DATE.getUTCMonth(), + FIXED_VIEW_DATE.getUTCDate() - 1 ); await createMessagesInRoom({ client, roomId, - // This should be lesser than the `archiveMessageLimit` + // This should be lesser than the `messageLimit` numMessages: 3, prefix: `foo`, - timestamp: dayBeforeArchiveDateTs, + timestamp: dayBeforeFixedViewDateTs, // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging increment: ONE_HOUR_IN_MS, @@ -812,18 +807,18 @@ describe('matrix-public-archive', () => { await createMessagesInRoom({ client, roomId, - // This should be lesser than the `archiveMessageLimit` + // This should be lesser than the `messageLimit` numMessages: 3, prefix: `foo`, - timestamp: archiveDate.getTime(), + timestamp: FIXED_VIEW_DATE.getTime(), // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging increment: ONE_HOUR_IN_MS, }); - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, archiveDate); - const { data: archivePageHtml } = await fetchEndpointAsText(archiveUrl); - const dom = parseHTML(archivePageHtml); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, FIXED_VIEW_DATE); + const { data: pageHtml } = await fetchEndpointAsText(testUrl); + const dom = parseHTML(pageHtml); // Make sure the time selector is *NOT* visible const timeSelectorElement = dom.document.querySelector(`[data-testid="time-selector"]`); @@ -915,7 +910,7 @@ describe('matrix-public-archive', () => { roomIdOrAlias: inputRoomIdOrAlias, //urlDateTime: actualUrlDateTime, continueAtEvent: inputContinueAtEventId, - } = parseArchiveUrlForRoom(inputUrl); + } = parseMatrixViewerUrlForRoom(inputUrl); let outputContinueAtEventId; if (inputContinueAtEventId) { @@ -990,22 +985,22 @@ describe('matrix-public-archive', () => { eventIdToFancyIdentifierMap.set(tombstoneEventId, fancyEventId); } else { // TODO: Pass `timestamp` massaging option to `createTestRoom()` when it - // supports it, see https://github.com/matrix-org/matrix-public-archive/issues/169 + // supports it, see https://github.com/matrix-org/matrix-viewer/issues/169 roomId = await createTestRoom(client); } const fancyRoomId = `!room${roomIndex + 1}`; fancyIdentifierToRoomIdMap.set(fancyRoomId, roomId); roomIdToFancyIdentifierMap.set(roomId, fancyRoomId); - // Join the archive user to the room before we create the test messages to + // Join the bot user to the room before we create the test messages to // avoid problems jumping to the latest activity since we can't control the // timestamp of the membership event. - const archiveAppServiceUserClient = await getTestClientForAs(); + const botAppServiceUserClient = await getTestClientForAs(); // We use `ensureRoomJoined` instead of `joinRoom` because we're joining - // the archive user here and want the same join `reason` to avoid a new + // the bot user here and want the same join `reason` to avoid a new // state event being created (`joinRoom` -> `{ displayname, membership }` // whereas `ensureRoomJoined` -> `{ reason, displayname, membership }`) - await ensureRoomJoined(archiveAppServiceUserClient.accessToken, roomId); + await ensureRoomJoined(botAppServiceUserClient.accessToken, roomId); // Just spread things out a bit so the event times are more obvious // and stand out from each other while debugging and so we just have @@ -1014,9 +1009,9 @@ describe('matrix-public-archive', () => { testCase.timeIncrementBetweenMessages || ONE_HOUR_IN_MS; for (const eventMeta of room.events) { - const archiveDate = new Date(Date.UTC(2022, 0, eventMeta.dayNumber, 0, 0, 0, 1)); + const viewDate = new Date(Date.UTC(2022, 0, eventMeta.dayNumber, 0, 0, 0, 1)); const originServerTs = - archiveDate.getTime() + eventMeta.eventIndexInDay * eventSendTimeIncrement; + viewDate.getTime() + eventMeta.eventIndexInDay * eventSendTimeIncrement; const content = { msgtype: 'm.text', body: `event${eventMeta.eventNumber} - day${eventMeta.dayNumber}.${eventMeta.eventIndexInDay}`, @@ -1047,9 +1042,9 @@ describe('matrix-public-archive', () => { // Assemble a list of events to to reference and assist with debugging when // some assertion fails for (const [fancyRoomId, roomId] of fancyIdentifierToRoomIdMap.entries()) { - const archiveAppServiceUserClient = await getTestClientForAs(); + const botAppServiceUserClient = await getTestClientForAs(); const eventsInRoom = await getMessagesInRoom({ - client: archiveAppServiceUserClient, + client: botAppServiceUserClient, roomId: roomId, // This is arbitrarily larger than any amount of messages we would ever // send in the tests @@ -1083,9 +1078,9 @@ describe('matrix-public-archive', () => { // -------------------------------------- // -------------------------------------- - // Make sure the archive is configured as the test expects - assert(testCase.archiveMessageLimit); - config.set('archiveMessageLimit', testCase.archiveMessageLimit); + // Make sure the app is configured as the test expects + assert(testCase.messageLimit); + config.set('messageLimit', testCase.messageLimit); // eslint-disable-next-line max-nested-callbacks const pagesKeyList = Object.keys(testCase).filter((key) => { @@ -1115,9 +1110,9 @@ describe('matrix-public-archive', () => { // Get the URL for the first page to fetch // - // Set the `archiveUrl` for debugging if the test fails here + // Set the `testUrl` for debugging if the test fails here const { roomIdOrAlias: startRoomFancyKey, urlDateTime: startUrlDateTime } = - parseArchiveUrlForRoom(urlJoin('https://example.com', testCase.startUrl)); + parseMatrixViewerUrlForRoom(urlJoin('https://example.com', testCase.startUrl)); const startRoomIdOrAlias = fancyIdentifierToRoomIdMap.get(startRoomFancyKey); assert( startRoomIdOrAlias, @@ -1127,7 +1122,7 @@ describe('matrix-public-archive', () => { 2 )}` ); - archiveUrl = `${matrixPublicArchiveURLCreator.archiveUrlForRoom( + testUrl = `${matrixViewerURLCreator.roomUrl( startRoomIdOrAlias )}/date/${startUrlDateTime}`; @@ -1148,7 +1143,7 @@ describe('matrix-public-archive', () => { roomIdOrAlias: expectedRoomFancyId, //urlDateTime: expectedUrlDateTime, continueAtEvent: expectedContinueAtEvent, - } = parseArchiveUrlForRoom(urlJoin('https://example.com', pageTestMeta.url)); + } = parseMatrixViewerUrlForRoom(urlJoin('https://example.com', pageTestMeta.url)); const expectedRoomId = fancyIdentifierToRoomIdMap.get(expectedRoomFancyId); assert( expectedRoomId, @@ -1160,10 +1155,8 @@ describe('matrix-public-archive', () => { ); // Fetch the given page. - const { data: archivePageHtml, res: pageRes } = await fetchEndpointAsText( - archiveUrl - ); - const pageDom = parseHTML(archivePageHtml); + const { data: pageHtml, res: pageRes } = await fetchEndpointAsText(testUrl); + const pageDom = parseHTML(pageHtml); const eventIdsOnPage = [...pageDom.document.querySelectorAll(`[data-event-id]`)] // eslint-disable-next-line max-nested-callbacks @@ -1264,7 +1257,7 @@ describe('matrix-public-archive', () => { // Move to the next iteration of the loop // // Set this for debugging if the test fails here - archiveUrl = nextPageLink; + testUrl = nextPageLink; } catch (err) { const errorWithContext = new RethrownError( `Encountered error while asserting ${pageKey}: (see original error below)`, @@ -1303,7 +1296,7 @@ describe('matrix-public-archive', () => { |--jump-fwd-4-messages-->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -1335,7 +1328,7 @@ describe('matrix-public-archive', () => { |--jump-fwd-4-messages-->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -1361,7 +1354,7 @@ describe('matrix-public-archive', () => { |--jump-fwd-4-messages-->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/04T01:00', page1: { url: '/roomid/room1/date/2022/01/04T01:00', @@ -1387,7 +1380,7 @@ describe('matrix-public-archive', () => { |---jump-fwd-4-messages--->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/03', page1: { url: '/roomid/room1/date/2022/01/03', @@ -1402,7 +1395,7 @@ describe('matrix-public-archive', () => { // creation events which are created in now time vs the timestamp massaging we // do for the message fixtures. We can uncomment this once Synapse supports // timestamp massaging for `/createRoom`, see - // https://github.com/matrix-org/matrix-public-archive/issues/169 + // https://github.com/matrix-org/matrix-viewer/issues/169 // // { // // In order to jump from the 1st page to the 2nd, we first "jump" forward 4 @@ -1419,7 +1412,7 @@ describe('matrix-public-archive', () => { // |---jump-fwd-4-messages--->| // [page2 ] // `, - // archiveMessageLimit: 4, + // messageLimit: 4, // startUrl: '/roomid/room1/date/2022/01/04', // page1: { // url: '/roomid/room1/date/2022/01/04', @@ -1456,7 +1449,7 @@ describe('matrix-public-archive', () => { |-jump-fwd-3-msg->| [page2 ] `, - archiveMessageLimit: 3, + messageLimit: 3, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -1483,7 +1476,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/03', page1: { url: '/roomid/room1/date/2022/01/03', @@ -1511,7 +1504,7 @@ describe('matrix-public-archive', () => { |------------------jump-fwd-8-msg---------------------->| [page2 ] `, - archiveMessageLimit: 8, + messageLimit: 8, startUrl: '/roomid/room1/date/2022/01/04', page1: { url: '/roomid/room1/date/2022/01/04', @@ -1535,7 +1528,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 8, + messageLimit: 8, startUrl: '/roomid/room1/date/2022/01/09', page1: { url: '/roomid/room1/date/2022/01/09', @@ -1550,9 +1543,9 @@ describe('matrix-public-archive', () => { // Test to make sure we can jump forwards from the 1st page to the 2nd page // with too many messages to display on a single day. // - // We jump forward 4 messages (`archiveMessageLimit`), then back-track to + // We jump forward 4 messages (`messageLimit`), then back-track to // the nearest hour which starts us from event9, and then we display 5 - // messages because we fetch one more than `archiveMessageLimit` to + // messages because we fetch one more than `messageLimit` to // determine overflow. testName: 'can jump forward to the next activity and land in too many messages', roomDayMessageStructureString: ` @@ -1563,7 +1556,7 @@ describe('matrix-public-archive', () => { |--jump-fwd-4-messages-->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -1579,11 +1572,11 @@ describe('matrix-public-archive', () => { // when there is a multiple-day gap between the end of the first page to the // next messages. // - // We jump forward 4 messages (`archiveMessageLimit`), then back-track to + // We jump forward 4 messages (`messageLimit`), then back-track to // the nearest hour because even though there is more than a day gap in the // jump, there aren't any mesages in between from another day. Because, we // back-tracked to the nearest hour, this starts us from event9, and then we - // display 5 messages because we fetch one more than `archiveMessageLimit` + // display 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward to the next activity when there is a multiple day gap', roomDayMessageStructureString: ` @@ -1594,7 +1587,7 @@ describe('matrix-public-archive', () => { |--jump-fwd-4-messages-->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -1621,7 +1614,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/04', page1: { url: '/roomid/room1/date/2022/01/04', @@ -1633,9 +1626,9 @@ describe('matrix-public-archive', () => { }, }, { - // We jump forward 4 messages (`archiveMessageLimit`) to event12, then + // We jump forward 4 messages (`messageLimit`) to event12, then // back-track to the nearest hour which starts off at event11 and render the - // page with 5 messages because we fetch one more than `archiveMessageLimit` + // page with 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward from one day with too many messages into the next day with too many messages', @@ -1647,7 +1640,7 @@ describe('matrix-public-archive', () => { |---jump-fwd-4-messages--->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -1673,7 +1666,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/03', page1: { url: '/roomid/room1/date/2022/01/03', @@ -1685,9 +1678,9 @@ describe('matrix-public-archive', () => { }, }, { - // We jump forward 4 messages (`archiveMessageLimit`) to event12, then + // We jump forward 4 messages (`messageLimit`) to event12, then // back-track to the nearest hour which starts off at event11 and render the - // page with 5 messages because we fetch one more than `archiveMessageLimit` + // page with 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward from one day with too many messages into the same day with too many messages', @@ -1699,7 +1692,7 @@ describe('matrix-public-archive', () => { |---jump-fwd-4-messages--->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02T6:00', page1: { url: '/roomid/room1/date/2022/01/02T6:00', @@ -1725,7 +1718,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02T11:00', page1: { url: '/roomid/room1/date/2022/01/02T11:00', @@ -1737,9 +1730,9 @@ describe('matrix-public-archive', () => { }, }, { - // We jump forward 4 messages (`archiveMessageLimit`) to event12, then + // We jump forward 4 messages (`messageLimit`) to event12, then // back-track to the nearest hour which starts off at event11 and render the - // page with 5 messages because we fetch one more than `archiveMessageLimit` + // page with 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward from the middle of one day with too many messages into the next day with too many messages', @@ -1751,7 +1744,7 @@ describe('matrix-public-archive', () => { |---jump-fwd-4-messages--->| [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/02T06:00', page1: { url: '/roomid/room1/date/2022/01/02T06:00', @@ -1778,7 +1771,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/03T06:00', page1: { url: '/roomid/room1/date/2022/01/03T06:00', @@ -1803,7 +1796,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/03T05:00', page1: { url: '/roomid/room1/date/2022/01/03T05:00', @@ -1834,7 +1827,7 @@ describe('matrix-public-archive', () => { // More than a minute for each but less than an hour when you multiply this // across all of messages timeIncrementBetweenMessages: 2 * ONE_MINUTE_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01T01:00', page1: { url: '/roomid/room1/date/2022/01/01T01:00', @@ -1863,7 +1856,7 @@ describe('matrix-public-archive', () => { // More than a minute for each but less than an hour when you multiply this // across all of messages timeIncrementBetweenMessages: 2 * ONE_MINUTE_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -1892,7 +1885,7 @@ describe('matrix-public-archive', () => { // More than a second for each but less than an minute when you multiply // this across all of messages timeIncrementBetweenMessages: 2 * ONE_SECOND_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01T00:01', page1: { url: '/roomid/room1/date/2022/01/01T00:01', @@ -1921,7 +1914,7 @@ describe('matrix-public-archive', () => { // More than a second for each but less than an minute when you multiply // this across all of messages timeIncrementBetweenMessages: 2 * ONE_SECOND_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -1938,9 +1931,9 @@ describe('matrix-public-archive', () => { // because day precision starts off at `T23:59:59.999Z` and jumping forward // will always land us in the next day. { - // We jump forward 4 messages (`archiveMessageLimit`) to event10, then + // We jump forward 4 messages (`messageLimit`) to event10, then // back-track to the nearest minute which starts off at event9 and render the - // page with 5 messages because we fetch one more than `archiveMessageLimit` + // page with 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward to the next activity when less than an hour between all messages', @@ -1955,7 +1948,7 @@ describe('matrix-public-archive', () => { // More than a minute for each but less than an hour when you multiply this // across all of messages timeIncrementBetweenMessages: 2 * ONE_MINUTE_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01T00:11', page1: { url: '/roomid/room1/date/2022/01/01T00:11', @@ -1967,9 +1960,9 @@ describe('matrix-public-archive', () => { }, }, { - // We jump forward 4 messages (`archiveMessageLimit`) to event10, then + // We jump forward 4 messages (`messageLimit`) to event10, then // back-track to the nearest second which starts off at event9 and render the - // page with 5 messages because we fetch one more than `archiveMessageLimit` + // page with 5 messages because we fetch one more than `messageLimit` // to determine overflow. testName: 'can jump forward to the next activity when less than an minute between all messages', @@ -1984,7 +1977,7 @@ describe('matrix-public-archive', () => { // More than a second for each but less than an minute when you multiply this // across all of messages timeIncrementBetweenMessages: 2 * ONE_SECOND_IN_MS, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room1/date/2022/01/01T00:00:11', page1: { url: '/roomid/room1/date/2022/01/01T00:00:11', @@ -2000,7 +1993,7 @@ describe('matrix-public-archive', () => { const jumpBackwardPredecessorTestCases = [ { // Page2 only shows 4 messages ($event4-7) instead of 5 - // (`archiveMessageLimit` + 1) because it also has the tombstone event which + // (`messageLimit` + 1) because it also has the tombstone event which // is hidden testName: 'can jump backward from one room to the predecessor room (different day)', roomDayMessageStructureString: ` @@ -2010,7 +2003,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room2/date/2022/01/03T05:00', page1: { url: '/roomid/room2/date/2022/01/03T05:00', @@ -2023,7 +2016,7 @@ describe('matrix-public-archive', () => { }, { // Page2 only shows 4 messages ($event4-7) instead of 5 - // (`archiveMessageLimit` + 1) because it also has the tombstone event which + // (`messageLimit` + 1) because it also has the tombstone event which // is hidden testName: 'can jump backward from one room to the predecessor room (same day)', roomDayMessageStructureString: ` @@ -2033,7 +2026,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 4, + messageLimit: 4, startUrl: '/roomid/room2/date/2022/01/02T10:00', page1: { url: '/roomid/room2/date/2022/01/02T10:00', @@ -2046,7 +2039,7 @@ describe('matrix-public-archive', () => { }, { // Page2 only shows 3 messages ($event2-4) instead of 4 - // (`archiveMessageLimit` + 1) because it also has the tombstone event which + // (`messageLimit` + 1) because it also has the tombstone event which // is hidden testName: 'jumping back before room was created will go down the predecessor chain', roomDayMessageStructureString: ` @@ -2056,7 +2049,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 3, + messageLimit: 3, startUrl: '/roomid/room4/date/2022/01/08', page1: { url: '/roomid/room4/date/2022/01/08', @@ -2070,8 +2063,8 @@ describe('matrix-public-archive', () => { // This doesn't work well because of the primordial create room events which // we can't control the timestamp of or assert properly in this diagram. If we // ever get timestamp massaging on the `/createRoom` endpoint (see - // https://github.com/matrix-org/matrix-public-archive/issues/169), we could - // make this work by increasing the `archiveMessageLimit` to something that + // https://github.com/matrix-org/matrix-viewer/issues/169), we could + // make this work by increasing the `messageLimit` to something that // would encompass all of the primordial events along with the last few // messages. // @@ -2085,7 +2078,7 @@ describe('matrix-public-archive', () => { // [page2] // [page3 ] // `, - // archiveMessageLimit: 4, + // messageLimit: 4, // startUrl: '/roomid/room2/date/2022/01/03', // page1: { // url: '/roomid/room2/date/2022/01/03', @@ -2107,11 +2100,11 @@ describe('matrix-public-archive', () => { // We jump from event3 which is found as the closest event looking forward // from the ts=0 in the successor room because the timestamp massaged events // come before `m.room.create` and other primordial events here (related to - // https://github.com/matrix-org/matrix-public-archive/issues/169). From - // event3, we jump forward 10 messages (`archiveMessageLimit`) to event12, + // https://github.com/matrix-org/matrix-viewer/issues/169). From + // event3, we jump forward 10 messages (`messageLimit`) to event12, // then back-track to the nearest hour which starts off at event11 and try // to render the page with 11 messages because we fetch one more than - // `archiveMessageLimit` to determine overflow but there aren't enough + // `messageLimit` to determine overflow but there aren't enough // messages. testName: 'can jump forward from one room to the successor room (different day)', roomDayMessageStructureString: ` @@ -2122,7 +2115,7 @@ describe('matrix-public-archive', () => { |------------------jump-fwd-10-messages----------------->| [page2 ] `, - archiveMessageLimit: 10, + messageLimit: 10, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -2137,10 +2130,10 @@ describe('matrix-public-archive', () => { // We jump from event8 which is found as the closest event looking forward // from the ts=0 in the successor room because the timestamp massaged events // come before `m.room.create` and other primordial events here (related to - // https://github.com/matrix-org/matrix-public-archive/issues/169). From - // event8, we jump forward 10 messages (`archiveMessageLimit`) to the end of + // https://github.com/matrix-org/matrix-viewer/issues/169). From + // event8, we jump forward 10 messages (`messageLimit`) to the end of // the room, then go to the day of the last message which will show us all - // messages in room2 because we fetch one more than `archiveMessageLimit` to + // messages in room2 because we fetch one more than `messageLimit` to // determine overflow which is more messages than room2 has. testName: 'can jump forward from one room to the successor room (same day)', roomDayMessageStructureString: ` @@ -2151,7 +2144,7 @@ describe('matrix-public-archive', () => { |------------------jump-fwd-10-messages----------------------->| [page2 ] `, - archiveMessageLimit: 10, + messageLimit: 10, startUrl: '/roomid/room1/date/2022/01/02T05:00', page1: { url: '/roomid/room1/date/2022/01/02T05:00', @@ -2166,11 +2159,11 @@ describe('matrix-public-archive', () => { // We jump from event3 which is found as the closest event looking forward // from the ts=0 in the successor room because the timestamp massaged events // come before `m.room.create` and other primordial events here (related to - // https://github.com/matrix-org/matrix-public-archive/issues/169). From - // event3, we jump forward 10 messages (`archiveMessageLimit`) to event13, + // https://github.com/matrix-org/matrix-viewer/issues/169). From + // event3, we jump forward 10 messages (`messageLimit`) to event13, // then back-track to the nearest hour which starts off at event11 and try // to render the page with 11 messages because we fetch one more than - // `archiveMessageLimit` to determine overflow but there aren't enough + // `messageLimit` to determine overflow but there aren't enough // messages. testName: 'can jump forward from one room to the successor room (multiple day gap)', roomDayMessageStructureString: ` @@ -2181,7 +2174,7 @@ describe('matrix-public-archive', () => { |----------------jump-fwd-10-messages------------------->| [page2 ] `, - archiveMessageLimit: 10, + messageLimit: 10, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -2200,17 +2193,17 @@ describe('matrix-public-archive', () => { // to the successor room and find the closest event from ts=0 looking // forward which is event5 because the timestamp massaged events come before // `m.room.create` and other primordial events here (related to - // https://github.com/matrix-org/matrix-public-archive/issues/169). From - // event5, we jump forward 10 messages (`archiveMessageLimit`) to event14, + // https://github.com/matrix-org/matrix-viewer/issues/169). From + // event5, we jump forward 10 messages (`messageLimit`) to event14, // then back-track to the *day* before the last message found which starts off // at event6 and try to render the page with 11 messages because we fetch - // one more than `archiveMessageLimit` to determine overflow but there + // one more than `messageLimit` to determine overflow but there // aren't enough messages. // // For the jump from page3 to page4, we jump forward 10 messages to event16, // then back-track to the nearest hour which starts off at event15 and try // to render the page with 11 messages because we fetch one more than - // `archiveMessageLimit`. + // `messageLimit`. testName: 'can jump forward from one room to the successor room (across multiple days)', roomDayMessageStructureString: ` [room1 ] [room2 ] @@ -2224,7 +2217,7 @@ describe('matrix-public-archive', () => { |----------------------jump-fwd-10-messages----------------------->| [page4 ] `, - archiveMessageLimit: 10, + messageLimit: 10, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -2259,7 +2252,7 @@ describe('matrix-public-archive', () => { |----------------------jump-fwd-10-messages----------------------->| [page4 ] `, - archiveMessageLimit: 10, + messageLimit: 10, startUrl: '/roomid/room1/date/2022/01/01', page1: { url: '/roomid/room1/date/2022/01/01', @@ -2289,7 +2282,7 @@ describe('matrix-public-archive', () => { [page1 ] [page2 ] `, - archiveMessageLimit: 3, + messageLimit: 3, startUrl: '/roomid/room1/date/2022/01/02', page1: { url: '/roomid/room1/date/2022/01/02', @@ -2386,9 +2379,9 @@ describe('matrix-public-archive', () => { it(testTitle, async () => { // The date should be just past midnight so we don't run into inclusive // bounds leaking messages from one day into another. - const archiveDate = new Date(Date.UTC(2022, 0, 1, 0, 0, 0, 1)); + const viewDate = new Date(Date.UTC(2022, 0, 1, 0, 0, 0, 1)); - config.set('archiveMessageLimit', 3); + config.set('messageLimit', 3); const client = await getTestClientForHs(testMatrixServerUrl1); const roomId = await createTestRoom(client); @@ -2400,13 +2393,13 @@ describe('matrix-public-archive', () => { // for another page of history numMessages: 10, prefix: `foo`, - timestamp: archiveDate.getTime(), + timestamp: viewDate.getTime(), increment: testCase.durationMinMs, }); const fourthEvent = eventMap.get(eventIds[3]); const sixthEvent = eventMap.get(eventIds[5]); - const jumpUrl = `${matrixPublicArchiveURLCreator.archiveJumpUrlForRoom(roomId, { + const jumpUrl = `${matrixViewerURLCreator.jumpUrlForRoom(roomId, { dir: directionValue, currentRangeStartTs: fourthEvent.originServerTs, currentRangeEndTs: sixthEvent.originServerTs, @@ -2431,17 +2424,17 @@ describe('matrix-public-archive', () => { const testCases = [ { testName: 'now is present', - archiveDate: nowDate, + viewDate: nowDate, expectedTemporalContext: 'present', }, { testName: 'start of today is present', - archiveDate: new Date(getUtcStartOfDayTs(nowDate)), + viewDate: new Date(getUtcStartOfDayTs(nowDate)), expectedTemporalContext: 'present', }, { testName: 'some time today is present', - archiveDate: new Date( + viewDate: new Date( getUtcStartOfDayTs(nowDate) + 12 * ONE_HOUR_IN_MS + 30 * ONE_MINUTE_IN_MS + @@ -2451,7 +2444,7 @@ describe('matrix-public-archive', () => { }, { testName: 'past is in the past', - archiveDate: new Date('2020-01-01'), + viewDate: new Date('2020-01-01'), expectedTemporalContext: 'past', }, ]; @@ -2464,30 +2457,27 @@ describe('matrix-public-archive', () => { testCases.forEach((testCase) => { assert(testCase.testName); - assert(testCase.archiveDate); + assert(testCase.viewDate); assert(testCase.expectedTemporalContext); // Warn if it's close to the end of the UTC day. This test could be a flakey and // cause a failure if `expectedTemporalContext` was created just before midnight - // (UTC) and we visit the archive after midnight (UTC). The - // `X-Date-Temporal-Context` would read as `past` when we expect `present`. + // (UTC) and we visit after midnight (UTC). The `X-Date-Temporal-Context` would + // read as `past` when we expect `present`. if (roundUpTimestampToUtcDay(nowDate) - nowDate.getTime() < 30 * 1000 /* 30 seconds */) { // eslint-disable-next-line no-console console.warn( `Test is being run at the end of the UTC day. This could result in a flakey ` + `failure if \`expectedTemporalContext\` was created just before midnight (UTC) ` + - `and we visit the archive after midnight (UTC). Since ` + + `and we visit after midnight (UTC). Since ` + `this is an e2e test we can't control the date/time exactly.` ); } it(testCase.testName, async () => { // Fetch the given page. - archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate( - roomId, - testCase.archiveDate - ); - const { res } = await fetchEndpointAsText(archiveUrl); + testUrl = matrixViewerURLCreator.roomUrlForDate(roomId, testCase.viewDate); + const { res } = await fetchEndpointAsText(testUrl); const dateTemporalContextHeader = res.headers.get('X-Date-Temporal-Context'); assert.strictEqual(dateTemporalContextHeader, testCase.expectedTemporalContext); @@ -2521,7 +2511,7 @@ describe('matrix-public-archive', () => { // // (we set this here in case we timeout while waiting for the test rooms to // appear in the room directory) - archiveUrl = matrixPublicArchiveURLCreator.roomDirectoryUrl(); + testUrl = matrixViewerURLCreator.roomDirectoryUrl(); // Try to avoid flakey tests where the homeserver hasn't added the rooms to the // room directory yet. This isn't completely robust as it doesn't check that the @@ -2535,7 +2525,7 @@ describe('matrix-public-archive', () => { searchTerm: roomMarsName, }); - const { data: roomDirectoryPageHtml } = await fetchEndpointAsText(archiveUrl); + const { data: roomDirectoryPageHtml } = await fetchEndpointAsText(testUrl); const dom = parseHTML(roomDirectoryPageHtml); const roomsOnPageWithoutSearch = [ @@ -2546,10 +2536,10 @@ describe('matrix-public-archive', () => { // Then browse the room directory again, this time with the search // narrowing down results. - archiveUrl = matrixPublicArchiveURLCreator.roomDirectoryUrl({ + testUrl = matrixViewerURLCreator.roomDirectoryUrl({ searchTerm: roomPlanetPrefix, }); - const { data: roomDirectoryWithSearchPageHtml } = await fetchEndpointAsText(archiveUrl); + const { data: roomDirectoryWithSearchPageHtml } = await fetchEndpointAsText(testUrl); const domWithSearch = parseHTML(roomDirectoryWithSearchPageHtml); const roomsOnPageWithSearch = [ @@ -2586,7 +2576,7 @@ describe('matrix-public-archive', () => { // (we set this here in case we timeout while waiting for the test rooms to // appear in the room directory) - archiveUrl = matrixPublicArchiveURLCreator.roomDirectoryUrl({ + testUrl = matrixViewerURLCreator.roomDirectoryUrl({ homeserver: HOMESERVER_URL_TO_PRETTY_NAME_MAP[testMatrixServerUrl2], searchTerm: roomPlanetPrefix, }); @@ -2602,7 +2592,7 @@ describe('matrix-public-archive', () => { searchTerm: roomYname, }); - const { data: roomDirectoryWithSearchPageHtml } = await fetchEndpointAsText(archiveUrl); + const { data: roomDirectoryWithSearchPageHtml } = await fetchEndpointAsText(testUrl); const domWithSearch = parseHTML(roomDirectoryWithSearchPageHtml); // Make sure the `?homserver` is selected in the homeserver selector `