mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:46:06 -04:00
Pass the current time to serialize event, rather than passing an
HS and getting a clock from it and calling time_msec on the clock. Remove the serialize_event method from the HS since it is no longer needed.
This commit is contained in:
parent
7b814d3f7f
commit
7f6f3f9d62
7 changed files with 45 additions and 20 deletions
|
@ -89,31 +89,31 @@ def prune_event(event):
|
|||
return type(event)(allowed_fields)
|
||||
|
||||
|
||||
def serialize_event(hs, e, client_event=True):
|
||||
def serialize_event(e, time_now_ms, client_event=True):
|
||||
# FIXME(erikj): To handle the case of presence events and the like
|
||||
if not isinstance(e, EventBase):
|
||||
return e
|
||||
|
||||
time_now_ms = int(time_now_ms)
|
||||
|
||||
# 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"]:
|
||||
now = int(hs.get_clock().time_msec())
|
||||
d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
|
||||
d["unsigned"]["age"] = time_now_ms - d["unsigned"]["age_ts"]
|
||||
return d
|
||||
|
||||
if "age_ts" in d["unsigned"]:
|
||||
now = int(hs.get_clock().time_msec())
|
||||
d["age"] = now - d["unsigned"]["age_ts"]
|
||||
d["age"] = time_now_ms - d["unsigned"]["age_ts"]
|
||||
del d["unsigned"]["age_ts"]
|
||||
|
||||
d["user_id"] = d.pop("sender", None)
|
||||
|
||||
if "redacted_because" in e.unsigned:
|
||||
d["redacted_because"] = serialize_event(
|
||||
hs, e.unsigned["redacted_because"]
|
||||
e.unsigned["redacted_because"], time_now_ms
|
||||
)
|
||||
|
||||
del d["unsigned"]["redacted_because"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue