From a383907fef394e7ab18f3c8e0624b7d50b59d482 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 8 Dec 2022 12:19:26 +0000 Subject: [PATCH] Revert "Don't return `end` from `/messages` if there are no more events (#12903)" This reverts commit c4f548e05d9a1858787d3a0883a5393d315473d8. This is because Tchap clients currently rely on this bug for message pagination. --- synapse/handlers/pagination.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py index c572508a0264..a88f146a117f 100644 --- a/synapse/handlers/pagination.py +++ b/synapse/handlers/pagination.py @@ -526,29 +526,18 @@ async def get_messages( next_token = from_token.copy_and_replace(StreamKeyType.ROOM, next_key) - # 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), - } + if events: + if event_filter: + events = await event_filter.filter(events) - if event_filter: - events = await event_filter.filter(events) - - if not use_admin_priviledge: - events = await filter_events_for_client( - self._storage_controllers, - user_id, - events, - is_peeking=(member_event_id is None), - ) + if not use_admin_priviledge: + events = await filter_events_for_client( + self._storage_controllers, + 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": [],