Add account logout feature via context menu
This commit is contained in:
@@ -99,14 +99,10 @@ class Backend:
|
||||
async def logout_client(self, user_id: str) -> None:
|
||||
client = self.clients.pop(user_id, None)
|
||||
if client:
|
||||
self.models[Account].pop(client.user_id, None)
|
||||
self.models[Account].pop(user_id, None)
|
||||
await client.logout()
|
||||
|
||||
|
||||
async def logout_all_clients(self) -> None:
|
||||
await asyncio.gather(*(
|
||||
self.logout_client(user_id) for user_id in self.clients.copy()
|
||||
))
|
||||
await self.saved_accounts.delete(user_id)
|
||||
|
||||
|
||||
async def wait_until_client_exists(self, user_id: str = "") -> None:
|
||||
|
@@ -131,6 +131,7 @@ class MatrixClient(nio.AsyncClient):
|
||||
with suppress(asyncio.CancelledError):
|
||||
await self.sync_task
|
||||
|
||||
await super().logout()
|
||||
await self.close()
|
||||
|
||||
|
||||
@@ -146,13 +147,14 @@ class MatrixClient(nio.AsyncClient):
|
||||
ft = asyncio.ensure_future(self.backend.get_profile(self.user_id))
|
||||
ft.add_done_callback(on_profile_response)
|
||||
|
||||
def on_unexpected_sync_stop(future) -> None:
|
||||
raise future.exception()
|
||||
def on_sync_stop(future) -> None:
|
||||
if isinstance(future.exception(), BaseException):
|
||||
raise future.exception()
|
||||
|
||||
self.sync_task = asyncio.ensure_future(
|
||||
self.sync_forever(timeout=10_000),
|
||||
)
|
||||
self.sync_task.add_done_callback(on_unexpected_sync_stop)
|
||||
self.sync_task.add_done_callback(on_sync_stop)
|
||||
|
||||
|
||||
@property
|
||||
|
Reference in New Issue
Block a user