diff options
author | Erik Johnston <erik@matrix.org> | 2014-09-23 15:37:32 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-09-23 15:37:32 +0100 |
commit | 932b376b4e3d1992268274f25e2343f6e81d93f8 (patch) | |
tree | 5aeeec82a70c39e6dcd558e986d7f6e31b7eac01 /synapse/api/events/utils.py | |
parent | Make sure we don't persist the 'pruned' key (diff) | |
download | synapse-932b376b4e3d1992268274f25e2343f6e81d93f8.tar.xz |
Add prune_event method
Diffstat (limited to 'synapse/api/events/utils.py')
-rw-r--r-- | synapse/api/events/utils.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/synapse/api/events/utils.py b/synapse/api/events/utils.py new file mode 100644 index 0000000000..dfefb2662a --- /dev/null +++ b/synapse/api/events/utils.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 OpenMarket Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .room import RoomMemberEvent + +def prune_event(event): + """ Prunes the given event of all keys we don't know about or think could + potentially be dodgy. + + This is used when we "delete" an event. We want to remove all fields that + the user has specified, but we do want to keep necessary information like + type, state_key etc. + """ + + # Remove all extraneous fields. + event.unrecognized_keys = {} + + if event.type == RoomMemberEvent.TYPE: + new_content = { + "membership": event.content["membership"] + } + else: + new_content = {} + + event.content = new_content + + return event |