Skip to content

Commit 805c0b2

Browse files
committed
Initial MSC3856 draft.
1 parent 1ec0d58 commit 805c0b2

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

proposals/3856-threads-list-api.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# MSC3856: Threads List API
2+
3+
An endpoint specific to listing the threads in a room is proposed to solve two
4+
issues:
5+
6+
1. Clients wish to display threads by the most recently active.
7+
2. Clients wish to display a list of threads the user is interested in.
8+
9+
It is currently difficult for clients to sort threads by the most recently
10+
responded to. Clients use the `/messages` API with a filter of
11+
`"related_by_rel_types": ["m.thread"]` to fetch the list of threads in a room. This
12+
returns the root thread events in topological order of those events (either
13+
forwards or backwards depending on the `dir` parameter).
14+
15+
Each event also includes bundled aggregation, which will include the latest
16+
event in each thread.
17+
18+
In order to sort threads by the latest event in that thread clients must
19+
paginate through all of the threads in the room, inspect the latest event from
20+
the bundled aggregations and attempt to sort them. This can require many round
21+
trips to the server and is wasteful for both the client and server.
22+
23+
Additionally, even with all of the threads a client is not able to accurately
24+
sort the threads since they lack the proper topological ordering of events. (The
25+
closest they can get is by using `age` or `origin_server_ts`, but this is not
26+
correct.)
27+
28+
For the second problem, it is currently not possible for a client to query for
29+
threads that the user has participated in (as defined in
30+
[MSC3440](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3440-threading-via-relations.md#event-format)).
31+
A client could add the user's MXID to the filter, e.g. `"related_by_senders":["@alice:example.com"]`,
32+
but this misses threads where the user sent the root message and has not yet replied.
33+
34+
## Proposal
35+
36+
### Client-Server endpoint
37+
38+
A new endpoint is proposed to query for threads in a room. This endpoint requires
39+
authentication and is subject to rate-limiting. This endpoint includes
40+
[bundled aggregations](https://spec.matrix.org/v1.3/client-server-api/#aggregations)
41+
in the response.
42+
43+
The returned threads are ordered by the most recently updated thread.
44+
45+
#### Request format
46+
47+
```
48+
GET /_matrix/client/v1/rooms/{roomId}/threads
49+
```
50+
51+
Query Parameters:
52+
53+
* **`filter`**: `enum`
54+
55+
Whether to include all threads in the room or only threads which the user has
56+
participated in, meaning that the user has created the root event of the thread
57+
or have created an event with a `m.thread` relation targeting the root.
58+
59+
One of `[all participated]`. Defaults to `all`.
60+
61+
XXX Rename this to something besides `filter`.
62+
* **`from`**: `string`
63+
64+
The token to start returning events from. This token can be obtained from a
65+
`prev_batch` or `next_batch` token returned by the `/sync` endpoint, or from
66+
an `end` token returned by a previous request to this endpoint.
67+
68+
If it is not provided, the homeserver shall return a list of threads from the
69+
last visible event in the room history for the requesting user.
70+
* **`limit`**: Optional: a client-defined limit to the maximum
71+
number of rooms to return per page. Must an integer greater than zero.
72+
73+
Server implementations should impose a maximum value to avoid resource
74+
exhaustion.
75+
* **`to`**: `string`
76+
77+
The token to stop returning events at. This token can be obtained from a
78+
`prev_batch` or `next_batch` token returned by the `/sync` endpoint, or from
79+
an `end` token returned by a previous request to this endpoint.
80+
81+
#### Response format
82+
83+
* **`chunk`**: [`[ClientEvent]`](https://spec.matrix.org/v1.3/client-server-api/#room-event-format) **Required**
84+
85+
A list of room of events which are the root event of threads. Each event includes
86+
bundled aggregations. The order is chronological by the latest event in that thread.
87+
* **`end`**: `string`
88+
89+
A token corresponding to the end of `chunk`. This token can be passed back to
90+
this endpoint to request further events.
91+
92+
If no further events are available (either because we have reached the start
93+
of the timeline, or because the user does not have permission to see any more
94+
events), this property is omitted from the response.
95+
* **`start`**: `string` **Required**
96+
97+
A token corresponding to the start of `chunk`. This will be the same as the
98+
value given in `from`.
99+
100+
XXX Define how ignored users are handled, which has two cases:
101+
102+
1. If the ignored user sent the root thread event.
103+
2. If the ignored user sent the latest thread event.
104+
105+
#### Example request:
106+
107+
```
108+
GET /_matrix/client/v1/rooms/%21ol19s%3Ableecker.street/threads?
109+
limit=25&
110+
filter=participated
111+
```
112+
113+
#### Example response:
114+
115+
```json
116+
{
117+
"chunk": [ClientEvent],
118+
"end": "...",
119+
"start": "..."
120+
}
121+
```
122+
123+
### MSC3440 Filtering
124+
125+
This MSC deprecates the [event filters added in MSC3440](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3440-threading-via-relations.md#fetch-all-threads-in-a-room)
126+
(`related_by_rel_types` and `related_by_senders`) as the only known use-case is
127+
more efficiently solved by this MSC.
128+
129+
## Potential issues
130+
131+
None forseen.
132+
133+
## Alternatives
134+
135+
Additional parameters could be added to the `/messages` API to control the ordering
136+
of the returned results. This would likely not be compatible with all the other
137+
options available on that endpoint.
138+
139+
Keeping this a separate API also gives the possibility of additional threads-specific
140+
filtering in the future.
141+
142+
## Security considerations
143+
144+
As with other endpoints that accept a `limit`, homeservers should apply a hard
145+
server-side maximum.
146+
147+
## Unstable prefix
148+
149+
The client-server API will be: `/_matrix/client/unstable/org.matrix.msc3856/rooms/{roomId}/threads`
150+
151+
## Dependencies
152+
153+
N/A

0 commit comments

Comments
 (0)