Skip to content

Commit 83aca3f

Browse files
SpiritCroctulir
andauthored
Implement MSC4169: backwards-compatible redaction sending for rooms < v11 using the /send endpoint (#18898)
Implement [MSC4169](matrix-org/matrix-spec-proposals#4169) While there is a dedicated API endpoint for redactions, being able to send redactions using the normal send endpoint is useful when using [MSC4140](matrix-org/matrix-spec-proposals#4140) for sending delayed redactions to replicate expiring messages. Currently this would only work on rooms >= v11 but fail with an internal server error on older room versions when setting the `redacts` field in the content, since older rooms would require that field to be outside of `content`. We can address this by copying it over if necessary. Relevant spec at https://spec.matrix.org/v1.8/rooms/v11/#moving-the-redacts-property-of-mroomredaction-events-to-a-content-property --------- Co-authored-by: Tulir Asokan <[email protected]>
1 parent d80f515 commit 83aca3f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

changelog.d/18898.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support [MSC4169](https://github.com/matrix-org/matrix-spec-proposals/pull/4169) for backwards-compatible redaction sending using the `/send` endpoint. Contributed by @SpiritCroc @ Beeper.

synapse/config/experimental.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ def read_config(
556556
# MSC4133: Custom profile fields
557557
self.msc4133_enabled: bool = experimental.get("msc4133_enabled", False)
558558

559+
# MSC4169: Backwards-compatible redaction sending using `/send`
560+
self.msc4169_enabled: bool = experimental.get("msc4169_enabled", False)
561+
559562
# MSC4210: Remove legacy mentions
560563
self.msc4210_enabled: bool = experimental.get("msc4210_enabled", False)
561564

synapse/handlers/message.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,14 +1013,37 @@ async def create_and_send_nonmember_event(
10131013
await self.clock.sleep(random.randint(1, 10))
10141014
raise ShadowBanError()
10151015

1016-
if ratelimit:
1016+
room_version = None
1017+
1018+
if (
1019+
event_dict["type"] == EventTypes.Redaction
1020+
and "redacts" in event_dict["content"]
1021+
and self.hs.config.experimental.msc4169_enabled
1022+
):
10171023
room_id = event_dict["room_id"]
10181024
try:
10191025
room_version = await self.store.get_room_version(room_id)
10201026
except NotFoundError:
1021-
# The room doesn't exist.
10221027
raise AuthError(403, f"User {requester.user} not in room {room_id}")
10231028

1029+
if not room_version.updated_redaction_rules:
1030+
# Legacy room versions need the "redacts" field outside of the event's
1031+
# content. However clients may still send it within the content, so move
1032+
# the field if necessary for compatibility.
1033+
redacts = event_dict.get("redacts") or event_dict["content"].pop(
1034+
"redacts", None
1035+
)
1036+
if redacts is not None and "redacts" not in event_dict:
1037+
event_dict["redacts"] = redacts
1038+
1039+
if ratelimit:
1040+
if room_version is None:
1041+
room_id = event_dict["room_id"]
1042+
try:
1043+
room_version = await self.store.get_room_version(room_id)
1044+
except NotFoundError:
1045+
raise AuthError(403, f"User {requester.user} not in room {room_id}")
1046+
10241047
if room_version.updated_redaction_rules:
10251048
redacts = event_dict["content"].get("redacts")
10261049
else:

synapse/rest/client/versions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
180180
"org.matrix.msc4155": self.config.experimental.msc4155_enabled,
181181
# MSC4306: Support for thread subscriptions
182182
"org.matrix.msc4306": self.config.experimental.msc4306_enabled,
183+
# MSC4169: Backwards-compatible redaction sending using `/send`
184+
"com.beeper.msc4169": self.config.experimental.msc4169_enabled,
183185
},
184186
},
185187
)

0 commit comments

Comments
 (0)