Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19782.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix [MSC3912](https://github.com/matrix-org/matrix-spec-proposals/pull/3912) (relation based redaction) for room versions greater than 10. Contributed by @famedly.
26 changes: 19 additions & 7 deletions synapse/handlers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from synapse.logging.opentracing import trace
from synapse.storage.databases.main.relations import ThreadsNextBatch, _RelatedEvent
from synapse.streams.config import PaginationConfig
from synapse.synapse_rust.room_versions import RoomVersion
from synapse.types import JsonDict, Requester, UserID
from synapse.util.async_helpers import gather_results
from synapse.visibility import filter_and_transform_events_for_client
Expand Down Expand Up @@ -211,6 +212,7 @@ async def redact_events_related_to(
event_id: str,
initial_redaction_event: EventBase,
relation_types: list[str],
room_version: RoomVersion,
) -> None:
"""Redacts all events related to the given event ID with one of the given
relation types.
Expand All @@ -228,6 +230,8 @@ async def redact_events_related_to(
event_id.
relation_types: The types of relations to look for. If "*" is in the list,
all related events will be redacted regardless of the type.
room_version: The RoomVersion of the room, for deciding where the 'redacts'
key should go in the event dict

Raises:
ShadowBanError if the requester is shadow-banned
Expand All @@ -244,16 +248,24 @@ async def redact_events_related_to(
)

for related_event_id in related_event_ids:
# Depending on the room version involved, the "redacts" key can go in one of
# two places. If we only use what was provided in the initial event, it will
# only target an event that was already redacted and nothing will happen.
new_redaction_content = dict(initial_redaction_event.content)
event_dict: JsonDict = {
"type": EventTypes.Redaction,
"content": new_redaction_content,
"room_id": initial_redaction_event.room_id,
"sender": requester.user.to_string(),
}
if room_version.updated_redaction_rules:
event_dict["content"].update({"redacts": related_event_id})
else:
event_dict["redacts"] = related_event_id
try:
await self._event_creation_handler.create_and_send_nonmember_event(
requester,
{
"type": EventTypes.Redaction,
"content": initial_redaction_event.content,
"room_id": initial_redaction_event.room_id,
"sender": requester.user.to_string(),
"redacts": related_event_id,
},
event_dict,
ratelimit=False,
)
except SynapseError as e:
Expand Down
1 change: 1 addition & 0 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ async def _do(
event_id=event_id,
initial_redaction_event=event,
relation_types=with_relations,
room_version=room_version,
)

event_id = event.event_id
Expand Down
Loading