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 @@
Put the `redacts` key under `content` when generating [MSC3912](https://github.com/matrix-org/matrix-spec-proposals/pull/3912) (relation based redactions) for room versions greater than 10. Contributed by @famedly.
30 changes: 23 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. Used 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,28 @@ async def redact_events_related_to(
)

for related_event_id in related_event_ids:
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(),
}
# Depending on the room version involved, the "redacts" key can go in one of
# two places.
#
# The Matrix Spec page for changes in Room Version 11 asks that we maintain
# a backward and forwards compatibility for clients over that API. That
# compatibility fixup will be in the client event serialization code. Here
# we form and persist the event strictly by the version of the room.
if room_version.updated_redaction_rules:
event_dict["content"].update({"redacts": related_event_id})
else:
event_dict["redacts"] = related_event_id
Comment thread
anoadragon453 marked this conversation as resolved.
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