diff --git a/mautrix_telegram/portal/base.py b/mautrix_telegram/portal/base.py index 1d2d6d71..ef6fce32 100644 --- a/mautrix_telegram/portal/base.py +++ b/mautrix_telegram/portal/base.py @@ -402,6 +402,8 @@ class BasePortal(ABC): @classmethod def get_by_tgid(cls, tgid: TelegramID, tg_receiver: Optional[TelegramID] = None, peer_type: str = None) -> Optional['Portal']: + if peer_type == "user" and tg_receiver is None: + raise ValueError("tg_receiver is required when peer_type is \"user\"") tg_receiver = tg_receiver or tgid tgid_full = (tgid, tg_receiver) try: diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 73b28945..a43961c7 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -348,7 +348,7 @@ class User(AbstractUser, BaseUser): continue elif isinstance(entity, TLUser) and not config["bridge.sync_direct_chats"]: continue - portal = po.Portal.get_by_entity(entity) + portal = po.Portal.get_by_entity(entity, receiver_id=self.tgid) self.portals[portal.tgid_full] = portal creators.append( portal.create_matrix_room(self, entity, invites=[self.mxid],