Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC3030: Jump to date API endpoint #3030

Merged
merged 28 commits into from Nov 6, 2022
Merged
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f4aa923
Initial MSC draft for jump to date
MadLittleMods Feb 25, 2021
11025d6
Update with alternate /timestamp_to_event endpoint
MadLittleMods Nov 17, 2021
95cd693
Add origin_server_ts for quick remote to local comparison
MadLittleMods Nov 30, 2021
13910e7
Add origin_server_ts to client endpoint
MadLittleMods Nov 30, 2021
2559770
Wrap lines
MadLittleMods Dec 3, 2021
f19a43a
Use stable when discussing MSC and document unstable
MadLittleMods Dec 3, 2021
f87a4f2
Describe the direction parameter
MadLittleMods Dec 3, 2021
d9b0bed
Add server support detection
MadLittleMods Dec 15, 2021
cc6a4a3
Fix typos
MadLittleMods Jan 18, 2022
2c8cdd8
Explain what happens when an event can't be found
MadLittleMods Jan 19, 2022
9aa73f4
Add context behind why we chose /timestamp_to_event vs alternatives
MadLittleMods Jan 19, 2022
fdd0022
Add comments about authentication and rate-limiting
MadLittleMods Jan 24, 2022
8238dfe
Return pagination token directly in future iteration
MadLittleMods Apr 9, 2022
75c157b
Abuse /timestamp_to_event to get create event
MadLittleMods Apr 9, 2022
cbd388f
Unrenderable events
MadLittleMods Apr 9, 2022
bb732d9
Add some complication thoughts around alternatives
MadLittleMods Apr 9, 2022
4d2a45a
Backfill event so we can get pagination token
MadLittleMods Apr 9, 2022
38b8147
Heuristic for which server to try first
MadLittleMods Sep 14, 2022
067bdeb
Give a suggestion on where to backfill from
MadLittleMods Sep 14, 2022
1804b71
Add alternative suggestion from @alphapapa
MadLittleMods Sep 14, 2022
8ca7a08
Better wording and fix typo
MadLittleMods Oct 11, 2022
ad99b64
No difference in homeservers
MadLittleMods Oct 11, 2022
bc2be78
Fix typos
MadLittleMods Oct 19, 2022
23cfab0
Fix extra word typo
MadLittleMods Oct 19, 2022
509c1b4
Summarizing discussion around why `dir` instead of closest
MadLittleMods Oct 19, 2022
b8d7ba3
Adjust to just suggest the right way
MadLittleMods Oct 20, 2022
fabfb34
Great simplification with the same meaning 🌟
MadLittleMods Oct 25, 2022
468a769
Perfect is the enemy of good
MadLittleMods Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
175 changes: 175 additions & 0 deletions proposals/3030-jump-to-date.md
@@ -0,0 +1,175 @@
# MSC3030: Jump to date API endpoint
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
turt2live marked this conversation as resolved.
Show resolved Hide resolved

Add an API that makes it easy to find the closest messages for a given
timestamp.

The goal of this change is to have clients be able to implement a jump to date
feature in order to see messages back at a given point in time. Pick a date from
a calender, heatmap, or paginate next/previous between days and view all of the
messages that were sent on that date.

For our [roadmap of feature parity with
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
Gitter](https://github.com/vector-im/roadmap/issues/26), we're also interested
in using this for a new better static Matrix archive. Our idea is to server-side
render [Hydrogen](https://github.com/vector-im/hydrogen-web) and this new
endpoint would allow us to jump back on the fly without having to paginate and
keep track of everything in order to display the selected date.

Also useful for archiving and backup use cases. This new endpoint can be used to
slice the messages by day and persist to file.

Related issue: [*URL for an arbitrary day of history and navigation for next and
previous days*
(vector-im/element-web#7677)](https://github.com/vector-im/element-web/issues/7677)


## Problem

These types of use cases are not supported by the current Matrix API because it
has no way to fetch or filter older messages besides a manual brute force
pagination from the latest. Paginating is time-consuming and expensive to
process every event as you go (not practical for clients). Imagine wanting to
get a message from 3 years ago 😫


## Proposal


Add new client API endpoint `GET
/_matrix/client/v1/rooms/{roomId}/timestamp_to_event?ts=<timestamp>?dir=[f|b]`
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
which fetches the closest `event_id` to the given timestamp `ts` query parameter
in the direction specified by the `dir` query parameter. The direction `dir`
query parameter accepts `f` for forward-in-time from the timestamp and `b` for
richvdh marked this conversation as resolved.
Show resolved Hide resolved
backward-in-time from the timestamp. This endpoint also returns
turt2live marked this conversation as resolved.
Show resolved Hide resolved
`origin_server_ts` to make it easy to do a quick comparison to see if the
`event_id` fetched is too far out of range to be useful for your use case.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

In order to solve the problem where a remote federated homeserver does not have
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
all of the history in a room and no suitably close event, we also add a server
API endpoint `GET
/_matrix/federation/v1/timestamp_to_event/{roomId}?ts=<timestamp>?dir=[f|b]`
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
which other homeservers can use to ask about their closest `event_id` to the
timestamp. This endpoint also returns `origin_server_ts` to make it easy to do a
quick comparison to see if the remote `event_id` fetched is closer than the
local one.

The heuristics for deciding when to ask another homeserver for a closer event if
your homeserver doesn't have something close, is left up to the homeserver
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
implementation. Although the heuristics will probably be based on whether the
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
closest event is a forward/backward extremity indicating it's next to a gap of
events which are potentially closer.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

```
GET /_matrix/client/v1/rooms/<roomID>/timestamp_to_event?ts=<timestamp>&dir=<direction>
{
"event_id": ...
"origin_server_ts": ...
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
```

Federation API endpoint:
```
GET /_matrix/federation/v1/timestamp_to_event/<roomID>?ts=<timestamp>&dir=<direction>
{
"event_id": ...
"origin_server_ts": ...
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
```

---

In order to paginate `/messages`, we need a pagination token which we can get
using `GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}?limi=0` for the
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
`event_id` returned by `/timestamp_to_event`.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved


## Potential issues
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

If you ask for "the message with `origin_server_ts` closest to Jan 1st 2018" you
might actually get a rogue random delayed one that was backfilled from a
federated server, but the human can figure that out by trying again with a
slight variation on the date or something.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved


## Alternatives


### Paginate `/messages` from timestamp
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

Add the `?around=<timestamp>` query parameter to the `GET
/_matrix/client/r0/rooms/{roomId}/messages` endpoint. This will start the
response at the message with `origin_server_ts` closest to the provided `around`
timestamp. The direction is determined by the existing `?dir` query parameter.

Use topoligical ordering, just as Element would use if you follow a permalink.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

### Filter by date in `RoomEventFilter`

Extend `RoomEventFilter` to be able to specify a timestamp or a date range. The
`RoomEventFilter` can be passed via the `?filter` query param on the `/messages`
endpoint.


### New `destination_server_ts` field

Add a new field and index on messages called `destination_server_ts` which
indicates when the message was received from federation. This gives a more
"real" time for how someone would actually consume those messages.

The contract of the API is "show me messages my server received at time T"
rather than the messy confusion of showing a delayed message which happened to
originally be sent at time T.

We've decided against this approach because the backfill from federated servers
could be horribly late.

---

Related issue around `/sync` vs `/messages`,
https://github.com/matrix-org/synapse/issues/7164

> Sync returns things in the order they arrive at the server; backfill returns
> them in the order determined by the event graph.
>
> *-- @richvdh, https://github.com/matrix-org/synapse/issues/7164#issuecomment-605877176*

> The general idea is that, if you're following a room in real-time (ie,
> `/sync`), you probably want to see the messages as they arrive at your server,
> rather than skipping any that arrived late; whereas if you're looking at a
> historical section of timeline (ie, `/messages`), you want to see the best
> representation of the state of the room as others were seeing it at the time.
>
> *-- @richvdh , https://github.com/matrix-org/synapse/issues/7164#issuecomment-605953296*


## Security considerations

We're only going to expose messages according to the existing message history
setting in the room (`m.room.history_visibility`). No extra data is exposed,
just a new way to sort through it all.



## Unstable prefix
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

While this MSC is not considered stable, the endpoints are available at `/unstable/org.matrix.msc3030` instead of their `/v1` description from above.

```
GET /_matrix/client/unstable/org.matrix.msc3030/rooms/<roomID>/timestamp_to_event?ts=<timestamp>&dir=<direction>
{
"event_id": ...
"origin_server_ts": ...
}
```

```
GET /_matrix/federation/unstable/org.matrix.msc3030/timestamp_to_event/<roomID>?ts=<timestamp>&dir=<direction>
{
"event_id": ...
"origin_server_ts": ...
}
```

Servers will indicate support for the new endpoint via a non-empty value for feature flag
`org.matrix.msc3030` in `unstable_features` in the response to `GET
/_matrix/client/versions`.