Fix /room/.../event/... to return the *original* event after any edits (#12476)

This is what the MSC (now) requires. Fixes https://github.com/matrix-org/synapse/issues/10310.
This commit is contained in:
Richard van der Hoff 2022-04-19 16:42:19 +01:00 committed by GitHub
parent 798deb3a10
commit b80bb7e452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 39 deletions

View file

@ -402,6 +402,7 @@ class EventClientSerializer:
*,
config: SerializeEventConfig = _DEFAULT_SERIALIZE_EVENT_CONFIG,
bundle_aggregations: Optional[Dict[str, "BundledAggregations"]] = None,
apply_edits: bool = True,
) -> JsonDict:
"""Serializes a single event.
@ -409,10 +410,10 @@ class EventClientSerializer:
event: The event being serialized.
time_now: The current time in milliseconds
config: Event serialization config
bundle_aggregations: Whether to include the bundled aggregations for this
event. Only applies to non-state events. (State events never include
bundled aggregations.)
bundle_aggregations: A map from event_id to the aggregations to be bundled
into the event.
apply_edits: Whether the content of the event should be modified to reflect
any replacement in `bundle_aggregations[<event_id>].replace`.
Returns:
The serialized event
"""
@ -430,8 +431,9 @@ class EventClientSerializer:
event,
time_now,
config,
bundle_aggregations[event.event_id],
event_aggregations,
serialized_event,
apply_edits=apply_edits,
)
return serialized_event
@ -470,6 +472,7 @@ class EventClientSerializer:
config: SerializeEventConfig,
aggregations: "BundledAggregations",
serialized_event: JsonDict,
apply_edits: bool,
) -> None:
"""Potentially injects bundled aggregations into the unsigned portion of the serialized event.
@ -479,7 +482,8 @@ class EventClientSerializer:
aggregations: The bundled aggregation to serialize.
serialized_event: The serialized event which may be modified.
config: Event serialization config
apply_edits: Whether the content of the event should be modified to reflect
any replacement in `aggregations.replace`.
"""
serialized_aggregations = {}
@ -490,9 +494,10 @@ class EventClientSerializer:
serialized_aggregations[RelationTypes.REFERENCE] = aggregations.references
if aggregations.replace:
# If there is an edit, apply it to the event.
# If there is an edit, optionally apply it to the event.
edit = aggregations.replace
self._apply_edit(event, serialized_event, edit)
if apply_edits:
self._apply_edit(event, serialized_event, edit)
# Include information about it in the relations dict.
serialized_aggregations[RelationTypes.REPLACE] = {