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 ## Backend
- Use new nio `AsyncClient.restore_login()`
- Better config file format - Better config file format
- Prevent starting multiple client instances, causes problems with E2E DB - 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.""" """Create and register a `MatrixClient` with known account details."""
client = MatrixClient( client = MatrixClient(
backend=self, self, user=user_id, homeserver=homeserver, device_id=device_id,
user=user_id, homeserver=homeserver, device_id=device_id,
) )
self.clients[user_id] = client self.clients[user_id] = client

View File

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