|
| 1 | +# MSC3855: 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 | + |
| 35 | +## Proposal |
| 36 | + |
| 37 | +### Client-Server endpoint |
| 38 | + |
| 39 | +A new endpoint is proposed to query for threads in a room. This endpoint requires |
| 40 | +authentication and is subject to rate-limiting. This endpoint includes |
| 41 | +[bundled aggregations](https://spec.matrix.org/v1.3/client-server-api/#aggregations) |
| 42 | +in the response. |
| 43 | + |
| 44 | +The returned threads are ordered by the most recently updated thread. |
| 45 | + |
| 46 | +#### Request format |
| 47 | + |
| 48 | +``` |
| 49 | +GET /_matrix/client/v1/rooms/{roomId}/threads |
| 50 | +``` |
| 51 | + |
| 52 | +Query Parameters: |
| 53 | + |
| 54 | +* **`filter`**: `enum` |
| 55 | + |
| 56 | + Whether to include all threads in the room or only threads which the user has |
| 57 | + participated in, meaning that the user has created the root event of the thread |
| 58 | + or have created an event with a `m.thread` relation targeting the root. |
| 59 | + |
| 60 | + One of `[all participated]`. Defaults to `all`. |
| 61 | + |
| 62 | + XXX Rename this to something besides `filter`. |
| 63 | +* **`from`**: `string` |
| 64 | + |
| 65 | + The token to start returning events from. This token can be obtained from a |
| 66 | + `prev_batch` or `next_batch` token returned by the `/sync` endpoint, or from |
| 67 | + an `end` token returned by a previous request to this endpoint. |
| 68 | + |
| 69 | + If it is not provided, the homeserver shall return a list of threads from the |
| 70 | + last visible event in the room history for the requesting user. |
| 71 | +* **`limit`**: Optional: a client-defined limit to the maximum |
| 72 | + number of rooms to return per page. Must an integer greater than zero. |
| 73 | + |
| 74 | + Server implementations should impose a maximum value to avoid resource |
| 75 | + exhaustion. |
| 76 | +* **`to`**: `string` |
| 77 | + |
| 78 | + The token to stop returning events at. This token can be obtained from a |
| 79 | + `prev_batch` or `next_batch` token returned by the `/sync` endpoint, or from |
| 80 | + an `end` token returned by a previous request to this endpoint. |
| 81 | + |
| 82 | +#### Response format |
| 83 | + |
| 84 | +* **`chunk`**: [`[ClientEvent]`](https://spec.matrix.org/v1.3/client-server-api/#room-event-format) **Required** |
| 85 | + |
| 86 | + A list of room of events which are the root event of threads. Each event includes |
| 87 | + bundled aggregations. The order is chronological by the latest event in that thread. |
| 88 | +* **`end`**: `string` |
| 89 | + |
| 90 | + A token corresponding to the end of `chunk`. This token can be passed back to |
| 91 | + this endpoint to request further events. |
| 92 | + |
| 93 | + If no further events are available (either because we have reached the start |
| 94 | + of the timeline, or because the user does not have permission to see any more |
| 95 | + events), this property is omitted from the response. |
| 96 | +* **`start`**: `string` **Required** |
| 97 | + |
| 98 | + A token corresponding to the start of `chunk`. This will be the same as the |
| 99 | + value given in `from`. |
| 100 | + |
| 101 | +#### Example request: |
| 102 | + |
| 103 | +``` |
| 104 | +GET /_matrix/client/v1/rooms/%21ol19s%3Ableecker.street/threads? |
| 105 | + limit=25& |
| 106 | + filter=participated |
| 107 | +``` |
| 108 | + |
| 109 | +#### Example response: |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + "chunk": [ClientEvent], |
| 114 | + "end": "...", |
| 115 | + "start": "..." |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +### MSC3440 Filtering |
| 120 | + |
| 121 | +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) |
| 122 | +(`related_by_rel_types` and `related_by_senders`) as the only known use-case is |
| 123 | +more efficiently solved by this MSC. |
| 124 | + |
| 125 | +## Potential issues |
| 126 | + |
| 127 | +None forseen. |
| 128 | + |
| 129 | +## Alternatives |
| 130 | + |
| 131 | +Additional parameters could be added to the `/messages` API to control the ordering |
| 132 | +of the returned results. This would likely not be compatible with all the other |
| 133 | +options available on that endpoint. |
| 134 | + |
| 135 | +Keeping this a separate API also gives the possibility of additional threads-specific |
| 136 | +filtering in the future. |
| 137 | + |
| 138 | +## Security considerations |
| 139 | + |
| 140 | +As with other endpoints that accept a `limit`, homeservers should apply a hard |
| 141 | +server-side maximum. |
| 142 | + |
| 143 | +## Unstable prefix |
| 144 | + |
| 145 | +The client-server API will be: `/_matrix/client/unstable/org.matrix.msc3855/rooms/{roomId}/threads` |
| 146 | + |
| 147 | +## Dependencies |
| 148 | + |
| 149 | +N/A |
0 commit comments