Implement get_bridge_states

This commit is contained in:
Tulir Asokan
2021-08-25 16:04:50 +03:00
parent 2e14991815
commit e276944b40
2 changed files with 14 additions and 2 deletions
+13 -1
View File
@@ -232,7 +232,7 @@ class User(AbstractUser, BaseUser):
@property
def _is_connected(self) -> bool:
return bool(self.client and self.client._sender
and self.client._sender._transport_connected)
and self.client._sender._transport_connected())
async def _track_connection(self) -> None:
self.log.debug("Starting loop to track connection state")
@@ -252,6 +252,18 @@ class User(AbstractUser, BaseUser):
state.remote_id = str(self.tgid)
state.remote_name = self.human_tg_id
async def get_bridge_states(self) -> List[BridgeState]:
if not self.tgid:
return []
if self._is_connected and await self.is_logged_in():
state_event = (BridgeStateEvent.BACKFILLING if self._is_backfilling
else BridgeStateEvent.CONNECTED)
ttl = 3600
else:
state_event = BridgeStateEvent.UNKNOWN_ERROR
ttl = 240
return [BridgeState(state_event=state_event, ttl=ttl)]
async def get_puppet(self) -> Optional['pu.Puppet']:
if not self.tgid:
return None
+1 -1
View File
@@ -5,6 +5,6 @@ python-magic>=0.4,<0.5
commonmark>=0.8,<0.10
aiohttp>=3,<4
yarl>=1,<2
mautrix>=0.10.4,<0.11
mautrix>=0.10.5,<0.11
telethon>=1.22,<1.24
telethon-session-sqlalchemy>=0.2.14,<0.3