Rename project from "Matrix Public Archive" to "Matrix Viewer" (#280)

Mentioned in the recent blog post: https://matrix.org/blog/2023/07/what-happened-with-the-archive/#next-steps

The canonical `view.matrix.org` instance is not live yet but this is pre-requisite work for that to happen.
madlittlemods/slightly-more-robust-seamless-pagination-test
Eric Eastwood 7 months ago committed by GitHub
parent 1d1d7d2d0d
commit 5d444d5044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 }}

@ -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

@ -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

@ -1,21 +1,28 @@
# Matrix Public Archive
# Matrix Viewer
<a href="https://matrix.to/#/#matrix-public-archive:matrix.org"><img src="https://img.shields.io/matrix/matrix-public-archive:matrix.org.svg?label=%23matrix-public-archive%3Amatrix.org&logo=matrix&server_fqdn=matrix.org" alt="Join the community and get support at #matrix-public-archive:matrix.org" /></a>
<a href="https://matrix.to/#/#matrix-viewer:matrix.org"><img src="https://img.shields.io/matrix/matrix-viewer:matrix.org.svg?label=%23matrix-viewer%3Amatrix.org&logo=matrix&server_fqdn=matrix.org" alt="Join the community and get support at #matrix-viewer:matrix.org" /></a>
> **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/) ๐ŸŒŒ
<!-- prettier-ignore -->
Room directory homepage | Archive room view
Room directory homepage | Room view
--- | ---
<img alt="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." src="https://user-images.githubusercontent.com/558581/236579462-fee0f9c0-29d2-4c3d-a695-c9eaf0f744ef.png" width="440"> | ![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)
<img alt="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." src="https://user-images.githubusercontent.com/558581/236579462-fee0f9c0-29d2-4c3d-a695-c9eaf0f744ef.png" width="440"> | ![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
```

@ -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

@ -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 */

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

@ -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';

@ -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

@ -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';

@ -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,

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

@ -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`).

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

10
package-lock.json generated

@ -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": {

@ -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"

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

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

@ -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}`);
}
}

@ -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) {

@ -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');

@ -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');

@ -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*.

@ -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;

@ -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:

@ -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),

@ -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
);
}

@ -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',

@ -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,

@ -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;