Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Closed
4 changes: 2 additions & 2 deletions docs/modules/third_party_rules_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ event with new data by returning the new event's data as a dictionary. In order
that, it is recommended the module calls `event.get_dict()` to get the current event as a
dictionary, and modify the returned dictionary accordingly.

Module writers may also wish to use this check to send an event into the room concurrent
Module writers may also wish to use this check to send a second event into the room along
with the event being checked, if this is the case the module writer must provide a dict that
will form the basis of the event that is to be added to the room and it must be returned by `check_event_allowed_v2`.
This dict will then be turned into an event at the appropriate time and it will be persisted after the event
that triggered it, and if the event that triggered it is in a batch of events for persisting, it will be added to the
end of that batch.
end of that batch. Note that the event MAY NOT be a membership event.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end of that batch. Note that the event MAY NOT be a membership event.
end of that batch. Note that the event MUST NOT be a membership event.

if we're going for RFC conventions (the capitals make me feel like it), MUST NOT is the term to use


If `check_event_allowed_v2` raises an exception, the module is assumed to have failed.
The event will not be accepted but is not treated as explicitly rejected, either.
Expand Down
4 changes: 4 additions & 0 deletions synapse/events/third_party_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(self, hs: "HomeServer"):
def register_third_party_rules_callbacks(
self,
check_event_allowed: Optional[CHECK_EVENT_ALLOWED_CALLBACK] = None,
check_event_allowed_v2: Optional[CHECK_EVENT_ALLOWED_V2_CALLBACK] = None,
on_create_room: Optional[ON_CREATE_ROOM_CALLBACK] = None,
check_threepid_can_be_invited: Optional[
CHECK_THREEPID_CAN_BE_INVITED_CALLBACK
Expand All @@ -217,6 +218,9 @@ def register_third_party_rules_callbacks(
if check_event_allowed is not None:
self._check_event_allowed_callbacks.append(check_event_allowed)

if check_event_allowed_v2 is not None:
self._check_event_allowed_v2_callbacks.append(check_event_allowed_v2)

if on_create_room is not None:
self._on_create_room_callbacks.append(on_create_room)

Expand Down
40 changes: 22 additions & 18 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,39 +1291,43 @@ async def create_event(
if encrypt_tp_event:
third_party_events_to_append.append(encrypt_tp_event)

for event_dict in third_party_events_to_append:
(
event,
unpersisted_context,
_,
) = await self.event_creation_handler.create_event(
creator,
event_dict,
prev_event_ids=prev_event,
state_map=state_map,
for_batch=True,
current_state_group=current_state_group,
)
context = await unpersisted_context.persist(event)
events_to_send.append((event, context))

if "name" in room_config:
name = room_config["name"]
name_event, name_context = await create_event(
name_event, name_context, name_tp_event = await create_event(
EventTypes.Name,
{"name": name},
True,
)
events_to_send.append((name_event, name_context))
if name_tp_event:
third_party_events_to_append.append(name_tp_event)

if "topic" in room_config:
topic = room_config["topic"]
topic_event, topic_context = await create_event(
topic_event, topic_context, topic_tp_event = await create_event(
EventTypes.Topic,
{"topic": topic},
True,
)
events_to_send.append((topic_event, topic_context))
if topic_tp_event:
third_party_events_to_append.append(topic_tp_event)

for event_dict in third_party_events_to_append:
(
event,
unpersisted_context,
_,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so (if I can read correctly) we don't let the callbacks on third-party events themselves generate more events? This could be worth putting in a comment and in the docs for the callback?

) = await self.event_creation_handler.create_event(
creator,
event_dict,
prev_event_ids=prev_event,
state_map=state_map,
for_batch=True,
current_state_group=current_state_group,
)
context = await unpersisted_context.persist(event)
events_to_send.append((event, context))

datastore = self.hs.get_datastores().state
events_and_context = (
Expand Down