mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
split out reducing stuff; just make encode_* static
This commit is contained in:
parent
2f82de18ee
commit
85b9f76f1d
@ -172,44 +172,36 @@ class SyncRestServlet(RestServlet):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encode_response(time_now, sync_result, access_token_id, filter):
|
def encode_response(time_now, sync_result, access_token_id, filter):
|
||||||
response = {
|
joined = SyncRestServlet.encode_joined(
|
||||||
"device_one_time_keys_count": sync_result.device_one_time_keys_count,
|
|
||||||
"next_batch": sync_result.next_batch.to_string(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if sync_result.account_data:
|
|
||||||
response["account_data"] = {"events": sync_result.account_data}
|
|
||||||
if sync_result.to_device:
|
|
||||||
response["to_device"] = {"events": sync_result.to_device}
|
|
||||||
if sync_result.device_lists:
|
|
||||||
response["device_lists"] = {
|
|
||||||
"changed": list(sync_result.device_lists),
|
|
||||||
}
|
|
||||||
|
|
||||||
if sync_result.presence:
|
|
||||||
response["presence"] = SyncRestServlet.encode_presence(
|
|
||||||
sync_result.presence, time_now
|
|
||||||
)
|
|
||||||
|
|
||||||
rooms = {}
|
|
||||||
if sync_result.joined:
|
|
||||||
rooms["join"] = SyncRestServlet.encode_joined(
|
|
||||||
sync_result.joined, time_now, access_token_id, filter.event_fields
|
sync_result.joined, time_now, access_token_id, filter.event_fields
|
||||||
)
|
)
|
||||||
if sync_result.invited:
|
|
||||||
rooms["invite"] = SyncRestServlet.encode_invited(
|
invited = SyncRestServlet.encode_invited(
|
||||||
sync_result.invited, time_now, access_token_id
|
sync_result.invited, time_now, access_token_id,
|
||||||
)
|
)
|
||||||
if sync_result.archived:
|
|
||||||
rooms["leave"] = SyncRestServlet.encode_archived(
|
archived = SyncRestServlet.encode_archived(
|
||||||
sync_result.archived, time_now, access_token_id,
|
sync_result.archived, time_now, access_token_id,
|
||||||
filter.event_fields,
|
filter.event_fields,
|
||||||
)
|
)
|
||||||
|
|
||||||
if rooms:
|
return {
|
||||||
response["rooms"] = rooms
|
"account_data": {"events": sync_result.account_data},
|
||||||
|
"to_device": {"events": sync_result.to_device},
|
||||||
return response
|
"device_lists": {
|
||||||
|
"changed": list(sync_result.device_lists),
|
||||||
|
},
|
||||||
|
"presence": SyncRestServlet.encode_presence(
|
||||||
|
sync_result.presence, time_now
|
||||||
|
),
|
||||||
|
"rooms": {
|
||||||
|
"join": joined,
|
||||||
|
"invite": invited,
|
||||||
|
"leave": archived,
|
||||||
|
},
|
||||||
|
"device_one_time_keys_count": sync_result.device_one_time_keys_count,
|
||||||
|
"next_batch": sync_result.next_batch.to_string(),
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encode_presence(events, time_now):
|
def encode_presence(events, time_now):
|
||||||
|
Loading…
Reference in New Issue
Block a user