Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
4e79b09d
Commit
4e79b09d
authored
10 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Fill out the prune_event method.
parent
3d2cca67
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/api/events/utils.py
+31
-6
31 additions, 6 deletions
synapse/api/events/utils.py
with
31 additions
and
6 deletions
synapse/api/events/utils.py
+
31
−
6
View file @
4e79b09d
...
@@ -13,7 +13,11 @@
...
@@ -13,7 +13,11 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
.room
import
RoomMemberEvent
from
.room
import
(
RoomMemberEvent
,
RoomJoinRulesEvent
,
RoomPowerLevelsEvent
,
RoomAddStateLevelEvent
,
RoomSendEventLevelEvent
,
RoomOpsPowerLevelsEvent
,
RoomAliasesEvent
,
RoomCreateEvent
,
)
def
prune_event
(
event
):
def
prune_event
(
event
):
"""
Prunes the given event of all keys we don
'
t know about or think could
"""
Prunes the given event of all keys we don
'
t know about or think could
...
@@ -27,12 +31,33 @@ def prune_event(event):
...
@@ -27,12 +31,33 @@ def prune_event(event):
# Remove all extraneous fields.
# Remove all extraneous fields.
event
.
unrecognized_keys
=
{}
event
.
unrecognized_keys
=
{}
new_content
=
{}
def
add_fields
(
*
fields
):
for
field
in
fields
:
if
field
in
event
.
content
:
new_content
[
field
]
=
event
.
content
[
field
]
if
event
.
type
==
RoomMemberEvent
.
TYPE
:
if
event
.
type
==
RoomMemberEvent
.
TYPE
:
new_content
=
{
add_fields
(
"
membership
"
)
"
membership
"
:
event
.
content
[
"
membership
"
]
elif
event
.
type
==
RoomCreateEvent
.
TYPE
:
}
add_fields
(
"
creator
"
)
else
:
elif
event
.
type
==
RoomJoinRulesEvent
.
TYPE
:
new_content
=
{}
add_fields
(
"
join_rule
"
)
elif
event
.
type
==
RoomPowerLevelsEvent
.
TYPE
:
# TODO: Actually check these are valid user_ids etc.
add_fields
(
"
default
"
)
for
k
,
v
in
event
.
content
.
items
():
if
k
.
startswith
(
"
@
"
)
and
isinstance
(
v
,
(
int
,
long
)):
new_content
[
k
]
=
v
elif
event
.
type
==
RoomAddStateLevelEvent
.
TYPE
:
add_fields
(
"
level
"
)
elif
event
.
type
==
RoomSendEventLevelEvent
.
TYPE
:
add_fields
(
"
level
"
)
elif
event
.
type
==
RoomOpsPowerLevelsEvent
.
TYPE
:
add_fields
(
"
kick_level
"
,
"
ban_level
"
,
"
delete_level
"
)
elif
event
.
type
==
RoomAliasesEvent
.
TYPE
:
add_fields
(
"
aliases
"
)
event
.
content
=
new_content
event
.
content
=
new_content
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment