Skip to content

Commit 48e0783

Browse files
authored
Clarifications to pagination parameters for various APIs (#3353)
1 parent dd0cc92 commit 48e0783

File tree

7 files changed

+67
-32
lines changed

7 files changed

+67
-32
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify the documentation around the pagination tokens used by `/sync`, `/rooms/{room_id}/messages`, `/initialSync`, `/rooms/{room_id}/initialSync`, and `/notifications`.

data/api/client-server/definitions/timeline_batch.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ properties:
2121
type: boolean
2222
prev_batch:
2323
description: A token that can be supplied to the `from` parameter of the
24-
rooms/{roomId}/messages endpoint.
24+
[`/rooms/<room_id>/messages`](#get_matrixclientr0roomsroomidmessages)
25+
endpoint in order to retrieve earlier events.
26+
27+
If no earlier events are available, this property may be omitted from
28+
the response.
2529
type: string
2630
type: object
2731
title: TimelineBatch

data/api/client-server/message_pagination.yaml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,31 @@ paths:
5151
name: from
5252
description: |-
5353
The token to start returning events from. This token can be obtained
54-
from a `prev_batch` token returned for each room by the sync API,
55-
or from a `start` or `end` token returned by a previous request
56-
to this endpoint.
54+
from a `prev_batch` or `next_batch` token returned by the `/sync` endpoint,
55+
or from an `end` token returned by a previous request to this endpoint.
56+
57+
This endpoint can also accept a value returned as a `start` token
58+
by a previous request to this endpoint, though servers are not
59+
required to support this. Clients should not rely on the behaviour.
5760
required: true
5861
x-example: "s345_678_333"
5962
- in: query
6063
type: string
6164
name: to
6265
description: |-
6366
The token to stop returning events at. This token can be obtained from
64-
a `prev_batch` token returned for each room by the sync endpoint,
65-
or from a `start` or `end` token returned by a previous request to
66-
this endpoint.
67+
a `prev_batch` or `next_batch` token returned by the `/sync` endpoint,
68+
or from an `end` token returned by a previous request to this endpoint.
6769
required: false
6870
- in: query
6971
type: string
7072
enum: ["b", "f"]
7173
name: dir
7274
description: |-
73-
The direction to return events from.
75+
The direction to return events from. If this is set to `f`, events
76+
will be returned in chronological order starting at `from`. If it
77+
is set to `b`, events will be returned in *reverse* chronolgical
78+
order, again starting at `from`.
7479
required: true
7580
x-example: "b"
7681
- in: query
@@ -96,20 +101,29 @@ paths:
96101
start:
97102
type: string
98103
description: |-
99-
The token the pagination starts from. If `dir=b` this will be
100-
the token supplied in `from`.
104+
A token corresponding to the start of `chunk`. This will be the same as
105+
the value given in `from`.
101106
end:
102107
type: string
103108
description: |-
104-
The token the pagination ends at. If `dir=b` this token should
105-
be used again to request even earlier events.
109+
A token corresponding to the end of `chunk`. This token can be passed
110+
back to this endpoint to request further events.
111+
112+
If no further events are available (either because we have
113+
reached the start of the timeline, or because the user does
114+
not have permission to see any more events), this property
115+
is omitted from the response.
106116
chunk:
107117
type: array
108118
description: |-
109119
A list of room events. The order depends on the `dir` parameter.
110120
For `dir=b` events will be in reverse-chronological order,
111-
for `dir=f` in chronological order, so that events start
112-
at the `from` point.
121+
for `dir=f` in chronological order. (The exact definition of `chronological`
122+
is dependent on the server implementation.)
123+
124+
Note that an empty `chunk` does not *necessarily* imply that no more events
125+
are available. Clients should continue to paginate until no `end` property
126+
is returned.
113127
items:
114128
"$ref": "../../event-schemas/schema/core-event-schema/room_event.yaml"
115129
state:
@@ -125,6 +139,7 @@ paths:
125139
the membership of those members has not changed.
126140
items:
127141
$ref: "../../event-schemas/schema/core-event-schema/state_event.yaml"
142+
required: [start, chunk]
128143
examples:
129144
application/json: {
130145
"start": "t47429-4392820_219380_26003_2265",

data/api/client-server/notifications.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ paths:
4141
- in: query
4242
type: string
4343
name: from
44-
description: Pagination token given to retrieve the next set of events.
44+
description: |-
45+
Pagination token to continue from. This should be the `next_token`
46+
returned from an earlier call to this endpoint.
4547
required: false
4648
x-example: "xxxxx"
4749
- in: query

data/api/client-server/old_sync.yaml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ paths:
3636
3737
This endpoint was deprecated in r0 of this specification. Clients
3838
should instead call the [`/sync`](/client-server-api/#get_matrixclientr0sync)
39-
API with a `since` parameter. See
39+
endpoint with a `since` parameter. See
4040
the [migration guide](https://matrix.org/docs/guides/migrating-from-client-server-api-v-1#deprecated-endpoints).
4141
operationId: getEvents
4242
security:
@@ -73,12 +73,12 @@ paths:
7373
start:
7474
type: string
7575
description: |-
76-
A token which correlates to the first value in `chunk`. This
76+
A token which correlates to the start of `chunk`. This
7777
is usually the same token supplied to `from=`.
7878
end:
7979
type: string
8080
description: |-
81-
A token which correlates to the last value in `chunk`. This
81+
A token which correlates to the end of `chunk`. This
8282
token should be used in the next request to `/events`.
8383
chunk:
8484
type: array
@@ -102,7 +102,7 @@ paths:
102102
103103
This endpoint was deprecated in r0 of this specification. Clients
104104
should instead call the [`/sync`](/client-server-api/#get_matrixclientr0sync)
105-
API with no `since` parameter. See
105+
endpoint with no `since` parameter. See
106106
the [migration guide](https://matrix.org/docs/guides/migrating-from-client-server-api-v-1#deprecated-endpoints).
107107
operationId: initialSync
108108
security:
@@ -199,8 +199,8 @@ paths:
199199
end:
200200
type: string
201201
description: |-
202-
A token which correlates to the last value in `chunk`. This
203-
token should be used with the `/events` API to listen for new
202+
A token which correlates to the end of the timelines returned. This
203+
token should be used with the `/events` endpoint to listen for new
204204
events.
205205
presence:
206206
type: array
@@ -237,13 +237,20 @@ paths:
237237
start:
238238
type: string
239239
description: |-
240-
A token which correlates to the first value in `chunk`.
241-
Used for pagination.
240+
A token which correlates to the start of `chunk`.
241+
Can be passed to
242+
[`/rooms/<room_id>/messages`](#get_matrixclientr0roomsroomidmessages)
243+
to retrieve earlier events.
244+
245+
If no earlier events are available, this property may be omitted from
246+
the response.
242247
end:
243248
type: string
244249
description: |-
245-
A token which correlates to the last value in `chunk`.
246-
Used for pagination.
250+
A token which correlates to the end of `chunk`.
251+
Can be passed to
252+
[`/rooms/<room_id>/messages`](#get_matrixclientr0roomsroomidmessages)
253+
to retrieve later events.
247254
chunk:
248255
type: array
249256
description: |-
@@ -257,7 +264,7 @@ paths:
257264
title: RoomEvent
258265
allOf:
259266
- "$ref": "../../event-schemas/schema/core-event-schema/room_event.yaml"
260-
required: ["start", "end", "chunk"]
267+
required: ["end", "chunk"]
261268
state:
262269
type: array
263270
description: |-

data/api/client-server/room_initial_sync.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ paths:
9898
start:
9999
type: string
100100
description: |-
101-
A token which correlates to the first value in `chunk`.
102-
Used for pagination.
101+
A token which correlates to the start of `chunk`. Can be passed to
102+
[`/rooms/<room_id>/messages`](#get_matrixclientr0roomsroomidmessages)
103+
to retrieve earlier events.
104+
105+
If no earlier events are available, this property may be omitted from
106+
the response.
103107
end:
104108
type: string
105109
description: |-
106-
A token which correlates to the last value in `chunk`.
107-
Used for pagination.
110+
A token which correlates to the end of `chunk`. Can be passed to
111+
[`/rooms/<room_id>/messages`](#get_matrixclientr0roomsroomidmessages)
112+
to retrieve later events.
108113
chunk:
109114
type: array
110115
description: |-
@@ -118,7 +123,7 @@ paths:
118123
title: RoomEvent
119124
allOf:
120125
- "$ref": "../../event-schemas/schema/core-event-schema/room_event.yaml"
121-
required: ["start", "end", "chunk"]
126+
required: ["end", "chunk"]
122127
state:
123128
type: array
124129
description: |-

data/api/client-server/sync.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ paths:
7373
name: since
7474
type: string
7575
description: |-
76-
A point in time to continue a sync from.
76+
A point in time to continue a sync from. This should be the
77+
`next_batch` token returned by an earlier call to this endpoint.
7778
x-example: "s72594_4483_1934"
7879
- in: query
7980
name: full_state

0 commit comments

Comments
 (0)