@@ 73,7 73,6 @@ class Session(BaseSession[str, Recipient]):
self.send_lock = asyncio.Lock()
f = self.user.registration_form
self.mm_client = get_client_from_registration_form(f, self.xmpp.cache)
- self.__init_ws()
self.view_events = dict[str, asyncio.Event]()
self._ws_task: Optional[asyncio.Task] = None
self._update_status_task: Optional[asyncio.Task] = None
@@ 140,6 139,7 @@ class Session(BaseSession[str, Recipient]):
await self.mm_client.login()
else:
raise
+ self.__init_ws()
self.contacts.user_legacy_id = (await self.mm_client.me).username
t1 = self._ws_task = asyncio.create_task(self.ws.connect(self.on_mm_event))
t2 = self._update_status_task = asyncio.create_task(
@@ 167,6 167,10 @@ class Session(BaseSession[str, Recipient]):
"You can try to use the re-login command, but you might need "
"to unregister and then re-register to the gateway."
)
+ if self._ws_task is not None and not self._ws_task.done():
+ self._ws_task.cancel()
+ if self._update_status_task is not None and not self._update_status_task.done():
+ self._update_status_task.cancel()
self.logged = False
self.send_gateway_status(
f"Not connected to {self.user.registration_form.get('url')}.", "dnd"