From 1c4b31d734f756fab7d46582cc8946014547971d Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 4 Aug 2021 23:07:38 -0500 Subject: [PATCH 1/5] Keep event fields that maintain the historical event structure intact Fix https://github.com/matrix-org/synapse/issues/10521 --- synapse/events/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index a0c07f62f44b..a34da460bb10 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -17,7 +17,7 @@ from frozendict import frozendict -from synapse.api.constants import EventTypes, RelationTypes +from synapse.api.constants import EventContentFields, EventTypes, RelationTypes from synapse.api.errors import Codes, SynapseError from synapse.api.room_versions import RoomVersion from synapse.util.async_helpers import yieldable_gather_results @@ -135,6 +135,12 @@ def add_fields(*fields): add_fields("history_visibility") elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules: add_fields("redacts") + elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_INSERTION: + add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID) + elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_CHUNK: + add_fields(EventContentFields.MSC2716_CHUNK_ID) + elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_MARKER: + add_fields(EventContentFields.MSC2716_MARKER_INSERTION) allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys} From 61fefb30bc30802cc408d6e873f53a16372cca2e Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 4 Aug 2021 23:11:36 -0500 Subject: [PATCH 2/5] Add changelog --- changelog.d/10538.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10538.feature diff --git a/changelog.d/10538.feature b/changelog.d/10538.feature new file mode 100644 index 000000000000..05ec2d4c7550 --- /dev/null +++ b/changelog.d/10538.feature @@ -0,0 +1 @@ +When redacting, keep event fields around that maintain the MSC2716 historical event structure intact. From cdf9f1e3a53be78b1a4c85013c947e9af2172360 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 6 Aug 2021 23:36:26 -0500 Subject: [PATCH 3/5] Bump room version --- synapse/api/room_versions.py | 30 +++++++++++++++++++++++++++++- synapse/events/utils.py | 6 +++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/synapse/api/room_versions.py b/synapse/api/room_versions.py index bc678efe4973..a58f5b2b1586 100644 --- a/synapse/api/room_versions.py +++ b/synapse/api/room_versions.py @@ -76,6 +76,8 @@ class RoomVersion: # MSC2716: Adds m.room.power_levels -> content.historical field to control # whether "insertion", "chunk", "marker" events can be sent msc2716_historical = attr.ib(type=bool) + # MSC2716: Adds support for redacting "insertion", "chunk", and "marker" events + msc2716_redactions = attr.ib(type=bool) class RoomVersions: @@ -92,6 +94,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V2 = RoomVersion( "2", @@ -106,6 +109,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V3 = RoomVersion( "3", @@ -120,6 +124,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V4 = RoomVersion( "4", @@ -134,6 +139,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V5 = RoomVersion( "5", @@ -148,6 +154,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V6 = RoomVersion( "6", @@ -162,6 +169,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) MSC2176 = RoomVersion( "org.matrix.msc2176", @@ -176,6 +184,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) MSC3083 = RoomVersion( "org.matrix.msc3083.v2", @@ -190,6 +199,7 @@ class RoomVersions: msc3083_join_rules=True, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V7 = RoomVersion( "7", @@ -204,10 +214,26 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=True, msc2716_historical=False, + msc2716_redactions=False, ) MSC2716 = RoomVersion( "org.matrix.msc2716", - RoomDisposition.STABLE, + RoomDisposition.UNSTABLE, + EventFormatVersions.V3, + StateResolutionVersions.V2, + enforce_key_validity=True, + special_case_aliases_auth=False, + strict_canonicaljson=True, + limit_notifications_power_levels=True, + msc2176_redaction_rules=False, + msc3083_join_rules=False, + msc2403_knocking=True, + msc2716_historical=True, + msc2716_redactions=False, + ) + MSC2716v2 = RoomVersion( + "org.matrix.msc2716v2", + RoomDisposition.UNSTABLE, EventFormatVersions.V3, StateResolutionVersions.V2, enforce_key_validity=True, @@ -218,6 +244,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=True, msc2716_historical=True, + msc2716_redactions=True, ) @@ -234,6 +261,7 @@ class RoomVersions: RoomVersions.MSC3083, RoomVersions.V7, RoomVersions.MSC2716, + RoomVersions.MSC2716v2, ) } diff --git a/synapse/events/utils.py b/synapse/events/utils.py index a34da460bb10..b6da2f60af99 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -135,11 +135,11 @@ def add_fields(*fields): add_fields("history_visibility") elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules: add_fields("redacts") - elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_INSERTION: + elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_INSERTION: add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID) - elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_CHUNK: + elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_CHUNK: add_fields(EventContentFields.MSC2716_CHUNK_ID) - elif room_version.msc2716_historical and event_type == EventTypes.MSC2716_MARKER: + elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER: add_fields(EventContentFields.MSC2716_MARKER_INSERTION) allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys} From e127d0eb23c6d8a4cde0b608b92abc1e2817cf9c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 9 Aug 2021 18:00:20 -0500 Subject: [PATCH 4/5] Better changelog text --- changelog.d/10538.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/10538.feature b/changelog.d/10538.feature index 05ec2d4c7550..120c8e8ca028 100644 --- a/changelog.d/10538.feature +++ b/changelog.d/10538.feature @@ -1 +1 @@ -When redacting, keep event fields around that maintain the MSC2716 historical event structure intact. +Add support for new redaction rules for historical events specified in [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716). From 3ad52165ce8b268414e0db3b0e42a5b394c67f4f Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 9 Aug 2021 18:12:47 -0500 Subject: [PATCH 5/5] Fix up room version after develop merge --- synapse/api/room_versions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/synapse/api/room_versions.py b/synapse/api/room_versions.py index 884a220759ae..11280c446220 100644 --- a/synapse/api/room_versions.py +++ b/synapse/api/room_versions.py @@ -76,6 +76,8 @@ class RoomVersion: # MSC2716: Adds m.room.power_levels -> content.historical field to control # whether "insertion", "chunk", "marker" events can be sent msc2716_historical = attr.ib(type=bool) + # MSC2716: Adds support for redacting "insertion", "chunk", and "marker" events + msc2716_redactions = attr.ib(type=bool) class RoomVersions: @@ -92,6 +94,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V2 = RoomVersion( "2", @@ -106,6 +109,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V3 = RoomVersion( "3", @@ -120,6 +124,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V4 = RoomVersion( "4", @@ -134,6 +139,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V5 = RoomVersion( "5", @@ -148,6 +154,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V6 = RoomVersion( "6", @@ -162,6 +169,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) MSC2176 = RoomVersion( "org.matrix.msc2176", @@ -176,6 +184,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=False, msc2716_historical=False, + msc2716_redactions=False, ) V7 = RoomVersion( "7", @@ -190,6 +199,7 @@ class RoomVersions: msc3083_join_rules=False, msc2403_knocking=True, msc2716_historical=False, + msc2716_redactions=False, ) V8 = RoomVersion( "8", @@ -204,6 +214,7 @@ class RoomVersions: msc3083_join_rules=True, msc2403_knocking=True, msc2716_historical=False, + msc2716_redactions=False, ) MSC2716 = RoomVersion( "org.matrix.msc2716",