Upgrade mautrix to 0.10.2 and use new BridgeStateEvents
This commit is contained in:
@@ -129,5 +129,8 @@ class TelegramBridge(Bridge):
|
|||||||
def is_bridge_ghost(self, user_id: UserID) -> bool:
|
def is_bridge_ghost(self, user_id: UserID) -> bool:
|
||||||
return bool(Puppet.get_id_from_mxid(user_id))
|
return bool(Puppet.get_id_from_mxid(user_id))
|
||||||
|
|
||||||
|
async def count_logged_in_users(self) -> int:
|
||||||
|
return len([user for user in User.by_tgid.values() if user.tgid])
|
||||||
|
|
||||||
|
|
||||||
TelegramBridge().run()
|
TelegramBridge().run()
|
||||||
|
|||||||
+10
-12
@@ -32,6 +32,7 @@ from mautrix.client import Client
|
|||||||
from mautrix.errors import MatrixRequestError, MNotFound
|
from mautrix.errors import MatrixRequestError, MNotFound
|
||||||
from mautrix.types import UserID, RoomID, PushRuleScope, PushRuleKind, PushActionType, RoomTagInfo
|
from mautrix.types import UserID, RoomID, PushRuleScope, PushRuleKind, PushActionType, RoomTagInfo
|
||||||
from mautrix.bridge import BaseUser, BridgeState
|
from mautrix.bridge import BaseUser, BridgeState
|
||||||
|
from mautrix.util.bridge_state import BridgeStateEvent
|
||||||
from mautrix.util.logging import TraceLogger
|
from mautrix.util.logging import TraceLogger
|
||||||
from mautrix.util.opt_prometheus import Gauge
|
from mautrix.util.opt_prometheus import Gauge
|
||||||
|
|
||||||
@@ -222,22 +223,17 @@ class User(AbstractUser, BaseUser):
|
|||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
connected = self._is_connected
|
connected = self._is_connected
|
||||||
self._track_metric(METRIC_CONNECTED, connected)
|
self._track_metric(METRIC_CONNECTED, connected)
|
||||||
await self.push_bridge_state(ok=connected, ttl=3600 if connected else 240,
|
if connected:
|
||||||
error="tg-not-connected" if not connected else None)
|
await self.push_bridge_state(BridgeStateEvent.CONNECTED, ttl=3600)
|
||||||
|
else:
|
||||||
|
await self.push_bridge_state(BridgeStateEvent.UNKNOWN_ERROR, ttl=240,
|
||||||
|
error="tg-not-connected")
|
||||||
|
|
||||||
async def fill_bridge_state(self, state: BridgeState) -> None:
|
async def fill_bridge_state(self, state: BridgeState) -> None:
|
||||||
await super().fill_bridge_state(state)
|
await super().fill_bridge_state(state)
|
||||||
state.remote_id = str(self.tgid)
|
state.remote_id = str(self.tgid)
|
||||||
state.remote_name = self.human_tg_id
|
state.remote_name = self.human_tg_id
|
||||||
|
|
||||||
async def get_bridge_state(self) -> BridgeState:
|
|
||||||
if not self.tgid:
|
|
||||||
return BridgeState(ok=False, error="logged-out")
|
|
||||||
elif not self._is_connected:
|
|
||||||
return BridgeState(ok=False, error="tg-not-connected")
|
|
||||||
else:
|
|
||||||
return BridgeState(ok=True)
|
|
||||||
|
|
||||||
async def get_puppet(self) -> Optional['pu.Puppet']:
|
async def get_puppet(self) -> Optional['pu.Puppet']:
|
||||||
if not self.tgid:
|
if not self.tgid:
|
||||||
return None
|
return None
|
||||||
@@ -249,7 +245,8 @@ class User(AbstractUser, BaseUser):
|
|||||||
self._track_connection_task.cancel()
|
self._track_connection_task.cancel()
|
||||||
self._track_connection_task = None
|
self._track_connection_task = None
|
||||||
self._track_metric(METRIC_CONNECTED, False)
|
self._track_metric(METRIC_CONNECTED, False)
|
||||||
await self.push_bridge_state(ok=False, error="tg-not-connected")
|
await self.push_bridge_state(state_event=BridgeStateEvent.UNKNOWN_ERROR,
|
||||||
|
error="tg-not-connected")
|
||||||
|
|
||||||
async def post_login(self, info: TLUser = None, first_login: bool = False) -> None:
|
async def post_login(self, info: TLUser = None, first_login: bool = False) -> None:
|
||||||
if config["metrics.enabled"] and not self._track_connection_task:
|
if config["metrics.enabled"] and not self._track_connection_task:
|
||||||
@@ -341,7 +338,7 @@ class User(AbstractUser, BaseUser):
|
|||||||
self.portals = {}
|
self.portals = {}
|
||||||
self.contacts = []
|
self.contacts = []
|
||||||
await self.save(portals=True, contacts=True)
|
await self.save(portals=True, contacts=True)
|
||||||
await self.push_bridge_state(ok=False, error="logged-out")
|
await self.push_bridge_state(BridgeStateEvent.LOGGED_OUT)
|
||||||
if self.tgid:
|
if self.tgid:
|
||||||
try:
|
try:
|
||||||
del self.by_tgid[self.tgid]
|
del self.by_tgid[self.tgid]
|
||||||
@@ -507,6 +504,7 @@ class User(AbstractUser, BaseUser):
|
|||||||
index = 0
|
index = 0
|
||||||
self.log.debug(f"Syncing dialogs (update_limit={update_limit}, "
|
self.log.debug(f"Syncing dialogs (update_limit={update_limit}, "
|
||||||
f"create_limit={create_limit})")
|
f"create_limit={create_limit})")
|
||||||
|
await self.push_bridge_state(BridgeStateEvent.BACKFILLING)
|
||||||
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
||||||
dialog: Dialog
|
dialog: Dialog
|
||||||
async for dialog in self.client.iter_dialogs(limit=update_limit, ignore_migrated=True,
|
async for dialog in self.client.iter_dialogs(limit=update_limit, ignore_migrated=True,
|
||||||
|
|||||||
+1
-1
@@ -5,6 +5,6 @@ python-magic>=0.4,<0.5
|
|||||||
commonmark>=0.8,<0.10
|
commonmark>=0.8,<0.10
|
||||||
aiohttp>=3,<4
|
aiohttp>=3,<4
|
||||||
yarl>=1,<2
|
yarl>=1,<2
|
||||||
mautrix>=0.9.7,<0.10
|
mautrix>=0.10.2,<0.11
|
||||||
telethon>=1.22,<1.23
|
telethon>=1.22,<1.23
|
||||||
telethon-session-sqlalchemy>=0.2.14,<0.3
|
telethon-session-sqlalchemy>=0.2.14,<0.3
|
||||||
|
|||||||
Reference in New Issue
Block a user