|
| 1 | +# MSC3567: Allow requesting events from the start/end of the room history |
| 2 | + |
| 3 | +It can be useful to request the latest events in a room directly without calling |
| 4 | +`/_matrix/client/v3/sync` first to fetch the room state. Some use-cases include: |
| 5 | + |
| 6 | +* Requesting events using a different filter after receiving a `/sync` response. |
| 7 | +* A client which does not need to fully sync an account, but wishes to inspect a |
| 8 | + specific room's history (perhaps for exporting or auditing). |
| 9 | + |
| 10 | + |
| 11 | +## Proposal |
| 12 | + |
| 13 | +The `from` field on the [`/_matrix/client/v3/rooms/{roomId}/messages`](https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3roomsroomidmessages) |
| 14 | +becomes optional. If it is not provided, the homeserver shall return a list of |
| 15 | +messages from the first or last (per the value of the `dir` parameter) visible |
| 16 | +event in the room history for the requesting user. |
| 17 | + |
| 18 | +Note that Synapse already implements this, but it is not spec-compliant. It is |
| 19 | +known to be used by Element Android [^1] and Element Web, and there are other |
| 20 | +use-cases involving threads [^2], which shows real-world usage that this would |
| 21 | +be valuable. |
| 22 | + |
| 23 | +Ideally this would not be necessary and the `prev_batch` token received from |
| 24 | +calling `/sync` could be provided as the pagination token to `/messages`, but this |
| 25 | +will not work if you `/sync` with a filter that excludes a given class of event |
| 26 | +(such as threaded replies), and all the events taking place in a room are of that |
| 27 | +class. This will result in your `/sync` not returning an update for that room, |
| 28 | +which means that your most recent `prev_batch` token precedes all the excluded |
| 29 | +events. Trying to back-paginate from `prev_batch` using `/messages` will not |
| 30 | +result in seeing the excluded events. |
| 31 | + |
| 32 | + |
| 33 | +## Potential issues |
| 34 | + |
| 35 | +None. |
| 36 | + |
| 37 | + |
| 38 | +## Alternatives |
| 39 | + |
| 40 | +The alternative is today's status quo: a client must first make a request to |
| 41 | +`/_matrix/client/v3/sync` and then follow-up that request with queries to |
| 42 | +`/_matrix/client/v3/rooms/{roomId}/messages`. This is clunky if the client is |
| 43 | +going to throw away most of the information received from the `/sync` request. |
| 44 | + |
| 45 | +The behavior also seems undefined if a different `filter` parameter is provided |
| 46 | +for the call to `/sync` compared to the one used for `/messages`. |
| 47 | + |
| 48 | + |
| 49 | +## Security considerations |
| 50 | + |
| 51 | +None. |
| 52 | + |
| 53 | + |
| 54 | +## Unstable prefix |
| 55 | + |
| 56 | +Since this is modifying the endpoint to support not including a field, no unstable |
| 57 | +prefix is necessary. |
| 58 | + |
| 59 | + |
| 60 | +## Dependencies |
| 61 | + |
| 62 | +N/A |
| 63 | + |
| 64 | +[^1]: https://github.com/matrix-org/synapse/issues/5538 |
| 65 | + |
| 66 | +[^2]: In order to list all threads in a room without pulling the history locally |
| 67 | +it uses `/messages` to push the filtering onto the homeserver. See https://github.com/matrix-org/matrix-js-sdk/pull/2065 |
0 commit comments