Fix logout
This commit is contained in:
parent
5a70adcc93
commit
60c64ad96f
|
@ -81,7 +81,9 @@ class MatrixClient(nio.AsyncClient):
|
||||||
self.backend: Backend = backend
|
self.backend: Backend = backend
|
||||||
self.models: ModelStore = self.backend.models
|
self.models: ModelStore = self.backend.models
|
||||||
|
|
||||||
self.starter_task: Optional[asyncio.Future] = None
|
self.profile_task: Optional[asyncio.Future] = None
|
||||||
|
self.sync_task: Optional[asyncio.Future] = None
|
||||||
|
self.load_rooms_task: Optional[asyncio.Future] = None
|
||||||
self.first_sync_done: asyncio.Event = asyncio.Event()
|
self.first_sync_done: asyncio.Event = asyncio.Event()
|
||||||
self.first_sync_date: Optional[datetime] = None
|
self.first_sync_date: Optional[datetime] = None
|
||||||
|
|
||||||
|
@ -123,21 +125,22 @@ class MatrixClient(nio.AsyncClient):
|
||||||
if isinstance(response, nio.LoginError):
|
if isinstance(response, nio.LoginError):
|
||||||
raise MatrixError.from_nio(response)
|
raise MatrixError.from_nio(response)
|
||||||
|
|
||||||
self.starter_task = asyncio.ensure_future(self.start())
|
asyncio.ensure_future(self.start())
|
||||||
|
|
||||||
|
|
||||||
async def resume(self, user_id: str, token: str, device_id: str) -> None:
|
async def resume(self, user_id: str, token: str, device_id: str) -> None:
|
||||||
response = nio.LoginResponse(user_id, device_id, token)
|
response = nio.LoginResponse(user_id, device_id, token)
|
||||||
await self.receive_response(response)
|
await self.receive_response(response)
|
||||||
self.starter_task = asyncio.ensure_future(self.start())
|
|
||||||
|
asyncio.ensure_future(self.start())
|
||||||
|
|
||||||
|
|
||||||
async def logout(self) -> None:
|
async def logout(self) -> None:
|
||||||
if self.starter_task:
|
for task in (self.profile_task, self.load_rooms_task, self.sync_task):
|
||||||
self.starter_task.cancel()
|
if task:
|
||||||
|
task.cancel()
|
||||||
with suppress(asyncio.CancelledError):
|
with suppress(asyncio.CancelledError):
|
||||||
await self.starter_task
|
await task
|
||||||
|
|
||||||
await super().logout()
|
await super().logout()
|
||||||
await self.close()
|
await self.close()
|
||||||
|
@ -157,12 +160,18 @@ class MatrixClient(nio.AsyncClient):
|
||||||
account.display_name = resp.displayname or ""
|
account.display_name = resp.displayname or ""
|
||||||
account.avatar_url = resp.avatar_url or ""
|
account.avatar_url = resp.avatar_url or ""
|
||||||
|
|
||||||
ft = asyncio.ensure_future(self.backend.get_profile(self.user_id))
|
self.profile_task = asyncio.ensure_future(
|
||||||
ft.add_done_callback(on_profile_response)
|
self.backend.get_profile(self.user_id),
|
||||||
|
)
|
||||||
|
self.profile_task.add_done_callback(on_profile_response)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
await self.sync_forever(timeout=10_000)
|
self.sync_task = asyncio.ensure_future(
|
||||||
|
self.sync_forever(timeout=10_000),
|
||||||
|
)
|
||||||
|
await self.sync_task
|
||||||
|
break # task cancelled
|
||||||
except Exception:
|
except Exception:
|
||||||
trace = traceback.format_exc().rstrip()
|
trace = traceback.format_exc().rstrip()
|
||||||
log.error("Exception during sync, will restart:\n%s", trace)
|
log.error("Exception during sync, will restart:\n%s", trace)
|
||||||
|
|
|
@ -58,7 +58,9 @@ class NioCallbacks:
|
||||||
await c.register_nio_room(c.all_rooms[room_id], left=True)
|
await c.register_nio_room(c.all_rooms[room_id], left=True)
|
||||||
|
|
||||||
if not c.first_sync_done.is_set():
|
if not c.first_sync_done.is_set():
|
||||||
asyncio.ensure_future(c.load_rooms_without_visible_events())
|
self.client.load_rooms_task = asyncio.ensure_future(
|
||||||
|
c.load_rooms_without_visible_events(),
|
||||||
|
)
|
||||||
|
|
||||||
c.first_sync_done.set()
|
c.first_sync_done.set()
|
||||||
c.first_sync_date = datetime.now()
|
c.first_sync_date = datetime.now()
|
||||||
|
|
|
@ -50,7 +50,6 @@ BoxPopup {
|
||||||
}
|
}
|
||||||
|
|
||||||
py.callCoro("logout_client", [userId])
|
py.callCoro("logout_client", [userId])
|
||||||
|
|
||||||
popup.close()
|
popup.close()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user