diff options
author | Patrick Cloke <patrickc@matrix.org> | 2023-07-26 12:45:17 -0400 |
---|---|---|
committer | Patrick Cloke <patrickc@matrix.org> | 2023-07-26 12:45:17 -0400 |
commit | 02867aeb257c666f23574864b18cf50c4ce99002 (patch) | |
tree | 358aef29f3ec3730457f73fc32a15acf418d1e1e /synapse/events | |
parent | FIx-up content hash checking for PDUs vs. delegated PDUs. (diff) | |
parent | Merge branch 'release-v1.89' into develop (diff) | |
download | synapse-02867aeb257c666f23574864b18cf50c4ce99002.tar.xz |
Merge remote-tracking branch 'origin/develop' into clokep/lm
Diffstat (limited to 'synapse/events')
-rw-r--r-- | synapse/events/__init__.py | 2 | ||||
-rw-r--r-- | synapse/events/builder.py | 2 | ||||
-rw-r--r-- | synapse/events/utils.py | 39 |
3 files changed, 25 insertions, 18 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index f95ec7dad7..eaf6fcf2f9 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -353,7 +353,7 @@ class EventBase(metaclass=abc.ABCMeta): @property def redacts(self) -> Optional[str]: """MSC2176 moved the redacts field into the content.""" - if self.room_version.msc2176_redaction_rules: + if self.room_version.updated_redaction_rules: return self.content.get("redacts") return self.get("redacts") diff --git a/synapse/events/builder.py b/synapse/events/builder.py index 9efaff77c9..e4ed46c756 100644 --- a/synapse/events/builder.py +++ b/synapse/events/builder.py @@ -183,7 +183,7 @@ class EventBuilder: # MSC2174 moves the redacts property to the content, it is invalid to # provide it as a top-level property. - if self._redacts is not None and not self.room_version.msc2176_redaction_rules: + if self._redacts is not None and not self.room_version.updated_redaction_rules: event_dict["redacts"] = self._redacts if self._origin_server_ts is not None: diff --git a/synapse/events/utils.py b/synapse/events/utils.py index c692b4008d..f834d5dad8 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -108,19 +108,16 @@ def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDic "origin_server_ts", ] - # Room versions from before MSC2176 had additional allowed keys. - if not room_version.msc2176_redaction_rules: - allowed_keys.extend(["prev_state", "membership"]) + # Earlier room versions from had additional allowed keys. + if not room_version.updated_redaction_rules: + allowed_keys.extend(["prev_state", "membership", "origin"]) + # The hub server should not be redacted for linear matrix. if room_version.linearized_matrix: allowed_keys.append("hub_server") else: allowed_keys.append("depth") - # Room versions before MSC3989 kept the origin field. - if not room_version.msc3989_redaction_rules: - allowed_keys.append("origin") - event_type = event_dict["type"] new_content = {} @@ -132,9 +129,9 @@ def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDic if event_type == EventTypes.Member: add_fields("membership") - if room_version.msc3375_redaction_rules: + if room_version.restricted_join_rule_fix: add_fields(EventContentFields.AUTHORISING_USER) - if room_version.msc3821_redaction_rules: + if room_version.updated_redaction_rules: # Preserve the signed field under third_party_invite. third_party_invite = event_dict["content"].get("third_party_invite") if isinstance(third_party_invite, collections.abc.Mapping): @@ -145,15 +142,16 @@ def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDic ] elif event_type == EventTypes.Create: - # MSC2176 rules state that create events cannot have their `content` redacted. - if room_version.msc2176_redaction_rules: + if room_version.updated_redaction_rules: + # MSC2176 rules state that create events cannot have their `content` redacted. new_content = event_dict["content"] - - if not room_version.msc2175_implicit_room_creator: + elif not room_version.implicit_room_creator: + # Some room versions give meaning to `creator` add_fields("creator") + elif event_type == EventTypes.JoinRules: add_fields("join_rule") - if room_version.msc3083_join_rules: + if room_version.restricted_join_rule: add_fields("allow") elif event_type == EventTypes.PowerLevels: add_fields( @@ -167,14 +165,14 @@ def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDic "redact", ) - if room_version.msc2176_redaction_rules: + if room_version.updated_redaction_rules: add_fields("invite") elif event_type == EventTypes.Aliases and room_version.special_case_aliases_auth: add_fields("aliases") elif event_type == EventTypes.RoomHistoryVisibility: add_fields("history_visibility") - elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules: + elif event_type == EventTypes.Redaction and room_version.updated_redaction_rules: add_fields("redacts") # Protect the rel_type and event_id fields under the m.relates_to field. @@ -483,6 +481,15 @@ def serialize_event( if config.as_client_event: d = config.event_format(d) + # If the event is a redaction, copy the redacts field from the content to + # top-level for backwards compatibility. + if ( + e.type == EventTypes.Redaction + and e.room_version.updated_redaction_rules + and e.redacts is not None + ): + d["redacts"] = e.redacts + only_event_fields = config.only_event_fields if only_event_fields: if not isinstance(only_event_fields, list) or not all( |