From af3b62dd7e75a222de207468e11d53ee13b05082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 20 Feb 2020 13:15:43 +0100 Subject: [PATCH] daemon: Load the media info when we start the daemon. --- pantalaimon/client.py | 3 ++- pantalaimon/daemon.py | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pantalaimon/client.py b/pantalaimon/client.py index 65ba83a..6bb4f53 100644 --- a/pantalaimon/client.py +++ b/pantalaimon/client.py @@ -33,7 +33,6 @@ from nio import ( KeyVerificationMac, KeyVerificationStart, LocalProtocolError, - OlmEvent, MegolmEvent, RoomContextError, RoomEncryptedMedia, @@ -156,6 +155,7 @@ class PanClient(AsyncClient): ssl=None, proxy=None, store_class=None, + media_info=None, ): config = config or AsyncClientConfig( store=store_class or SqliteStore, store_name="pan.db" @@ -172,6 +172,7 @@ class PanClient(AsyncClient): self.server_name = server_name self.pan_store = pan_store self.pan_conf = pan_conf + self.media_info = media_info if INDEXING_ENABLED: logger.info("Indexing enabled.") diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index c2e2ba8..f8a8488 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -91,6 +91,7 @@ class ProxyDaemon: pan_clients = attr.ib(init=False, default=attr.Factory(dict)) client_info = attr.ib(init=False, default=attr.Factory(dict), type=dict) default_session = attr.ib(init=False, default=None) + media_info = attr.ib(init=False, default=None) database_name = "pan.db" def __attrs_post_init__(self): @@ -100,6 +101,7 @@ class ProxyDaemon: self.hostname = self.homeserver.hostname self.store = PanStore(self.data_dir) accounts = self.store.load_users(self.name) + self.media_info = self.store.load_media(self.name) for user_id, device_id in accounts: if self.conf.keyring: @@ -133,6 +135,7 @@ class ProxyDaemon: ssl=self.ssl, proxy=self.proxy, store_class=self.client_store_class, + media_info=self.media_info, ) pan_client.user_id = user_id pan_client.access_token = token @@ -453,7 +456,9 @@ class ProxyDaemon: assert session - path = urllib.parse.quote(request.path) # re-encode path stuff like room aliases + path = urllib.parse.quote( + request.path + ) # re-encode path stuff like room aliases method = request.method headers = CIMultiDict(request.headers) @@ -556,6 +561,7 @@ class ProxyDaemon: ssl=self.ssl, proxy=self.proxy, store_class=self.client_store_class, + media_info=self.media_info, ) response = await pan_client.login(password, "pantalaimon")