From d2229554a982c17aa8ea15a56774f94b2c0a2cc8 Mon Sep 17 00:00:00 2001 From: vslg Date: Sun, 28 Jun 2020 09:46:34 -0300 Subject: [PATCH] Do not replace existing session (#63) --- src/backend/backend.py | 5 +++++ src/backend/matrix_client.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/backend.py b/src/backend/backend.py index 0750a51b..646fd2e7 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -135,6 +135,11 @@ class Backend: await client.close() raise + # Check if the user is already present on mirage + if client.user_id in self.clients.keys(): + await client.logout() + return client.user_id + if order is None and not self.models["accounts"]: order = 0 elif order is None: diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index d151f778..f988d3c5 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -177,6 +177,7 @@ class MatrixClient(nio.AsyncClient): self.profile_task: Optional[asyncio.Future] = None self.server_config_task: Optional[asyncio.Future] = None self.sync_task: Optional[asyncio.Future] = None + self.start_task: Optional[asyncio.Future] = None self.upload_monitors: Dict[UUID, nio.TransferMonitor] = {} self.upload_tasks: Dict[UUID, asyncio.Task] = {} @@ -236,7 +237,7 @@ class MatrixClient(nio.AsyncClient): await super().login( password, device_name or self.default_device_name(), ) - asyncio.ensure_future(self._start()) + self.start_task = asyncio.ensure_future(self._start()) async def resume(self, user_id: str, token: str, device_id: str) -> None: @@ -245,13 +246,18 @@ class MatrixClient(nio.AsyncClient): response = nio.LoginResponse(user_id, device_id, token) await self.receive_response(response) - asyncio.ensure_future(self._start()) + self.start_task = asyncio.ensure_future(self._start()) async def logout(self) -> None: """Logout from the server. This will delete the device.""" - tasks = (self.profile_task, self.sync_task, self.server_config_task) + tasks = ( + self.profile_task, + self.sync_task, + self.server_config_task, + self.start_task, + ) for task in tasks: if task: