summary refs log tree commit diff
path: root/synapse/events/utils.py
diff options
context:
space:
mode:
authorAndrew Morgan <1342360+anoadragon453@users.noreply.github.com>2021-02-09 19:07:00 +0000
committerGitHub <noreply@github.com>2021-02-09 19:07:00 +0000
commit6bf58d8194ff7c89a1c8249bade78492bbfa0900 (patch)
treedbaccc690b25f7273562569ba25b09c8a0a90b0b /synapse/events/utils.py
parentAdd complement running monolith synapse to buildkite pipeline (#80) (diff)
downloadsynapse-6bf58d8194ff7c89a1c8249bade78492bbfa0900.tar.xz
Add knocking support (#81)
Implement knocking as defined by https://github.com/matrix-org/matrix-doc/pull/2403

This is the base knocking stuff, taken from https://github.com/matrix-org/synapse/pull/6739
and does not include any public room directory changes.

While knocking hasn't merged yet on mainline due to waiting on getting Complement
into Synapse's CI, the code has been well-tested.
Diffstat (limited to 'synapse/events/utils.py')
-rw-r--r--synapse/events/utils.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py

index 14f7f1156f..72c8ad4fe5 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py
@@ -228,6 +228,7 @@ def format_event_for_client_v1(d): "replaces_state", "prev_content", "invite_room_state", + "knock_room_state", ) for key in copy_keys: if key in d["unsigned"]: @@ -264,7 +265,7 @@ def serialize_event( event_format=format_event_for_client_v1, token_id=None, only_event_fields=None, - is_invite=False, + include_stripped_room_state=False, ): """Serialize event for clients @@ -275,8 +276,10 @@ def serialize_event( event_format token_id only_event_fields - is_invite (bool): Whether this is an invite that is being sent to the - invitee + include_stripped_room_state (bool): Some events can have stripped room state + stored in the `unsigned` field. This is required for invite and knock + functionality. If this option is False, that state will be removed from the + event before it is returned. Otherwise, it will be kept. Returns: dict @@ -308,11 +311,13 @@ def serialize_event( if txn_id is not None: d["unsigned"]["transaction_id"] = txn_id - # If this is an invite for somebody else, then we don't care about the - # invite_room_state as that's meant solely for the invitee. Other clients - # will already have the state since they're in the room. - if not is_invite: + # invite_room_state and knock_room_state are a list of stripped room state events + # that are meant to provide metadata about a room to an invitee/knocker. They are + # intended to only be included in specific circumstances, such as down sync, and + # should not be included in any other case. + if not include_stripped_room_state: d["unsigned"].pop("invite_room_state", None) + d["unsigned"].pop("knock_room_state", None) if as_client_event: d = event_format(d)