|
@@ -8,7 +8,7 @@ import asyncio
|
|
|
|
|
|
from mautrix.util.logging import TraceLogger
|
|
|
|
|
|
-from .rpc import CONNECT_EVENT, SignaldRPCClient
|
|
|
+from .rpc import CONNECT_EVENT, DISCONNECT_EVENT, SignaldRPCClient
|
|
|
from .errors import UnexpectedError, UnexpectedResponse
|
|
|
from .types import (Address, Quote, Attachment, Reaction, Account, Message, DeviceInfo, Group,
|
|
|
Profile, GroupID, GetIdentitiesResponse, ListenEvent, ListenAction, GroupV2,
|
|
@@ -33,6 +33,7 @@ class SignaldClient(SignaldRPCClient):
|
|
|
self.add_rpc_handler("listen_stopped", self._parse_listen_stop)
|
|
|
self.add_rpc_handler("version", self._log_version)
|
|
|
self.add_rpc_handler(CONNECT_EVENT, self._resubscribe)
|
|
|
+ self.add_rpc_handler(DISCONNECT_EVENT, self._on_disconnect)
|
|
|
|
|
|
def add_event_handler(self, event_class: Type[T], handler: EventHandler) -> None:
|
|
|
self._event_handlers.setdefault(event_class, []).append(handler)
|
|
@@ -99,6 +100,14 @@ class SignaldClient(SignaldRPCClient):
|
|
|
for username in list(self._subscriptions):
|
|
|
await self.subscribe(username)
|
|
|
|
|
|
+ async def _on_disconnect(self, *_) -> None:
|
|
|
+ if self._subscriptions:
|
|
|
+ self.log.debug("Notifying of disconnection from users")
|
|
|
+ for username in self._subscriptions:
|
|
|
+ evt = ListenEvent(action=ListenAction.SOCKET_DISCONNECTED, username=username,
|
|
|
+ exception="Disconnected from signald")
|
|
|
+ await self._run_event_handler(evt)
|
|
|
+
|
|
|
async def register(self, phone: str, voice: bool = False, captcha: Optional[str] = None
|
|
|
) -> str:
|
|
|
resp = await self.request_v1("register", account=phone, voice=voice, captcha=captcha)
|