summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2021-09-29 23:59:04 -0500
committerEric Eastwood <erice@element.io>2021-09-29 23:59:04 -0500
commit96d9d111ea584029ed3d7d5c1f40a725e81707e6 (patch)
tree900a7ff506a44d8a01cbc21215d1a04ec96f550c
parentForce /context to return state for the given historical event (diff)
downloadsynapse-96d9d111ea584029ed3d7d5c1f40a725e81707e6.tar.xz
Set full state for each historical event like others
-rw-r--r--synapse/handlers/message.py58
-rw-r--r--synapse/handlers/room.py8
2 files changed, 34 insertions, 32 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index f3dad1ab5c..9e6a0e0415 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -600,31 +600,6 @@ class EventCreationHandler:
 
         builder.internal_metadata.historical = historical
 
-        # Strip down the auth_event_ids to only what we need to auth the event.
-        # For example, we don't need extra m.room.member that don't match event.sender
-        if auth_event_ids is not None:
-            # If auth events are provided, prev events must be also.
-            assert prev_event_ids is not None
-
-            temp_event = await builder.build(
-                prev_event_ids=prev_event_ids,
-                auth_event_ids=auth_event_ids,
-                depth=depth,
-            )
-            #logger.info("auth_event_ids before=%s", auth_event_ids)
-            auth_events = await self.store.get_events_as_list(auth_event_ids)
-            # Create a StateMap[str]
-            auth_event_state_map = {
-                (e.type, e.state_key): e.event_id for e in auth_events
-            }
-            # Actually strip down and use the necessary auth events
-            auth_event_ids = self._event_auth_handler.compute_auth_events(
-                event=temp_event,
-                current_state_ids=auth_event_state_map,
-                for_verification=False,
-            )
-            #logger.info("auth_event_ids after=%s", auth_event_ids)
-
         event, context = await self.create_new_client_event(
             builder=builder,
             requester=requester,
@@ -931,6 +906,34 @@ class EventCreationHandler:
             Tuple of created event, context
         """
 
+        # Strip down the auth_event_ids to only what we need to auth the event.
+        # For example, we don't need extra m.room.member that don't match event.sender
+        if auth_event_ids is not None:
+            # If auth events are provided, prev events must be also.
+            assert prev_event_ids is not None
+
+            # Copy the full auth state before it stripped down
+            full_state_ids_at_event = auth_event_ids.copy()
+
+            temp_event = await builder.build(
+                prev_event_ids=prev_event_ids,
+                auth_event_ids=auth_event_ids,
+                depth=depth,
+            )
+            #logger.info("auth_event_ids before=%s", auth_event_ids)
+            auth_events = await self.store.get_events_as_list(auth_event_ids)
+            # Create a StateMap[str]
+            auth_event_state_map = {
+                (e.type, e.state_key): e.event_id for e in auth_events
+            }
+            # Actually strip down and use the necessary auth events
+            auth_event_ids = self._event_auth_handler.compute_auth_events(
+                event=temp_event,
+                current_state_ids=auth_event_state_map,
+                for_verification=False,
+            )
+            #logger.info("auth_event_ids after=%s", auth_event_ids)
+
         if prev_event_ids is not None:
             assert (
                 len(prev_event_ids) <= 10
@@ -940,6 +943,7 @@ class EventCreationHandler:
         else:
             prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
 
+
         # we now ought to have some prev_events (unless it's a create event).
         #
         # do a quick sanity check here, rather than waiting until we've created the
@@ -964,8 +968,8 @@ class EventCreationHandler:
             old_state = None
             # Define the state for historical messages while we know to get all of
             # state_groups setup properly when we `compute_event_context`.
-            if builder.internal_metadata.is_historical() and auth_event_ids:
-                old_state = await self.store.get_events_as_list(auth_event_ids)
+            if builder.internal_metadata.is_historical() and full_state_ids_at_event:
+                old_state = await self.store.get_events_as_list(full_state_ids_at_event)
 
             context = await self.state.compute_event_context(event, old_state=old_state)
 
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index ef556cd058..8b6c96c1b7 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -1162,19 +1162,17 @@ class RoomContextHandler:
         else:
             state_filter = StateFilter.all()
 
+        logger.info("get_event_context event_id=%s =====================", event_id)
         # XXX: why do we return the state as of the last event rather than the
         # first? Shouldn't we be consistent with /sync?
         # https://github.com/matrix-org/matrix-doc/issues/687
-
-        logger.info("get_event_context event_id=%s =====================", event_id)
-        
         event_id_to_get_state_from = last_event_id
 
         # For historical events, we want to get the state at the specified event.
         # TODO: maybe we can change how we're getting events_before and events_after
         # here so it still works correctly without this hack
-        if event.internal_metadata.is_historical():
-            event_id_to_get_state_from = event_id
+        # if event.internal_metadata.is_historical():
+        #     event_id_to_get_state_from = event_id
 
         state = await self.state_store.get_state_for_events(
             [event_id_to_get_state_from], state_filter=state_filter