Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7afb615

Browse files
When redacting, keep event fields around that maintain the historical event structure intact (MSC2716) (#10538)
* Keep event fields that maintain the historical event structure intact Fix #10521 * Add changelog * Bump room version * Better changelog text * Fix up room version after develop merge
1 parent 6b61deb commit 7afb615

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

changelog.d/10538.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for new redaction rules for historical events specified in [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716).

synapse/api/room_versions.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class RoomVersion:
7676
# MSC2716: Adds m.room.power_levels -> content.historical field to control
7777
# whether "insertion", "chunk", "marker" events can be sent
7878
msc2716_historical = attr.ib(type=bool)
79+
# MSC2716: Adds support for redacting "insertion", "chunk", and "marker" events
80+
msc2716_redactions = attr.ib(type=bool)
7981

8082

8183
class RoomVersions:
@@ -92,6 +94,7 @@ class RoomVersions:
9294
msc3083_join_rules=False,
9395
msc2403_knocking=False,
9496
msc2716_historical=False,
97+
msc2716_redactions=False,
9598
)
9699
V2 = RoomVersion(
97100
"2",
@@ -106,6 +109,7 @@ class RoomVersions:
106109
msc3083_join_rules=False,
107110
msc2403_knocking=False,
108111
msc2716_historical=False,
112+
msc2716_redactions=False,
109113
)
110114
V3 = RoomVersion(
111115
"3",
@@ -120,6 +124,7 @@ class RoomVersions:
120124
msc3083_join_rules=False,
121125
msc2403_knocking=False,
122126
msc2716_historical=False,
127+
msc2716_redactions=False,
123128
)
124129
V4 = RoomVersion(
125130
"4",
@@ -134,6 +139,7 @@ class RoomVersions:
134139
msc3083_join_rules=False,
135140
msc2403_knocking=False,
136141
msc2716_historical=False,
142+
msc2716_redactions=False,
137143
)
138144
V5 = RoomVersion(
139145
"5",
@@ -148,6 +154,7 @@ class RoomVersions:
148154
msc3083_join_rules=False,
149155
msc2403_knocking=False,
150156
msc2716_historical=False,
157+
msc2716_redactions=False,
151158
)
152159
V6 = RoomVersion(
153160
"6",
@@ -162,6 +169,7 @@ class RoomVersions:
162169
msc3083_join_rules=False,
163170
msc2403_knocking=False,
164171
msc2716_historical=False,
172+
msc2716_redactions=False,
165173
)
166174
MSC2176 = RoomVersion(
167175
"org.matrix.msc2176",
@@ -176,6 +184,7 @@ class RoomVersions:
176184
msc3083_join_rules=False,
177185
msc2403_knocking=False,
178186
msc2716_historical=False,
187+
msc2716_redactions=False,
179188
)
180189
V7 = RoomVersion(
181190
"7",
@@ -190,6 +199,22 @@ class RoomVersions:
190199
msc3083_join_rules=False,
191200
msc2403_knocking=True,
192201
msc2716_historical=False,
202+
msc2716_redactions=False,
203+
)
204+
V8 = RoomVersion(
205+
"8",
206+
RoomDisposition.STABLE,
207+
EventFormatVersions.V3,
208+
StateResolutionVersions.V2,
209+
enforce_key_validity=True,
210+
special_case_aliases_auth=False,
211+
strict_canonicaljson=True,
212+
limit_notifications_power_levels=True,
213+
msc2176_redaction_rules=False,
214+
msc3083_join_rules=True,
215+
msc2403_knocking=True,
216+
msc2716_historical=False,
217+
msc2716_redactions=False,
193218
)
194219
MSC2716 = RoomVersion(
195220
"org.matrix.msc2716",
@@ -204,20 +229,22 @@ class RoomVersions:
204229
msc3083_join_rules=False,
205230
msc2403_knocking=True,
206231
msc2716_historical=True,
232+
msc2716_redactions=False,
207233
)
208-
V8 = RoomVersion(
209-
"8",
210-
RoomDisposition.STABLE,
234+
MSC2716v2 = RoomVersion(
235+
"org.matrix.msc2716v2",
236+
RoomDisposition.UNSTABLE,
211237
EventFormatVersions.V3,
212238
StateResolutionVersions.V2,
213239
enforce_key_validity=True,
214240
special_case_aliases_auth=False,
215241
strict_canonicaljson=True,
216242
limit_notifications_power_levels=True,
217243
msc2176_redaction_rules=False,
218-
msc3083_join_rules=True,
244+
msc3083_join_rules=False,
219245
msc2403_knocking=True,
220-
msc2716_historical=False,
246+
msc2716_historical=True,
247+
msc2716_redactions=True,
221248
)
222249

223250

synapse/events/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from frozendict import frozendict
1919

20-
from synapse.api.constants import EventTypes, RelationTypes
20+
from synapse.api.constants import EventContentFields, EventTypes, RelationTypes
2121
from synapse.api.errors import Codes, SynapseError
2222
from synapse.api.room_versions import RoomVersion
2323
from synapse.util.async_helpers import yieldable_gather_results
@@ -135,6 +135,12 @@ def add_fields(*fields):
135135
add_fields("history_visibility")
136136
elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules:
137137
add_fields("redacts")
138+
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_INSERTION:
139+
add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID)
140+
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_CHUNK:
141+
add_fields(EventContentFields.MSC2716_CHUNK_ID)
142+
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER:
143+
add_fields(EventContentFields.MSC2716_MARKER_INSERTION)
138144

139145
allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys}
140146

0 commit comments

Comments
 (0)