From d0b8ef1fe46efd7dd93cfd208effd345b6fa4a80 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 25 Feb 2022 12:49:48 +0000 Subject: [PATCH] Only remove `event` if it was in the result in the first place. --- synapse/handlers/federation.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 98d850cb69d6..0ad3b372f16e 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1008,14 +1008,17 @@ async def get_state_ids_for_pdu(self, room_id: str, event_id: str) -> List[str]: state_map = next(iter(state_groups.values())) - if event.is_state(): - # Get previous state + # we need the state *before* event. + state_key = event.get_state_key() + if ( + state_key is not None + and state_map.get((event.type, state_key)) == event.event_id + ): if "replaces_state" in event.unsigned: prev_id = event.unsigned["replaces_state"] - if prev_id != event.event_id: - state_map[(event.type, event.state_key)] = prev_id + state_map[(event.type, state_key)] = prev_id else: - state_map.pop((event.type, event.state_key), None) + del state_map[(event.type, state_key)] return list(state_map.values())