mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-10-01 03:35:38 -04:00
main: Handle sync requests.
Note this does not handle encryption yet. It just passes the request transparently to nio.
This commit is contained in:
parent
710939e5bd
commit
8b791976cd
41
main.py
41
main.py
@ -142,9 +142,46 @@ class ProxyDaemon:
|
||||
)
|
||||
|
||||
async def sync(self, request):
|
||||
access_token = self.get_access_token(request)
|
||||
|
||||
if not access_token:
|
||||
return web.Response(
|
||||
status=405,
|
||||
text="Not implemented"
|
||||
status=401,
|
||||
text=json.dumps({
|
||||
"errcode": "M_MISSING_TOKEN",
|
||||
"error": "Missing access token."
|
||||
})
|
||||
)
|
||||
|
||||
try:
|
||||
client = self.client_sessions[access_token]
|
||||
except KeyError:
|
||||
return web.Response(
|
||||
status=401,
|
||||
text=json.dumps({
|
||||
"errcode": "M_UNKNOWN_TOKEN",
|
||||
"error": "Unrecognised access token."
|
||||
})
|
||||
)
|
||||
|
||||
sync_filter = request.query.get("filter", None)
|
||||
timeout = request.query.get("timeout", None)
|
||||
|
||||
try:
|
||||
sync_filter = json.loads(sync_filter)
|
||||
except (JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
response = await client.sync(timeout, sync_filter)
|
||||
|
||||
# TODO replace decrypted messages here, upload keys, fetch the members
|
||||
# of encrypted rooms if needed and do key queries if needed.
|
||||
|
||||
print("Should upload keys: {}".format(client.should_upload_keys))
|
||||
|
||||
return web.Response(
|
||||
status=response.transport_response.status,
|
||||
text=await response.transport_response.text()
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user