diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2024-04-29 15:22:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 15:22:13 +0100 |
commit | b548f7803a9b7ba51a66d47ddb9bb69dce541a48 (patch) | |
tree | edf0a111f84a08464c6551c4d75e3667fa13c60b /synapse/events | |
parent | Update tornado 6.2 -> 6.4 (#17131) (diff) | |
download | synapse-b548f7803a9b7ba51a66d47ddb9bb69dce541a48.tar.xz |
Add support for MSC4115 (#17104)
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
Diffstat (limited to 'synapse/events')
-rw-r--r-- | synapse/events/utils.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py index e0613d0dbc..0772472312 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -49,7 +49,7 @@ from synapse.api.errors import Codes, SynapseError from synapse.api.room_versions import RoomVersion from synapse.types import JsonDict, Requester -from . import EventBase +from . import EventBase, make_event_from_dict if TYPE_CHECKING: from synapse.handlers.relations import BundledAggregations @@ -82,17 +82,14 @@ def prune_event(event: EventBase) -> EventBase: """ pruned_event_dict = prune_event_dict(event.room_version, event.get_dict()) - from . import make_event_from_dict - pruned_event = make_event_from_dict( pruned_event_dict, event.room_version, event.internal_metadata.get_dict() ) - # copy the internal fields + # Copy the bits of `internal_metadata` that aren't returned by `get_dict` pruned_event.internal_metadata.stream_ordering = ( event.internal_metadata.stream_ordering ) - pruned_event.internal_metadata.outlier = event.internal_metadata.outlier # Mark the event as redacted @@ -101,6 +98,29 @@ def prune_event(event: EventBase) -> EventBase: return pruned_event +def clone_event(event: EventBase) -> EventBase: + """Take a copy of the event. + + This is mostly useful because it does a *shallow* copy of the `unsigned` data, + which means it can then be updated without corrupting the in-memory cache. Note that + other properties of the event, such as `content`, are *not* (currently) copied here. + """ + # XXX: We rely on at least one of `event.get_dict()` and `make_event_from_dict()` + # making a copy of `unsigned`. Currently, both do, though I don't really know why. + # Still, as long as they do, there's not much point doing yet another copy here. + new_event = make_event_from_dict( + event.get_dict(), event.room_version, event.internal_metadata.get_dict() + ) + + # Copy the bits of `internal_metadata` that aren't returned by `get_dict`. + new_event.internal_metadata.stream_ordering = ( + event.internal_metadata.stream_ordering + ) + new_event.internal_metadata.outlier = event.internal_metadata.outlier + + return new_event + + def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDict: """Redacts the event_dict in the same way as `prune_event`, except it operates on dicts rather than event objects |