From 2fc738dc20c7e77787fccab5ede1fc16a629edbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Jun 2019 15:00:35 +0200 Subject: [PATCH] client: Change the initial sync to contain full state. Fetching the full state with the initial sync is important because we don't store any room state locally. Since we don't store any sync token we are getting the full state anyways. But once we do this change will be crucial for encryption to work correctly. --- pantalaimon/client.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/pantalaimon/client.py b/pantalaimon/client.py index 0db4220..fbfb5a5 100644 --- a/pantalaimon/client.py +++ b/pantalaimon/client.py @@ -372,6 +372,15 @@ class PanClient(AsyncClient): logger.info(f"Starting sync loop for {self.user_id}") loop = asyncio.get_event_loop() + + self.history_fetcher_task = loop.create_task(self.fetcher_loop()) + + task = loop.create_task(self.sync_loop()) + self.task = task + + return task + + async def sync_loop(self): timeout = 30000 sync_filter = { @@ -380,11 +389,32 @@ class PanClient(AsyncClient): } } - task = loop.create_task(self.sync_forever(timeout, sync_filter)) - self.task = task - self.history_fetcher_task = loop.create_task(self.fetcher_loop()) + # We don't store any room state so initial sync needs to be with the + # full_state parameter. Subsequent ones are normal. + while True: + try: + response = await self.sync( + sync_filter=sync_filter, + full_state=True + ) + + if isinstance(response, SyncResponse): + await self.sync_tasks(response) + break + else: + await asyncio.sleep(3) + + except asyncio.CancelledError: + return + + except ClientConnectionError: + try: + await asyncio.sleep(3) + except asyncio.CancelledError: + return + + await self.sync_forever(timeout, sync_filter) - return task async def start_sas(self, message, device): try: