From fc2fb605e3aae2c33a4e680b3750d665479b5ffa Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 14 Nov 2019 16:20:30 -0400 Subject: [PATCH] Prefer using own client for fetching own profile --- TODO.md | 4 ++++ src/python/backend.py | 16 +++++++++------- src/python/matrix_client.py | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 065ac948..90fc92e9 100644 --- a/TODO.md +++ b/TODO.md @@ -33,6 +33,7 @@ - When qml syntax highlighting supports ES6 string interpolation, use that - Fixes + - CPU usage - `code` not colored in room subtitle - In the "Leave me" room, "join > Hi > left" aren't combined - Event delegates changing height don't scroll the list @@ -146,6 +147,9 @@ - Edit/delete own devices - Request room keys from own other devices - Auto-trust accounts within the same client + - Provide help when undecryptable messages occur, including: + - Trigger `nio.AsyncClient.request_room_key` + - Option to export-logout-login-import to fix one-time key problems - Read receipts - Status message and presence diff --git a/src/python/backend.py b/src/python/backend.py index 11daa80f..2286ebce 100644 --- a/src/python/backend.py +++ b/src/python/backend.py @@ -197,13 +197,14 @@ class Backend: # Client functions that don't need authentification - async def _any_client(self) -> MatrixClient: + async def _any_client(self, prefer: str = "") -> MatrixClient: while True: - try: - return next(c for c in self.clients.values()) - except StopIteration: - # Retry after a bit if we don't have any clients yet - await asyncio.sleep(0.1) + if self.clients: + break + await asyncio.sleep(0.1) + + return self.clients.get(prefer) or \ + next(c for c in self.clients.values()) async def get_profile(self, user_id: str) -> nio.ProfileGetResponse: @@ -211,7 +212,8 @@ class Backend: return self.profile_cache[user_id] async with self.get_profile_locks[user_id]: - response = await (await self._any_client()).get_profile(user_id) + client = await self._any_client(prefer=user_id) + response = await client.get_profile(user_id) if isinstance(response, nio.ProfileGetError): raise MatrixError.from_nio(response) diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index fcc2cc88..7ccb8b47 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -133,7 +133,10 @@ class MatrixClient(nio.AsyncClient): async def start(self) -> None: def on_profile_response(future) -> None: - if future.exception(): + exception = future.exception() + + if exception: + log.warn("On %s client startup: %s", self.user_id, exception) return resp = future.result()