Commit Graph

130 Commits

Author SHA1 Message Date
Eric Eastwood 776347207e
Updates to be compatible with the latest Hydrogen changes (rename `urlCreator` -> `urlRouter`) (#134)
Hydrogen changes:

 - https://github.com/vector-im/hydrogen-web/pull/918
2022-11-10 17:37:08 -06:00
Eric Eastwood 8a2dabe97b
Fix room image avatars not showing in the room directory (#133)
Fix room image avatars not showing in the room directory

Fix https://github.com/matrix-org/matrix-public-archive/issues/95
2022-11-10 00:29:44 -06:00
Eric Eastwood 3d604a1d87
Update Hydrogen SDK dependency 0.23.0-scratch (#131) 2022-11-09 19:07:30 -06:00
Eric Eastwood fa4720af04
Increase perceived performance by scrolling to the right spot before Hydrogen loads (#128) 2022-11-09 18:57:33 -06:00
Eric Eastwood 3671da0405
Fix NPE with non-existent event permalink `?at=$doesnotexist` (#130) 2022-11-09 02:07:10 -06:00
Eric Eastwood dc85e839a1
Add config to disable search engine indexing (#127) 2022-11-08 22:41:58 -06:00
Eric Eastwood b3c553a863
Add comment reference to issue about adding hour chunk time slices (#126) 2022-11-08 22:35:28 -06:00
Eric Eastwood 026a08a77a
Jump forward and backward seamlessly (#121)
Fix https://github.com/matrix-org/matrix-public-archive/issues/120
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/114

 - Uses event permalinking (`?at=$xxx`) to continue the scroll where you should start reading again.
 - When we jump forwards, we make sure that we go a day back to ensure there isn't more than the page limit between where we jumped from and the day so we don't lose any messages in a gap.
2022-11-03 05:06:53 -05:00
Eric Eastwood 5bae040d72
Add permalink highlighting - `?at=$xxx` (#123)
ex.
```
http://localhost:3050/r/test-room1:my.synapse.server/date/2022/07/28?at=$O9fDg42JoSh9VdcL820FDUS0Gi_CkPt_hrN1pK1fPEY
````

Fix https://github.com/matrix-org/matrix-public-archive/issues/4

Split out from https://github.com/matrix-org/matrix-public-archive/pull/121
2022-11-03 04:49:07 -05:00
Eric Eastwood 2dff7ecea5
Refactor `fetchEndpointAsText`/`fetchEndpointAsJson` to return `res` alongside `data` (#122)
Split out of https://github.com/matrix-org/matrix-public-archive/pull/121
where we needed to use `res.url`.
2022-11-03 04:12:00 -05:00
Eric Eastwood 91d84fcc08
Don't change the URL as you scroll around (#119)
Fix https://github.com/matrix-org/matrix-public-archive/issues/115

Reverting behavior originally introduced in https://github.com/matrix-org/matrix-public-archive/pull/71
2022-11-02 04:35:36 -05:00
Eric Eastwood 08254cbb49
Add a way to jump forwards and backwards to more activity in the room (seamless navigation) (#114)
Fix https://github.com/matrix-org/matrix-public-archive/issues/46
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/71

Summary:

 - Changes the "Jump to next activity in room" to actually continue you to the next 100 messages ahead. Previously, it only jumped you to the single next event in the room which meant a lot of backwards overlap each time.
    - Jumping this direction will also start your scroll position at the top of the timeline to continue reading seamlessly `?continue=top`
 - Adds "Jump to previous activity in room" to the top of the timeline to continue reading the previous part of the conversation.

[1]: There is a caveat with seamless here which is also commented on in the code:

> XXX: This is flawed in the fact that when we go `/messages?dir=b` it could  backfill messages which will fill up the response before we perfectly connect and  continue from the position they were jumping from before. When `/messages?dir=f`  backfills, we won't have this problem anymore because any messages backfilled in  the forwards direction would be picked up the same going backwards.

(need forwards fill MSC)
2022-11-02 04:27:30 -05:00
Eric Eastwood dc7017ae4c
Move Hydrogen `timelineViewModel` creation to our main view model (#118)
Move Hydrogen `timelineViewModel` creation to our main view model.

Was it better to keep this Hydrogen boilerplate outside? Maybe 🤷. It's possible that all of this will go away with something like https://github.com/MadLittleMods/hydrogen-static-archives-prototype/pull/2

Should we also move the [`room` VM creation](8275f120a6/shared/hydrogen-vm-render-script.js (L88-L111))? Maybe but it's not as much noise as all of this tile/timeline stuff.
2022-11-01 08:54:43 -05:00
Eric Eastwood 718f01e5a4
Refactor to use `TimelineView` (#117)
We have to figure out our own layout but does get rid of some of the `RoomView` boilerplate.
The `TimelineView` still has outside boilerplate styles to work.

There shouldn't be any visible change.
2022-11-01 08:36:32 -05:00
Eric Eastwood b75b807865
Small readme updates (#112) 2022-10-28 00:44:40 -05:00
Eric Eastwood 2b4ecb737a
Add support for client-side room alias hash `#` redirects to the correct URL (#111)
This helps when someone just pastes a room alias on the end of the domain,

 - `/#room-alias:server` -> `/r/room-alias:server`
 - `/r/#room-alias:server/date/2022/10/27` -> `/r/room-alias:server/date/2022/10/27`

Since these redirects happen on the client, we can't write any e2e tests. Those e2e tests do everything but run client-side JavaScript.

Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/107

Part of https://github.com/matrix-org/matrix-public-archive/issues/25
2022-10-28 00:32:24 -05:00
Eric Eastwood 7a88ea0c19
Add support for room aliases (#107)
Also does friendly redirects if you don't exactly use the right URL pattern.
For example, if you paste the full room ID with the `!` like `/roomid/!foo:bar`,
it will properly redirect you to `/roomid/foo:bar`. It also does this sort of
thing for URL encoded room ID's and aliases.

Fix https://github.com/matrix-org/matrix-public-archive/issues/25
2022-10-27 01:09:13 -05:00
Eric Eastwood b7c00c31c1
Fix URL being duplicated in query param (#110)
Fix https://github.com/matrix-org/matrix-public-archive/pull/104#discussion_r1004023030

### What was the problem?

We were previously seeing this behavior with the old code:

```
Before: http://localhost:3050/!xxx:server/date/2022/09/20?via=my.synapse.server
replaceUrlSilently(url='http://localhost:3050/!xxx:server/date/2022/09/20')`
After: http://localhost:3050/!xxx:server/date/2022/09/20?via=my.synapse.serverhttp://localhost:3050/!xxx:server/date/2022/07/29
```

Because `replacingUrl` was evaluating to `replacingUrl = '?via=my.synapse.serverhttp://192.168.1.151:3050/!HBehERstyQBxyJDLfR:my.synapse.server/date/2022/07/29'` which is relative and was appended to the current URL.


### Solution

Now with the new code, we more clearly handle the 3 cases:

 - Normal Hydrogen `#/foo-bar` hash routing on the end of the URL
 - When `url=''` and we just need clear the Hydrogen hash route and maintain the current path and query parameters
 - An absolute URL which we can completely replace the page URL with
2022-10-25 01:59:23 -05:00
Eric Eastwood d19c08397a
Fixup room directory fetch error message (#108)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/96
2022-10-24 15:49:23 -05:00
Eric Eastwood 2bda335f1c
Clean up spurious logs when SSR rendering Hydrogen (#106)
**Before:**

```
Child printed something to stdout: Mounting Hydrogen...

Child printed something to stderr: Skipping `addedHomservers` read from LocalStorage since LocalStorage is not available

Child printed something to stdout: Completed mounting Hydrogen: 22.188ms

Child printed something to stdout: 2 uncaughtException TypeError: this.dialogNode.close is not a function
    at ModalView.closeModal (C:\Users\MLM\Documents\GitHub\element\matrix-public-archive\shared\views\ModalView.js:115:21)
    at Timeout._onTimeout (C:\Users\MLM\Documents\GitHub\element\matrix-public-archive\shared\views\ModalView.js:87:18)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
```


**After:**

```
Child printed something to stdout: Mounting Hydrogen...

Child printed something to stderr: Skipping `addedHomservers` read from LocalStorage since LocalStorage is not available

Child printed something to stdout: Completed mounting Hydrogen: 14.2ms
```
2022-10-21 17:27:10 -05:00
Eric Eastwood 7c09ac13f9
Fix form <select> value not being up to date by the time we auto-submit the form on selection (#105)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/102#discussion_r1002190782
2022-10-21 16:24:22 -05:00
Eric Eastwood d2d6c5a580
Link rooms with `?via` query paramter from room directory landing page (#104)
Fix https://github.com/matrix-org/matrix-public-archive/issues/91

So we're always able to join the room from our origin homeserver to the remote room we don't know about yet.
2022-10-21 16:06:11 -05:00
Eric Eastwood 3b4fb52bfe
Fix pagination links not accounting for homeserver selection (#103)
Fix https://github.com/matrix-org/matrix-public-archive/issues/93

Previously caused the `?homeserver` query parameter to be lost when paginating
2022-10-21 15:52:07 -05:00
Eric Eastwood 048f03fff7
Stop using `selectEl.value` as crutch over swapping `selected` attribute (#102)
Originally introduced in:

 - https://github.com/matrix-org/matrix-public-archive/pull/87
 - https://github.com/matrix-org/matrix-public-archive/pull/98
2022-10-21 15:35:11 -05:00
Eric Eastwood dcc2f5dd03
Fix typo in room fetch error section (#100) 2022-10-21 02:15:42 -05:00
Eric Eastwood 1e89179f09
Page-load with the correct homeserver selected (#98)
Page-load with the correct homeserver selected (according to `?homeserver`).

Fix https://github.com/matrix-org/matrix-public-archive/issues/92

Also makes sure that the `?homeserver` is always available somewhere in the list; whether that be in the available homeserver list or the added homeserver list depending on it someone cleared it out or never had it because they visited from someone else's link.
2022-10-21 02:09:26 -05:00
Eric Eastwood 75d4a14845
Fix hash and query parameter ordering and repeating (#99)
This would happen after opening the "Add server" modal

Before:
```
/?search=&homeserver=foo.bar#/add-server?search=&homeserver=foo.bar
```

After:
```
/?search=&homeserver=foo.bar#/add-server
```
2022-10-21 01:14:06 -05:00
Eric Eastwood 6bb88b1ecd
Load room directory and show error message when we're unable to fetch rooms (#96)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/84 to address https://github.com/matrix-org/matrix-public-archive/issues/80

Also explains why we show the details of the error message.

Part of https://github.com/matrix-org/internal-config/issues/1342

Related to https://github.com/matrix-org/matrix-public-archive/issues/97
2022-10-20 22:48:00 -05:00
Eric Eastwood b34c1b817d
Add homeserver selector to room directory landing page (#87)
Opting for the simple solution and using `include_all_networks` instead of needing to fetch the information about the third-party networks.

Fix https://github.com/matrix-org/matrix-public-archive/issues/6 (last piece done with this PR)
2022-10-20 02:06:43 -05:00
Eric Eastwood a0089b0fe4
Add `Content-Security-Policy` (CSP) (#81)
Add `Content-Security-Policy` (CSP) that restricts the page to just what it is expected to do.

This helps limit the damage that can be done by any XSS attack.

Fix https://github.com/matrix-org/internal-config/issues/1341
2022-10-19 12:07:39 -05:00
Eric Eastwood 0962075f8d
Improve performance of scrolling on room directory (animating gradient and shadow header) (#90) 2022-10-19 01:50:16 -05:00
Eric Eastwood 27ed76c7a9
Implement `ModalView` with native `<dialog>` element (#88)
The main benefit we're getting from this refactor is semantics, `Escape` to close modal, and focus lock.

We have one existing modal with the Developer Options.

This refactor is happening so it can be used to add a new homeserver in the homeserver selector on the room directory page, https://github.com/matrix-org/matrix-public-archive/pull/87
2022-10-19 01:04:19 -05:00
Eric Eastwood 5142e508a2
Have full room description readable from tooltip (#85)
The `RoomCard`  clips text two lines before ellipsing. This will make the rest of the description readable if you hover over the description.
2022-10-18 18:38:00 -05:00
Eric Eastwood f9e16964e1
Fix off-by-one calendar months with time zones that are greater than UTC+0 (#86)
Fix off-by-one calendar months with time zones that are greater than UTC+0 (GMT+0).

Fix https://github.com/matrix-org/matrix-public-archive/issues/77

Previously, we would calculate `lastDayOfTheMonthDate` in the local timezone because we were using the vanilla `new Date(year, month, 0)` constructor. For any timezone greater than `UTC+0` (like London UTC+1 or Korea UTC +9), this means that the date is a day-behind when we go back to UTC+0.

**Before:**

```
inputDate Fri, 29 Jul 2022 00:00:00 GMT 1659052800000
lastDayOfTheMonthDate Sat, 30 Jul 2022 23:00:00 GMT 1659222000000
lastDayOfTheMonth 30
```

**After**

```
inputDate Fri, 29 Jul 2022 00:00:00 GMT 1659052800000
lastDayOfTheMonthDate Sun, 31 Jul 2022 00:00:00 GMT 1659225600000
lastDayOfTheMonth 31
```
2022-10-18 18:36:13 -05:00
Eric Eastwood df89750401
Throw more understandable error when we fail to fetch from the homeserver room directory (#84)
Fix https://github.com/matrix-org/matrix-public-archive/issues/80

```
RethrownError: Unable to fetch rooms from room directory (homeserver=http://localhost:8008/)
    searchTerm=, paginationToken=undefined, limit=9
    at matrix-public-archive\server\routes\room-directory-routes.js:55:13
    --- Original Error ---
    Error: HTTP Error Response: 500 Internal Server Error: {"errcode":"M_UNKNOWN","error":"Internal server error"}
        URL=http://localhost:8008/_matrix/client/v3/publicRooms?
        at checkResponseStatus (matrix-public-archive\server\lib\fetch-endpoint.js:21:11)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async fetchEndpoint (matrix-public-archive\server\lib\fetch-endpoint.js:38:3)
        at async fetchEndpointAsJson (matrix-public-archive\server\lib\fetch-endpoint.js:63:15)
        at async fetchPublicRooms (matrix-public-archive\server\lib\matrix-utils\fetch-public-rooms.js:26:26)
        at async matrix-public-archive\server\tracing\trace-utilities.js:31:24
        at async matrix-public-archive\server\routes\room-directory-routes.js:45:62
```
2022-10-18 16:42:33 -05:00
Eric Eastwood b8062b16a2
Fix wrong path to Hydrogen styles on timeout error page (#83)
Regressed in https://github.com/matrix-org/matrix-public-archive/pull/61 where we tried to serve this under `/css/hydrogen-styles.css` but it doesn't work because all of the image and font references in the CSS file expect it to be at the domain root so just reverted back to serving at the root `/`.
2022-10-18 03:42:37 -05:00
Eric Eastwood f796afe55e
Sanity check that we are not leaking the access token to the client (#82)
This isn't spawning from any previous security issue. Just adding an extra check to help ensure we don't ever regress this in the future.

```
AssertionError [ERR_ASSERTION]: We should not be leaking the `config.matrixAccessToken` to the Hydrogen render function because this will reach the client!
    at renderHydrogenToString (matrix-public-archive\server\hydrogen-render\render-hydrogen-to-string.js:24:3)
    at renderHydrogenVmRenderScriptToPageHtml (matrix-public-archive\server\hydrogen-render\render-hydrogen-vm-render-script-to-page-html.js:22:36)
    at matrix-public-archive\server\routes\room-directory-routes.js:53:28
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
```
2022-10-18 02:40:40 -05:00
Eric Eastwood 1d77c721d0
Use rainbow Matrix.org gradient (#75)
Another iteration of the design,
https://www.figma.com/file/lpW5CqaEbPsYX2pmfIhzRo/Matrix-Public-Archive

Part of https://github.com/matrix-org/matrix-public-archive/issues/6
2022-10-18 01:30:26 -05:00
Eric Eastwood 2581f88495
Fix XSS when blatting `window.matrixPublicArchiveContext` to the page (#79)
Fix https://github.com/matrix-org/internal-config/issues/1335
2022-10-13 14:36:04 -05:00
Eric Eastwood ff315141fd
Add domain to tracing service to distinguish different Matrix public archive instances (#76) 2022-10-11 16:03:33 -05:00
Eric Eastwood b39d7caf31
Add linting to CI (#74)
- Prettier
 - ESLint
2022-09-27 22:21:00 -05:00
Eric Eastwood be837515fe
Show surrounding messages for a full screen of content (#71)
1. Add surrounding messages to the given messages so we have a full screen of content to make it feel lively even in quiet rooms
    - As you scroll around the timeline across different days, the date changes in the URL, calendar, etc
 2. Add summary item to the bottom of the timeline that explains if we couldn't find any messages in the specific day requested 
    - Also allows you to the jump to the next activity in the room. Adds `/:roomId/jump?ts=xxx&dir=[f|b]` to facilitate this.
    - Part of https://github.com/matrix-org/matrix-public-archive/issues/46
 3. Add developer options modal which is linked from the bottom of the right-panel
    - Adds an option so you can debug the `IntersectionObserver` and how it's selecting the active day from the top-edge of the scroll viewport.
    - In the future, this will also include a nice little visualization of the backend timing traces
2022-09-20 16:02:09 -05:00
Eric Eastwood 92668996d7
Add search to room directory landing page (#70)
Part of https://github.com/matrix-org/matrix-public-archive/issues/6
2022-09-15 20:41:55 -05:00
Eric Eastwood f73246768f
Bigger more clickable buttons on mobile (#69)
Bigger more clickable buttons on mobile. Feels a lot better on a phone. The buttons already have invisible margin in their hitbox but the bigger size makes your thumb less cramped to the edge to click them.

Also reduce the container padding so it feels more balanced in the single column card layout.
2022-09-08 22:32:06 -05:00
Eric Eastwood b7597b2749
Add clickjacking prevention middleware (#68)
Fix https://github.com/matrix-org/matrix-public-archive/issues/67
2022-09-08 19:30:20 -05:00
Eric Eastwood 32c77ecffe
Only show `world_readable` or `public` rooms in the archive. Only index `world_readable` (#66)
Only show `world_readable` or `public` rooms in the archive. Only allow `world_readable` rooms to be indexed by search engines.

Related to https://github.com/matrix-org/matrix-public-archive/issues/47
2022-09-08 19:15:07 -05:00
Eric Eastwood 65a371910a
Redirect to last day with message history (#65)
Redirect to last day with message history: `/:roomIdOrAlias` -> `/:roomIdOrAlias/date/:yyyy/:mm/:dd`

Fix https://github.com/matrix-org/matrix-public-archive/issues/60
2022-09-08 02:18:18 -05:00
Eric Eastwood 127d416e6a
Room directory landing page v1 (#61)
Part of https://github.com/matrix-org/matrix-public-archive/issues/6
2022-09-08 01:30:04 -05:00
Eric Eastwood 02b86a8405
Render pipeline separation of concerns (#64)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/36

Render pipeline separation of concerns:

 1. Run in `child_process`
 2. Hydrogen render
 
It's now just a generic `child_process` runner that runs the Hydrogen render in it. This eliminates the windy path of the 1-4 steps that was only held together by the file names themselves.
2022-09-02 20:49:06 -05:00
Eric Eastwood f6bd581f77
Better `child_process` error handling v2 - timeouts and actually fail process for error in scope (#62)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/51

Better `child_process` error handling for a couple scenarios with the finger pointing at it 👉

Also make sure we handle all of these scenarios:

 1. Child process fork script throws an `uncaughtException` or `unhandledRejection`
    - These are captured and serialized back to the parent and stored in `childErrors` and exposed if we never get a successful rendered HTML response.
 2. Child process fails to startup 
    - Render process is rejected in the `child.on('error', ...` callback
 3. 👉 Child process times out and is aborted
    - Render process is rejected in the `child.on('error', ...` callback and any `childErrors` encountered are logged
 4. 👉 Child process fork script throws an error in scope of in `process.on('message', async (renderOptions) => {`
    - Child exits with code 1 and we reject the render process with the error
 5. Child process exits with code 1 (error)
    - Render process is rejected with any `childError` info
 6. Child process exits with code 0 (success) but never sends back any HTML
    - We have a `returnedData` data check and any child errors encountered are logged
2022-09-02 18:49:45 -05:00