You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/4354-sticky-events.md
+44-16Lines changed: 44 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,7 @@ The new `/sync` section looks like:
118
118
"state": { ... },
119
119
"timeline": { ... },
120
120
"sticky": {
121
+
"prev_batch":"s11_22_33_44_55_66_77_88",
121
122
"events": [
122
123
{
123
124
"sender":"@bob:example.com",
@@ -166,6 +167,7 @@ Over Simplified Sliding Sync, Sticky Events have their own extension `sticky_eve
166
167
{
167
168
"rooms": {
168
169
"!726s6s6q:example.com": {
170
+
"prev_batch":"s11_22_33_44_55_66_77_88",
169
171
"events": [{
170
172
"sender":"@bob:example.com",
171
173
"type":"m.foo",
@@ -184,6 +186,45 @@ Sticky events are expected to be encrypted and so there is no [state filter](htt
184
186
equivalent provided for sticky events e.g to filter sticky events by event type.
185
187
As with normal events, sticky events sent by ignored users MUST NOT be delivered to clients.
186
188
189
+
#### Pagination
190
+
191
+
If there are too many sticky events to return down `/sync`, the server may choose not to deliver all sticky events and
192
+
instead provide a `prev_batch` token which can be passed to a new endpoint to retrieve sticky events in that room. If all
193
+
sticky events were delivered, the `prev_batch` token is omitted from the Sync / Sliding Sync response object.
194
+
195
+
This proposal recommends only sending a `prev_batch` token if there are more than 100 sticky events in a given room. This
196
+
minimises the chances that clients will need to paginate, improving responsiveness at the cost of higher initial bandwidth used.
197
+
198
+
The API shape follows the one proposed in [MSC4308: Thread Subscriptions extension to Sliding Sync](https://github.com/matrix-org/matrix-spec-proposals/blob/rei/msc_ssext_threadsubs/proposals/4308-sliding-sync-ext-thread-subscriptions.md#companion-endpoint-for-backpaginating-thread-subscription-changes):
199
+
200
+
```
201
+
GET /_matrix/client/v1/rooms/{roomId}/sticky_events
202
+
```
203
+
URL query parameters:
204
+
- dir (string, required): always `b` (backward), to mirror other pagination endpoints. The forward direction is not yet specified to be implemented.
205
+
- from (string, optional): a token used to continue backpaginating
206
+
The token is either acquired from a previous `/sticky_events` response, or the `prev_batch` in a Sliding Sync / Sync response.
207
+
The token is opaque and has no client-discernible meaning.
208
+
If this token is not provided, then backpagination starts from the 'end'.
209
+
- to (string, optional): a token used to limit the backpagination
210
+
The token, originally acquired from pos in a Sliding Sync response, would be the same one used as the pos request parameter in the Sliding Sync request that returned the prev_batch.
211
+
- limit (int, optional; default 100): a maximum number of sticky events to fetch in one response.
212
+
Must be greater than zero. Servers may impose a smaller limit than requested.
213
+
214
+
Response body:
215
+
```js
216
+
{
217
+
"sticky_events": [ ... ], // list of sticky events
218
+
// If there are still more sticky events to fetch,
219
+
// a new `from` token the client can use to walk further
220
+
// backwards. (The `to` token, if used, should be reused.)
221
+
"end":"OPAQUE_TOKEN"
222
+
}
223
+
```
224
+
225
+
NB: This endpoint may also be used to retrieve sticky events in a room without calling `/sync` at all (by omitting both `from` and `to`),
226
+
which may be useful for bots.
227
+
187
228
### Rate limits
188
229
189
230
As sticky events are sent to clients regardless of the timeline limit, care needs to be taken to ensure
@@ -274,22 +315,8 @@ following protections in place:
274
315
* All sticky events are subject to normal PDU checks, meaning that the sender must be authorised to send events into the room.
275
316
* Servers sending lots of sticky events may be asked to try again later as a form of rate-limiting.
276
317
Due to data expiring, subsequent requests will gradually have less data.
277
-
* Sticky events are returned down `/sync` in batches of 100 to ensure clients never get a single enormous `/sync` response. They
278
-
will still get all unexpired sticky events via batches.
279
-
280
-
We could add a layer of indirection to the `/sync` response where we only announce the number of sticky events, and
281
-
expect the client to fetch them when they are ready via a different endpoint. This has roughly the same bandwidth cost, but
282
-
the client chooses when to pull in this information, reducing the time-to-interactivity. This has a few problems:
283
-
- It assumes sticky events are not urgently required when opening the application. This may be true for something like live
284
-
location sharing but may not be true for VoIP calls.
285
-
- It's not clear that there is a strong need for the extra indirection, given the strong rate limits and expirations already in
286
-
place.
287
-
- Adding the indirection increases complexity and friction when using the API, and presupposes the standard `/sync` model.
288
-
For [MSC4186: Simplified Sliding Sync](https://github.com/matrix-org/matrix-spec-proposals/pull/4186), clients can already indirect
289
-
if they wish to by simply not enabling the extension until they are ready to receive the data. Therefore, any new `/get_sticky_events`
290
-
API would really only be useful for A) applications which do not sync, B) users of the existing `/sync` API. The use case for applications
291
-
which do not sync is weak, given the entire point of sticky events is to ensure rapid synchronisation of temporary data. This heavily
292
-
implies the use of some kind of syncing mechanism to receive timely updates, which polling a `/get_sticky_events` endpoint subverts.
318
+
* Sticky events are returned down `/sync` with a recommended limit of 100 per room to ensure clients never get a single enormous `/sync` response. They
319
+
will still get all unexpired sticky events via the pagination endpoint.
293
320
294
321
295
322
## Alternatives
@@ -351,6 +378,7 @@ In the common case, it provides protection against clock skew when clients have
351
378
- The sticky key in the `content` of the PDU is `msc4354_sticky_key`.
352
379
- To enable this in SSS, the extension name is `org.matrix.msc4354.sticky_events`.
353
380
- The `unsigned.sticky_duration_ttl_ms` field is `unsigned.msc4354_sticky_duration_ttl_ms`
381
+
- The endpoint `/_matrix/client/v1/rooms/{roomId}/sticky_events` is `/_matrix/client/unstable/org.matrix.msc4354/rooms/{roomId}/sticky_events`.
0 commit comments