Skip to content

Commit 65e78cd

Browse files
Keep paginating /messages until no end token (#823)
Per the spec, keep paginating `/messages` until no `end` token. > Note that an empty `chunk` does not *necessarily* imply that no more events are available. Clients should continue to paginate until no `end` property is returned. > > *-- https://spec.matrix.org/v1.16/client-server-api/#get_matrixclientv3roomsroomidmessages*
1 parent 44111a2 commit 65e78cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/csapi/room_messages_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,13 @@ func _sendAndTestMessageHistory(
458458
firstEventIndex, lastEventIndex,
459459
)
460460

461+
// Keep paginating until we reach the start of the room (no `end` property is
462+
// returned).
463+
//
464+
// > Note that an empty `chunk` does not necessarily imply that no more events are
465+
// > available. Clients should continue to paginate until no `end` property is returned.
466+
// >
467+
// > https://spec.matrix.org/v1.16/client-server-api/#get_matrixclientv3roomsroomidmessages
461468
endTokenRes := gjson.GetBytes(messagesResBody, "end")
462469
// "`end`: If no further events are available (either because we have reached the
463470
// start of the timeline, or because the user does not have permission to see
@@ -466,12 +473,6 @@ func _sendAndTestMessageHistory(
466473
break
467474
}
468475
fromToken = endTokenRes.Str
469-
470-
// Or if we don't see any more events, we will assume that we reached the
471-
// start of the room. No more to paginate.
472-
if len(actualEventIDsFromRequest) == 0 {
473-
break
474-
}
475476
}
476477

477478
// Put them in chronological order to match the expected list

0 commit comments

Comments
 (0)