From 6eda8bd1658c88cc1a6074933631c0a99a4b7c35 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 10 Mar 2023 13:23:14 +0200 Subject: [PATCH] Update Telethon Fixes #896 --- mautrix_telegram/abstract_user.py | 10 +++++++++- mautrix_telegram/portal.py | 2 +- mautrix_telegram/user.py | 8 ++++++-- requirements.txt | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index 8d827002..481c0616 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -676,7 +676,15 @@ class AbstractUser(ABC): if not portal: return elif portal and not portal.allow_bridging: - self.log.debug(f"Ignoring message in portal {portal.tgid_log} (bridging disallowed)") + self.log.debug( + f"Ignoring message {update.id} in portal {portal.tgid_log} (bridging disallowed)" + ) + return + + if not portal.mxid and getattr(original_update, "mau_left_channel", False): + self.log.debug( + f"Ignoring message {update.id} in portal {portal.tgid_log} because user isn't in the chat" + ) return if self.is_relaybot: diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 2e6b27c0..9bd75979 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -3870,7 +3870,7 @@ class Portal(DBPortal, BasePortal): return portal if peer_type: - cls.log.info(f"Creating portal for {peer_type} {tgid} (receiver {tg_receiver})") + cls.log.info(f"Creating portal object for {peer_type} {tgid} (receiver {tg_receiver})") # TODO enable this for non-release builds # (or add better wrong peer type error handling) # if peer_type == "chat": diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 2d77c23e..4a911ce2 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -52,6 +52,7 @@ from telethon.tl.types import ( User as TLUser, ) from telethon.tl.types.contacts import ContactsNotModified +from telethon.tl.types.help import AppConfig from telethon.tl.types.messages import AvailableReactions from mautrix.appservice import DOUBLE_PUPPET_SOURCE_KEY @@ -106,6 +107,7 @@ class User(DBUser, AbstractUser, BaseUser): _available_emoji_reactions_fetched: float _available_emoji_reactions_lock: asyncio.Lock _app_config: dict[str, Any] | None + _app_config_hash: int def __init__( self, @@ -143,6 +145,7 @@ class User(DBUser, AbstractUser, BaseUser): self._available_emoji_reactions_fetched = 0 self._available_emoji_reactions_lock = asyncio.Lock() self._app_config = None + self._app_config_hash = 0 ( self.relaybot_whitelisted, @@ -969,8 +972,9 @@ class User(DBUser, AbstractUser, BaseUser): async def get_app_config(self) -> dict[str, Any]: if not self._app_config: - cfg = await self.client(GetAppConfigRequest()) - self._app_config = util.parse_tl_json(cfg) + cfg: AppConfig = await self.client(GetAppConfigRequest(hash=self._app_config_hash)) + self._app_config = util.parse_tl_json(cfg.config) + self._app_config_hash = cfg.hash return self._app_config async def get_max_reactions(self, is_premium: bool | None = None) -> int: diff --git a/requirements.txt b/requirements.txt index 4fc8aaee..ccff7a9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.19.4,<0.20 -tulir-telethon==1.28.0a4 +tulir-telethon==1.28.0a8 asyncpg>=0.20,<0.28 mako>=1,<2 setuptools