From bc4610af045f46f62927845959760b7e26c75659 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 1 Aug 2020 14:11:34 +0300 Subject: [PATCH] Add option to disable backfilling normal groups --- mautrix_telegram/commands/telegram/misc.py | 3 +++ mautrix_telegram/config.py | 1 + mautrix_telegram/example-config.yaml | 4 ++++ mautrix_telegram/portal/telegram.py | 2 ++ 4 files changed, 10 insertions(+) diff --git a/mautrix_telegram/commands/telegram/misc.py b/mautrix_telegram/commands/telegram/misc.py index 5e5e4531..22b9b445 100644 --- a/mautrix_telegram/commands/telegram/misc.py +++ b/mautrix_telegram/commands/telegram/misc.py @@ -346,6 +346,9 @@ async def backfill(evt: CommandEvent) -> None: except (ValueError, IndexError): limit = -1 portal = po.Portal.get_by_mxid(evt.room_id) + if not evt.config["bridge.backfill.normal_groups"] and portal.peer_type == "chat": + await evt.reply("Backfilling normal groups is disabled in the bridge config") + return try: await portal.backfill(evt.sender, limit=limit) except TakeoutInitDelayError: diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 36f77383..ae88f04b 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -123,6 +123,7 @@ class Config(BaseBridgeConfig): copy("bridge.backfill.initial_limit") copy("bridge.backfill.missed_limit") copy("bridge.backfill.disable_notifications") + copy("bridge.backfill.normal_groups") copy("bridge.initial_power_level_overrides.group") copy("bridge.initial_power_level_overrides.user") diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 89642f70..62e15718 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -260,6 +260,10 @@ bridge: # If using double puppeting, should notifications be disabled # while the initial backfill is in progress? disable_notifications: false + # Whether or not to enable backfilling in normal groups. + # Normal groups have numerous technical problems in Telegram, and backfilling normal groups + # will likely cause problems if there are multiple Matrix users in the group. + normal_groups: false # Overrides for base power levels. initial_power_level_overrides: diff --git a/mautrix_telegram/portal/telegram.py b/mautrix_telegram/portal/telegram.py index 4391f9c8..7a28c967 100644 --- a/mautrix_telegram/portal/telegram.py +++ b/mautrix_telegram/portal/telegram.py @@ -427,6 +427,8 @@ class PortalTelegram(BasePortal, ABC): else config["bridge.backfill.missed_limit"]) if limit == 0: return + if not config["bridge.backfill.normal_groups"] and self.peer_type == "chat": + return last = DBMessage.find_last(self.mxid, (source.tgid if self.peer_type != "channel" else self.tgid)) min_id = last.tgid if last else 0