This change enables CORS support in the archive — to allow web developers to create web applications with frontend JavaScript code that can fetch pages from the archive (for example, for scraping content from chat logs).
Otherwise, without this change, web developers can’t create web apps with frontend JavaScript that can fetch chat logs from the archive and then consume the content of the logs.
It’s imaginable that web developers may find use cases for consuming the chat logs in the archive from frontend JavaScript code — at the simplest level, web apps that fetch and scrape logs to get data out of them or to pull out particular snippets from the logs.
Developers can anyway already scrape the contents of the archive — by using server-side programming languages or by using `curl` or whatever from the command line. They just can’t do the same from frontend JavaScript code, unless CORS support is enabled.
Fixes https://github.com/matrix-org/matrix-public-archive/issues/141
Node.js v19 has `crypto` set on the global already, so this change causes `vmContext.global.crypto` to be assigned only if `vmContext.global.crypto` isn’t already defined.
Otherwise, without this change, the room directory fails to render in Node.js v19+, and instead _"TypeError: Cannot set property crypto of `#<Object>` which has only a getter"_ gets thrown.
This might be a little ambiguous since we'll have permalinks within the Matrix Public Archive with `?at=$xxx` (related https://github.com/matrix-org/matrix-public-archive/issues/137) which is different from `matrix.to` permalinks 🤔
But will just go with it for now ⏩
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)
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.
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
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
**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
```
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.
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
```
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
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
```
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
```
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 `/`.
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)
```
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
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.