Skip to content

Commit 322fd41

Browse files
SpiritCroctulir
andauthored
Implement MSC4169: backwards-compatible send of redactions in pre-v11 rooms using the /send endpoint (#52)
Co-authored-by: Tulir Asokan <[email protected]>
1 parent 557272b commit 322fd41

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-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
@@ -552,6 +552,9 @@ def read_config(
552552
# MSC4133: Custom profile fields
553553
self.msc4133_enabled: bool = experimental.get("msc4133_enabled", False)
554554

555+
# MSC4169: Backwards-compatible redaction sending using `/send`
556+
self.msc4169_enabled: bool = experimental.get("msc4169_enabled", False)
557+
555558
# MSC4210: Remove legacy mentions
556559
self.msc4210_enabled: bool = experimental.get("msc4210_enabled", False)
557560

synapse/handlers/message.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,14 +1003,38 @@ async def create_and_send_nonmember_event(
10031003
await self.clock.sleep(random.randint(1, 10))
10041004
raise ShadowBanError()
10051005

1006-
if ratelimit:
1006+
room_version = None
1007+
1008+
if (
1009+
event_dict["type"] == EventTypes.Redaction
1010+
and "redacts" in event_dict["content"]
1011+
and self.hs.config.experimental.msc4169_enabled
1012+
):
1013+
10071014
room_id = event_dict["room_id"]
10081015
try:
10091016
room_version = await self.store.get_room_version(room_id)
10101017
except NotFoundError:
1011-
# The room doesn't exist.
10121018
raise AuthError(403, f"User {requester.user} not in room {room_id}")
10131019

1020+
if not room_version.updated_redaction_rules:
1021+
# Legacy room versions need the "redacts" field outside of the event's
1022+
# content. However clients may still send it within the content, so copy
1023+
# the field if necessary for compatibility.
1024+
redacts = event_dict.get("redacts") or event_dict["content"].pop(
1025+
"redacts", None
1026+
)
1027+
if redacts is not None and "redacts" not in event_dict:
1028+
event_dict["redacts"] = redacts
1029+
1030+
if ratelimit:
1031+
if room_version is None:
1032+
room_id = event_dict["room_id"]
1033+
try:
1034+
room_version = await self.store.get_room_version(room_id)
1035+
except NotFoundError:
1036+
raise AuthError(403, f"User {requester.user} not in room {room_id}")
1037+
10141038
if room_version.updated_redaction_rules:
10151039
redacts = event_dict["content"].get("redacts")
10161040
else:

synapse/rest/client/versions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
177177
"uk.tcpip.msc4133": self.config.experimental.msc4133_enabled,
178178
# MSC4155: Invite filtering
179179
"org.matrix.msc4155": self.config.experimental.msc4155_enabled,
180+
# MSC4169: Backwards-compatible redaction sending using `/send`
181+
"com.beeper.msc4169": self.config.experimental.msc4169_enabled,
180182
},
181183
},
182184
)

0 commit comments

Comments
 (0)