diff options
author | H. Shay <hillerys@element.io> | 2023-03-06 12:48:59 -0800 |
---|---|---|
committer | H. Shay <hillerys@element.io> | 2023-03-06 12:48:59 -0800 |
commit | 7fc487421f19d8841c36481701655bc31bfcd79f (patch) | |
tree | e5c4e634fa957a561675156c868c561c36a71d66 /synapse/handlers/message.py | |
parent | add clearer return values (diff) | |
parent | Pass the requester during event serialization. (#15174) (diff) | |
download | synapse-7fc487421f19d8841c36481701655bc31bfcd79f.tar.xz |
Merge branch 'develop' into shay/rework_module
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r-- | synapse/handlers/message.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 77d92f1574..d283a938c0 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -16,6 +16,7 @@ # limitations under the License. import logging import random +from builtins import dict from http import HTTPStatus from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Tuple @@ -50,7 +51,7 @@ from synapse.event_auth import validate_event_for_room_version from synapse.events import EventBase, relation_from_event from synapse.events.builder import EventBuilder from synapse.events.snapshot import EventContext, UnpersistedEventContextBase -from synapse.events.utils import maybe_upsert_event_field +from synapse.events.utils import SerializeEventConfig, maybe_upsert_event_field from synapse.events.validator import EventValidator from synapse.handlers.directory import DirectoryHandler from synapse.logging import opentracing @@ -245,8 +246,11 @@ class MessageHandler: ) room_state = room_state_events[membership_event_id] - now = self.clock.time_msec() - events = self._event_serializer.serialize_events(room_state.values(), now) + events = self._event_serializer.serialize_events( + room_state.values(), + self.clock.time_msec(), + config=SerializeEventConfig(requester=requester), + ) return events async def _user_can_see_state_at_event( @@ -574,7 +578,7 @@ class EventCreationHandler: state_map: Optional[StateMap[str]] = None, for_batch: bool = False, current_state_group: Optional[int] = None, - ) -> Tuple[EventBase, EventContext, Optional[dict]]: + ) -> Tuple[EventBase, UnpersistedEventContextBase, Optional[dict]]: """ Given a dict from a client, create a new event. If bool for_batch is true, will create an event using the prev_event_ids, and will create an event context for @@ -723,8 +727,6 @@ class EventCreationHandler: current_state_group=current_state_group, ) - context = await unpersisted_context.persist(event) - # In an ideal world we wouldn't need the second part of this condition. However, # this behaviour isn't spec'd yet, meaning we should be able to deactivate this # behaviour. Another reason is that this code is also evaluated each time a new @@ -741,7 +743,7 @@ class EventCreationHandler: assert state_map is not None prev_event_id = state_map.get((EventTypes.Member, event.sender)) else: - prev_state_ids = await context.get_prev_state_ids( + prev_state_ids = await unpersisted_context.get_prev_state_ids( StateFilter.from_types([(EventTypes.Member, None)]) ) prev_event_id = prev_state_ids.get((EventTypes.Member, event.sender)) @@ -766,8 +768,7 @@ class EventCreationHandler: ) self.validator.validate_new(event, self.config) - - return event, context, new_event + return event, unpersisted_context, new_event async def _is_exempt_from_privacy_policy( self, builder: EventBuilder, requester: Requester @@ -1007,7 +1008,11 @@ class EventCreationHandler: max_retries = 5 for i in range(max_retries): try: - event, context, third_party_event_dict = await self.create_event( + ( + event, + unpersisted_context, + third_party_event_dict, + ) = await self.create_event( requester, event_dict, txn_id=txn_id, @@ -1018,6 +1023,7 @@ class EventCreationHandler: historical=historical, depth=depth, ) + context = await unpersisted_context.persist(event) assert self.hs.is_mine_id(event.sender), "User must be our own: %s" % ( event.sender, @@ -1209,7 +1215,6 @@ class EventCreationHandler: if for_batch: assert prev_event_ids is not None assert state_map is not None - assert current_state_group is not None auth_ids = self._event_auth_handler.compute_auth_events(builder, state_map) event = await builder.build( prev_event_ids=prev_event_ids, auth_event_ids=auth_ids, depth=depth @@ -2067,7 +2072,7 @@ class EventCreationHandler: max_retries = 5 for i in range(max_retries): try: - event, context, _ = await self.create_event( + event, unpersisted_context, _ = await self.create_event( requester, { "type": EventTypes.Dummy, @@ -2076,6 +2081,7 @@ class EventCreationHandler: "sender": user_id, }, ) + context = await unpersisted_context.persist(event) event.internal_metadata.proactively_send = False |