Use nio's new restore_login() method

This commit is contained in:
miruka 2020-07-26 23:45:28 -04:00
parent e611f89fe3
commit 6d8980bcb3
3 changed files with 10 additions and 13 deletions

View File

@ -176,8 +176,6 @@
## Backend
- Use new nio `AsyncClient.restore_login()`
- Better config file format
- Prevent starting multiple client instances, causes problems with E2E DB

View File

@ -233,8 +233,7 @@ class Backend:
"""Create and register a `MatrixClient` with known account details."""
client = MatrixClient(
backend=self,
user=user_id, homeserver=homeserver, device_id=device_id,
self, user=user_id, homeserver=homeserver, device_id=device_id,
)
self.clients[user_id] = client

View File

@ -292,19 +292,19 @@ class MatrixClient(nio.AsyncClient):
async def resume(
self,
user_id: str,
token: str,
device_id: str,
state: str = "online",
status_msg: str = "",
user_id: str,
access_token: str,
device_id: str,
state: str = "online",
status_msg: str = "",
) -> None:
"""Login to the server using an existing access token."""
"""Restore a previous login to the server with a saved access token."""
response = nio.LoginResponse(user_id, device_id, token)
account = self.models["accounts"][user_id]
await self.receive_response(response)
self.restore_login(user_id, device_id, access_token)
account = self.models["accounts"][user_id]
self._presence = "offline" if state == "invisible" else state
account.set_fields(
presence=Presence.State(state), status_msg=status_msg,
)