Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Don't return end from /messages if there are no more events #12903

Merged
merged 6 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12903.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug which caused the `/messages` endpoint to return an incorrect `end` attribute when there were no more events. Contributed by @Vetchu.
23 changes: 17 additions & 6 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,25 @@ async def get_messages(

next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key)

if events:
if event_filter:
events = await event_filter.filter(events)
# if no events are returned from pagination, that implies
# we have reached the end of the available events.
# In that case we do not return end, to tell the client
# there is no need for further queries.
if not events:
return {
"chunk": [],
"start": await from_token.to_string(self.store),
}

events = await filter_events_for_client(
self.storage, user_id, events, is_peeking=(member_event_id is None)
)
if event_filter:
events = await event_filter.filter(events)

events = await filter_events_for_client(
self.storage, user_id, events, is_peeking=(member_event_id is None)
)

# if after the filter applied there are no more events
# return immediately - but there might be more in next_token batch
if not events:
return {
"chunk": [],
Expand Down