Prefer using own client for fetching own profile
This commit is contained in:
parent
f727645342
commit
fc2fb605e3
4
TODO.md
4
TODO.md
|
@ -33,6 +33,7 @@
|
||||||
- When qml syntax highlighting supports ES6 string interpolation, use that
|
- When qml syntax highlighting supports ES6 string interpolation, use that
|
||||||
|
|
||||||
- Fixes
|
- Fixes
|
||||||
|
- CPU usage
|
||||||
- `code` not colored in room subtitle
|
- `code` not colored in room subtitle
|
||||||
- In the "Leave me" room, "join > Hi > left" aren't combined
|
- In the "Leave me" room, "join > Hi > left" aren't combined
|
||||||
- Event delegates changing height don't scroll the list
|
- Event delegates changing height don't scroll the list
|
||||||
|
@ -146,6 +147,9 @@
|
||||||
- Edit/delete own devices
|
- Edit/delete own devices
|
||||||
- Request room keys from own other devices
|
- Request room keys from own other devices
|
||||||
- Auto-trust accounts within the same client
|
- 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
|
- Read receipts
|
||||||
- Status message and presence
|
- Status message and presence
|
||||||
|
|
||||||
|
|
|
@ -197,21 +197,23 @@ class Backend:
|
||||||
|
|
||||||
# Client functions that don't need authentification
|
# Client functions that don't need authentification
|
||||||
|
|
||||||
async def _any_client(self) -> MatrixClient:
|
async def _any_client(self, prefer: str = "") -> MatrixClient:
|
||||||
while True:
|
while True:
|
||||||
try:
|
if self.clients:
|
||||||
return next(c for c in self.clients.values())
|
break
|
||||||
except StopIteration:
|
|
||||||
# Retry after a bit if we don't have any clients yet
|
|
||||||
await asyncio.sleep(0.1)
|
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:
|
async def get_profile(self, user_id: str) -> nio.ProfileGetResponse:
|
||||||
if user_id in self.profile_cache:
|
if user_id in self.profile_cache:
|
||||||
return self.profile_cache[user_id]
|
return self.profile_cache[user_id]
|
||||||
|
|
||||||
async with self.get_profile_locks[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):
|
if isinstance(response, nio.ProfileGetError):
|
||||||
raise MatrixError.from_nio(response)
|
raise MatrixError.from_nio(response)
|
||||||
|
|
|
@ -133,7 +133,10 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
def on_profile_response(future) -> 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
|
return
|
||||||
|
|
||||||
resp = future.result()
|
resp = future.result()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user