From 87909d07eca5b194399eae3d3c5979f3466aef4d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 15 Dec 2023 22:27:39 +0200 Subject: [PATCH] Fix potential issues with ignore_unbridged_group_chat option --- CHANGELOG.md | 6 ++++++ mautrix_telegram/abstract_user.py | 6 +++++- mautrix_telegram/portal.py | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb642f17..33b82fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.15.1 (unreleased) + +* Updated Docker image to Alpine 3.19. +* Fixed some potential cases where a portal room would be created for the + relaybot even if `ignore_unbridged_group_chat` was enabled. + # v0.15.0 (2023-11-26) * Removed support for MSC2716 backfilling. diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index 4badfdc0..b9d99d15 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -658,7 +658,11 @@ async def update_channel(self, update: UpdateChannel) -> None: await portal.delete_telegram_user(self.tgid, sender=None) elif chan := getattr(update, "mau_channel", None): if not portal.mxid: - background_task.create(self._delayed_create_channel(chan)) + if ( + not self.is_relaybot + or not self.config["bridge.relaybot.ignore_unbridged_group_chat"] + ): + background_task.create(self._delayed_create_channel(chan)) else: self.log.debug("Updating channel info with data fetched by Telethon") await portal.update_info(self, chan) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 2ab062db..63e2b577 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -787,6 +787,8 @@ async def create_matrix_room( background_task.create(update) await self.invite_to_matrix(invites or []) return self.mxid + elif user.is_relaybot and self.config["bridge.relaybot.ignore_unbridged_group_chat"]: + raise Exception("create_matrix_room called as relaybot") async with self._room_create_lock: try: return await self._create_matrix_room( @@ -3372,6 +3374,8 @@ async def _handle_telegram_message( self, source: au.AbstractUser, sender: p.Puppet | None, evt: Message ) -> None: if not self.mxid: + if source.is_relaybot and self.config["bridge.relaybot.ignore_unbridged_group_chat"]: + return self.log.debug("Got telegram message %d, but no room exists, creating...", evt.id) await self.create_matrix_room(source, invites=[source.mxid], update_if_exists=False) if not self.mxid: @@ -3536,7 +3540,7 @@ async def _mark_disappearing( async def _create_room_on_action( self, source: au.AbstractUser, action: TypeMessageAction ) -> bool: - if source.is_relaybot and self.config["bridge.ignore_unbridged_group_chat"]: + if source.is_relaybot and self.config["bridge.relaybot.ignore_unbridged_group_chat"]: return False create_and_exit = (MessageActionChatCreate, MessageActionChannelCreate) create_and_continue = (