diff --git a/mautrix_telegram/commands/portal.py b/mautrix_telegram/commands/portal.py index 84ad61b0..f5cb0433 100644 --- a/mautrix_telegram/commands/portal.py +++ b/mautrix_telegram/commands/portal.py @@ -74,7 +74,12 @@ async def id(evt: CommandEvent) -> Dict: portal = po.Portal.get_by_mxid(evt.room_id) if not portal: return await evt.reply("This is not a portal room.") - await evt.reply(f"This room is bridged to Telegram chat ID `{portal.tgid}`.") + tgid = portal.tgid + if portal.peer_type == "chat": + tgid = -tgid + elif portal.peer_type == "channel": + tgid = f"-100{tgid}" + await evt.reply(f"This room is bridged to Telegram chat ID `{tgid}`.") @command_handler(help_section=SECTION_PORTAL_MANAGEMENT, diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 63e72f35..29606ab1 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -1841,9 +1841,11 @@ class Portal: del self.by_tgid[self.tgid_full] except KeyError: pass - existing = self.by_tgid[(new_id, new_id)] - if existing: + try: + existing = self.by_tgid[(new_id, new_id)] existing.delete() + except KeyError: + pass self.db_instance.update(tgid=new_id, tg_receiver=new_id) old_id = self.tgid self.tgid = new_id