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

Support room version 11 #15912

Merged
merged 8 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@ def serialize_event(
if config.as_client_event:
d = config.event_format(d)

# If the event is a redaction, copy the redacts field from the content to
# top-level for backwards compatibility.
if (
e.type == EventTypes.Redaction
and e.room_version.updated_redaction_rules
and e.redacts is not None
):
d["redacts"] = e.redacts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where was this discussed as a thing needing to be done? I'm slightly hesitant to sneak such a change in a PR to stabilise the room versions, unless its something that has been discussed/is in the MSC/etc

Copy link
Member Author

@clokep clokep Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #15823, it points back to the text from the MSC. It was missed in the initial implementation of MSC2174.


only_event_fields = config.only_event_fields
if only_event_fields:
if not isinstance(only_event_fields, list) or not all(
Expand Down
19 changes: 18 additions & 1 deletion tests/rest/client/test_redactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from synapse.rest import admin
from synapse.rest.client import login, room, sync
from synapse.server import HomeServer
from synapse.storage._base import db_to_json
from synapse.storage.database import LoggingTransaction
from synapse.types import JsonDict
from synapse.util import Clock

Expand Down Expand Up @@ -597,5 +599,20 @@ def test_content_redaction(self) -> None:
redact_event = timeline[-1]
self.assertEqual(redact_event["type"], EventTypes.Redaction)
# The redacts key should be in the content.
self.assertNotIn("redacts", redact_event)
self.assertEquals(redact_event["content"]["redacts"], event_id)

# It should also be copied as the top-level redacts field for backwards
# compatibility.
self.assertEquals(redact_event["redacts"], event_id)

# But it isn't actually part of the event.
def get_event(txn: LoggingTransaction) -> JsonDict:
return db_to_json(
main_datastore._fetch_event_rows(txn, [event_id])[event_id].json
)

main_datastore = self.hs.get_datastores().main
event_json = self.get_success(
main_datastore.db_pool.runInteraction("get_event", get_event)
)
self.assertNotIn("redacts", event_json)