From 79341b8d283315920491f3e80a18a53470571d67 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 13 May 2018 11:22:20 +0300 Subject: [PATCH] Add support for Telethon's catch_up() (ref #124) --- example-config.yaml | 3 +++ mautrix_telegram/bot.py | 6 ++++++ mautrix_telegram/config.py | 1 + mautrix_telegram/user.py | 2 ++ setup.py | 2 +- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/example-config.yaml b/example-config.yaml index 8f237ba3..b5db9a43 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -112,6 +112,9 @@ bridge: # # Remember that proper sticker support always requires Pillow to convert webp into png. native_stickers: true + # Whether or not to fetch and handle Telegram updates at startup from the time the bridge was down. + # WARNING: Probably buggy, might get stuck in infinite loop. + catch_up: false # The prefix for commands. Only required in non-management rooms. command_prefix: "!tg" diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index e56eb814..ff81c345 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -86,6 +86,12 @@ class Bot(AbstractUser): except (ChannelPrivateError, ChannelInvalidError): self.remove_chat(id.channel_id) + if config["bridge.catch_up"]: + try: + await self.client.catch_up() + except Exception: + self.log.exception("Failed to run catch_up() for bot") + def register_portal(self, portal: po.Portal): self.add_chat(portal.tgid, portal.peer_type) diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 6af886c1..7e220c67 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -179,6 +179,7 @@ class Config(DictWithRecursion): copy("bridge.plaintext_highlights") copy("bridge.public_portals") copy("bridge.native_stickers") + copy("bridge.catch_up") copy("bridge.command_prefix") diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index a34f9a7d..827609d6 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -150,6 +150,8 @@ class User(AbstractUser): await self.update_info(info) await self.sync_dialogs() await self.sync_contacts() + if config["bridge.catch_up"]: + await self.client.catch_up() except Exception: self.log.exception("Failed to run post-login functions") diff --git a/setup.py b/setup.py index 32450688..816f9fb6 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ setuptools.setup( install_requires=[ "aiohttp>=3.0.1,<4", - "mautrix-appservice>=0.1.4,<0.2.0", + "mautrix-appservice>=0.2.3,<0.3.0", "SQLAlchemy>=1.2.3,<2", "alembic>=0.9.8,<0.10", "Markdown>=2.6.11,<3",