summary refs log tree commit diff
path: root/synapse/handlers/message.py
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2022-11-18 16:37:36 -0600
committerEric Eastwood <erice@element.io>2022-11-18 16:37:36 -0600
commitd993cb0b1c9efeebe52f40b8bdb871d02718c6d0 (patch)
tree9d68187784d5db6bdc242387af5400b141ab995a /synapse/handlers/message.py
parentFix poetry.lock conflicts (diff)
parentFix /key/v2/server calls with URL-unsafe key IDs (#14490) (diff)
downloadsynapse-d993cb0b1c9efeebe52f40b8bdb871d02718c6d0.tar.xz
Merge branch 'develop' into madlittlemods/11850-migrate-to-opentelemetry
Conflicts:
	docs/usage/configuration/config_documentation.md
	poetry.lock
	synapse/handlers/message.py
	synapse/http/server.py
	synapse/logging/opentracing.py
	synapse/rest/client/keys.py
	synapse/rest/client/room.py
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r--synapse/handlers/message.py62
1 files changed, 42 insertions, 20 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index e8b0a758a4..f2a0101733 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -877,6 +877,36 @@ class EventCreationHandler:
                 return prev_event
         return None
 
+    async def get_event_from_transaction(
+        self,
+        requester: Requester,
+        txn_id: str,
+        room_id: str,
+    ) -> Optional[EventBase]:
+        """For the given transaction ID and room ID, check if there is a matching event.
+        If so, fetch it and return it.
+
+        Args:
+            requester: The requester making the request in the context of which we want
+                to fetch the event.
+            txn_id: The transaction ID.
+            room_id: The room ID.
+
+        Returns:
+            An event if one could be found, None otherwise.
+        """
+        if requester.access_token_id:
+            existing_event_id = await self.store.get_event_id_from_transaction_id(
+                room_id,
+                requester.user.to_string(),
+                requester.access_token_id,
+                txn_id,
+            )
+            if existing_event_id:
+                return await self.store.get_event(existing_event_id)
+
+        return None
+
     async def create_and_send_nonmember_event(
         self,
         requester: Requester,
@@ -956,18 +986,17 @@ class EventCreationHandler:
         # extremities to pile up, which in turn leads to state resolution
         # taking longer.
         async with self.limiter.queue(event_dict["room_id"]):
-            if txn_id and requester.access_token_id:
-                existing_event_id = await self.store.get_event_id_from_transaction_id(
-                    event_dict["room_id"],
-                    requester.user.to_string(),
-                    requester.access_token_id,
-                    txn_id,
+            if txn_id:
+                event = await self.get_event_from_transaction(
+                    requester, txn_id, event_dict["room_id"]
                 )
-                if existing_event_id:
-                    event = await self.store.get_event(existing_event_id)
+                if event:
                     # we know it was persisted, so must have a stream ordering
                     assert event.internal_metadata.stream_ordering
-                    return event, event.internal_metadata.stream_ordering
+                    return (
+                        event,
+                        event.internal_metadata.stream_ordering,
+                    )
 
             event, context = await self.create_event(
                 requester,
@@ -1433,17 +1462,10 @@ class EventCreationHandler:
             a room that has been un-partial stated.
         """
 
-        for event, context in events_and_context:
-            # Skip push notification actions for historical messages
-            # because we don't want to notify people about old history back in time.
-            # The historical messages also do not have the proper `context.current_state_ids`
-            # and `state_groups` because they have `prev_events` that aren't persisted yet
-            # (historical messages persisted in reverse-chronological order).
-            if not event.internal_metadata.is_historical():
-                with tracing.start_active_span("calculate_push_actions"):
-                    await self._bulk_push_rule_evaluator.action_for_event_by_user(
-                        event, context
-                    )
+        with tracing.start_active_span("calculate_push_actions"):
+            await self._bulk_push_rule_evaluator.action_for_events_by_user(
+                events_and_context
+            )
 
         try:
             # If we're a worker we need to hit out to the master.