kill off `send_nonmember_event`
This is now redundant, and we can just call `handle_new_client_event` directly.pull/8463/head
parent
fd0282201e
commit
e775b5bb5b
|
@ -635,47 +635,6 @@ class EventCreationHandler:
|
||||||
msg = self._block_events_without_consent_error % {"consent_uri": consent_uri}
|
msg = self._block_events_without_consent_error % {"consent_uri": consent_uri}
|
||||||
raise ConsentNotGivenError(msg=msg, consent_uri=consent_uri)
|
raise ConsentNotGivenError(msg=msg, consent_uri=consent_uri)
|
||||||
|
|
||||||
async def send_nonmember_event(
|
|
||||||
self,
|
|
||||||
requester: Requester,
|
|
||||||
event: EventBase,
|
|
||||||
context: EventContext,
|
|
||||||
ratelimit: bool = True,
|
|
||||||
ignore_shadow_ban: bool = False,
|
|
||||||
) -> int:
|
|
||||||
"""
|
|
||||||
Persists and notifies local clients and federation of an event.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
requester: The requester sending the event.
|
|
||||||
event: The event to send.
|
|
||||||
context: The context of the event.
|
|
||||||
ratelimit: Whether to rate limit this send.
|
|
||||||
ignore_shadow_ban: True if shadow-banned users should be allowed to
|
|
||||||
send this event.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
The stream_id of the persisted event.
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
if event.type == EventTypes.Member:
|
|
||||||
raise SynapseError(
|
|
||||||
500, "Tried to send member event through non-member codepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
ev = await self.handle_new_client_event(
|
|
||||||
requester=requester,
|
|
||||||
event=event,
|
|
||||||
context=context,
|
|
||||||
ratelimit=ratelimit,
|
|
||||||
ignore_shadow_ban=ignore_shadow_ban,
|
|
||||||
)
|
|
||||||
|
|
||||||
# we know it was persisted, so must have a stream ordering
|
|
||||||
assert ev.internal_metadata.stream_ordering
|
|
||||||
return ev.internal_metadata.stream_ordering
|
|
||||||
|
|
||||||
async def deduplicate_state_event(
|
async def deduplicate_state_event(
|
||||||
self, event: EventBase, context: EventContext
|
self, event: EventBase, context: EventContext
|
||||||
) -> Optional[EventBase]:
|
) -> Optional[EventBase]:
|
||||||
|
@ -716,7 +675,7 @@ class EventCreationHandler:
|
||||||
"""
|
"""
|
||||||
Creates an event, then sends it.
|
Creates an event, then sends it.
|
||||||
|
|
||||||
See self.create_event and self.send_nonmember_event.
|
See self.create_event and self.handle_new_client_event.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
requester: The requester sending the event.
|
requester: The requester sending the event.
|
||||||
|
@ -726,9 +685,19 @@ class EventCreationHandler:
|
||||||
ignore_shadow_ban: True if shadow-banned users should be allowed to
|
ignore_shadow_ban: True if shadow-banned users should be allowed to
|
||||||
send this event.
|
send this event.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The event, and its stream ordering (if state event deduplication happened,
|
||||||
|
the previous, duplicate event).
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ShadowBanError if the requester has been shadow-banned.
|
ShadowBanError if the requester has been shadow-banned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if event_dict["type"] == EventTypes.Member:
|
||||||
|
raise SynapseError(
|
||||||
|
500, "Tried to send member event through non-member codepath"
|
||||||
|
)
|
||||||
|
|
||||||
if not ignore_shadow_ban and requester.shadow_banned:
|
if not ignore_shadow_ban and requester.shadow_banned:
|
||||||
# We randomly sleep a bit just to annoy the requester.
|
# We randomly sleep a bit just to annoy the requester.
|
||||||
await self.clock.sleep(random.randint(1, 10))
|
await self.clock.sleep(random.randint(1, 10))
|
||||||
|
@ -754,14 +723,17 @@ class EventCreationHandler:
|
||||||
spam_error = "Spam is not permitted here"
|
spam_error = "Spam is not permitted here"
|
||||||
raise SynapseError(403, spam_error, Codes.FORBIDDEN)
|
raise SynapseError(403, spam_error, Codes.FORBIDDEN)
|
||||||
|
|
||||||
stream_id = await self.send_nonmember_event(
|
ev = await self.handle_new_client_event(
|
||||||
requester,
|
requester=requester,
|
||||||
event,
|
event=event,
|
||||||
context,
|
context=context,
|
||||||
ratelimit=ratelimit,
|
ratelimit=ratelimit,
|
||||||
ignore_shadow_ban=ignore_shadow_ban,
|
ignore_shadow_ban=ignore_shadow_ban,
|
||||||
)
|
)
|
||||||
return event, stream_id
|
|
||||||
|
# we know it was persisted, so must have a stream ordering
|
||||||
|
assert ev.internal_metadata.stream_ordering
|
||||||
|
return ev, ev.internal_metadata.stream_ordering
|
||||||
|
|
||||||
@measure_func("create_new_client_event")
|
@measure_func("create_new_client_event")
|
||||||
async def create_new_client_event(
|
async def create_new_client_event(
|
||||||
|
@ -1255,8 +1227,12 @@ class EventCreationHandler:
|
||||||
|
|
||||||
# Since this is a dummy-event it is OK if it is sent by a
|
# Since this is a dummy-event it is OK if it is sent by a
|
||||||
# shadow-banned user.
|
# shadow-banned user.
|
||||||
await self.send_nonmember_event(
|
await self.handle_new_client_event(
|
||||||
requester, event, context, ratelimit=False, ignore_shadow_ban=True,
|
requester=requester,
|
||||||
|
event=event,
|
||||||
|
context=context,
|
||||||
|
ratelimit=False,
|
||||||
|
ignore_shadow_ban=True,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except ConsentNotGivenError:
|
except ConsentNotGivenError:
|
||||||
|
|
|
@ -230,8 +230,8 @@ class RoomCreationHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
# now send the tombstone
|
# now send the tombstone
|
||||||
await self.event_creation_handler.send_nonmember_event(
|
await self.event_creation_handler.handle_new_client_event(
|
||||||
requester, tombstone_event, tombstone_context
|
requester=requester, event=tombstone_event, context=tombstone_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
old_room_state = await tombstone_context.get_current_state_ids()
|
old_room_state = await tombstone_context.get_current_state_ids()
|
||||||
|
|
|
@ -413,7 +413,7 @@ class RegistrationTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.get_success(
|
self.get_success(
|
||||||
event_creation_handler.send_nonmember_event(requester, event, context)
|
event_creation_handler.handle_new_client_event(requester, event, context)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register a second user, which won't be be in the room (or even have an invite)
|
# Register a second user, which won't be be in the room (or even have an invite)
|
||||||
|
|
|
@ -608,7 +608,9 @@ class HomeserverTestCase(TestCase):
|
||||||
if soft_failed:
|
if soft_failed:
|
||||||
event.internal_metadata.soft_failed = True
|
event.internal_metadata.soft_failed = True
|
||||||
|
|
||||||
self.get_success(event_creator.send_nonmember_event(requester, event, context))
|
self.get_success(
|
||||||
|
event_creator.handle_new_client_event(requester, event, context)
|
||||||
|
)
|
||||||
|
|
||||||
return event.event_id
|
return event.event_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue