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
1b4a164c
Commit
1b4a164c
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Add support for formatting events in the way a v2 client expects
parent
c81a1955
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/events/utils.py
+52
-39
52 additions, 39 deletions
synapse/events/utils.py
with
52 additions
and
39 deletions
synapse/events/utils.py
+
52
−
39
View file @
1b4a164c
...
...
@@ -89,7 +89,46 @@ def prune_event(event):
return
type
(
event
)(
allowed_fields
)
def
serialize_event
(
e
,
time_now_ms
,
client_event
=
True
,
strip_ids
=
False
):
def
format_event_raw
(
d
):
return
d
def
format_event_for_client_v1
(
d
):
d
[
"
user_id
"
]
=
d
.
pop
(
"
sender
"
,
None
)
move_keys
=
(
"
age
"
,
"
redacted_because
"
,
"
replaces_state
"
,
"
prev_content
"
)
for
key
in
move_keys
:
if
key
in
d
[
"
unsigned
"
]:
d
[
key
]
=
d
[
"
unsigned
"
][
key
]
drop_keys
=
(
"
auth_events
"
,
"
prev_events
"
,
"
hashes
"
,
"
signatures
"
,
"
depth
"
,
"
unsigned
"
,
"
origin
"
)
for
key
in
drop_keys
:
d
.
pop
(
key
,
None
)
return
d
def
format_event_for_client_v2
(
d
):
drop_keys
=
(
"
auth_events
"
,
"
prev_events
"
,
"
hashes
"
,
"
signatures
"
,
"
depth
"
,
"
origin
"
)
for
key
in
drop_keys
:
d
.
pop
(
key
,
None
)
return
d
def
format_event_for_client_v2_without_event_id
(
d
):
d
=
format_event_for_client_v2
(
d
)
d
.
pop
(
"
room_id
"
,
None
)
d
.
pop
(
"
event_id
"
,
None
)
return
d
def
serialize_event
(
e
,
time_now_ms
,
as_client_event
=
True
,
event_format
=
format_event_for_client_v1
,
token_id
=
None
):
# FIXME(erikj): To handle the case of presence events and the like
if
not
isinstance
(
e
,
EventBase
):
return
e
...
...
@@ -99,48 +138,22 @@ def serialize_event(e, time_now_ms, client_event=True, strip_ids=False):
# Should this strip out None's?
d
=
{
k
:
v
for
k
,
v
in
e
.
get_dict
().
items
()}
if
not
client_event
:
# set the age and keep all other keys
if
"
age_ts
"
in
d
[
"
unsigned
"
]:
d
[
"
unsigned
"
][
"
age
"
]
=
time_now_ms
-
d
[
"
unsigned
"
][
"
age_ts
"
]
return
d
if
"
age_ts
"
in
d
[
"
unsigned
"
]:
d
[
"
age
"
]
=
time_now_ms
-
d
[
"
unsigned
"
][
"
age_ts
"
]
del
d
[
"
unsigned
"
][
"
age_ts
"
]
d
[
"
user_id
"
]
=
d
.
pop
(
"
sender
"
,
None
)
d
[
"
unsigned
"
][
"
age
"
]
=
time_now_ms
-
d
[
"
unsigned
"
][
"
age_ts
"
]
d
[
"
unsigned
"
][
"
age_ts
"
]
if
"
redacted_because
"
in
e
.
unsigned
:
d
[
"
redacted_because
"
]
=
serialize_event
(
d
[
"
unsigned
"
][
"
redacted_because
"
]
=
serialize_event
(
e
.
unsigned
[
"
redacted_because
"
],
time_now_ms
)
del
d
[
"
unsigned
"
][
"
redacted_because
"
]
if
"
redacted_by
"
in
e
.
unsigned
:
d
[
"
redacted_by
"
]
=
e
.
unsigned
[
"
redacted_by
"
]
del
d
[
"
unsigned
"
][
"
redacted_by
"
]
if
token_id
is
not
None
:
if
token_id
==
e
.
internal_metadata
[
"
token_id
"
]:
txn_id
=
e
.
internal_metadata
.
get
(
"
txn_id
"
,
None
)
if
txn_id
is
not
None
:
d
[
"
unsigned
"
][
"
transaction_id
"
]
=
txn_id
if
"
replaces_state
"
in
e
.
unsigned
:
d
[
"
replaces_state
"
]
=
e
.
unsigned
[
"
replaces_state
"
]
del
d
[
"
unsigned
"
][
"
replaces_state
"
]
if
"
prev_content
"
in
e
.
unsigned
:
d
[
"
prev_content
"
]
=
e
.
unsigned
[
"
prev_content
"
]
del
d
[
"
unsigned
"
][
"
prev_content
"
]
del
d
[
"
auth_events
"
]
del
d
[
"
prev_events
"
]
del
d
[
"
hashes
"
]
del
d
[
"
signatures
"
]
d
.
pop
(
"
depth
"
,
None
)
d
.
pop
(
"
unsigned
"
,
None
)
d
.
pop
(
"
origin
"
,
None
)
d
.
pop
(
"
prev_state
"
,
None
)
if
strip_ids
:
d
.
pop
(
"
room_id
"
,
None
)
d
.
pop
(
"
event_id
"
,
None
)
return
d
if
as_client_event
:
return
event_format
(
d
)
else
:
return
d
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