diff options
author | Richard van der Hoff <richard@matrix.org> | 2024-04-23 17:10:20 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2024-04-23 17:10:20 +0100 |
commit | 6a4c6a1492e6a578090227b6e8ff0ab892bd6903 (patch) | |
tree | 9247f1020288d0cbe68b8206987c30ab6083dc27 /synapse/events | |
parent | Merge branch 'rav/log_state_desync' into active_branches_base (diff) | |
parent | Enable MSC4115 in complement tests (diff) | |
download | synapse-6a4c6a1492e6a578090227b6e8ff0ab892bd6903.tar.xz |
Merge branch 'rav/event_visibility' into active_branches_base github/rav/work rav/work
Diffstat (limited to 'synapse/events')
-rw-r--r-- | synapse/events/utils.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py index e0613d0dbc..8b7c5885db 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,8 +82,6 @@ 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() ) @@ -101,6 +99,25 @@ 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. + """ + new_event = make_event_from_dict( + event.get_dict(), event.room_version, event.internal_metadata.get_dict() + ) + + # copy the internal fields + 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 |